亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? serialcomm.cpp

?? route
?? CPP
字號:

#include <unistd.h>  // UNIX standard function definitions 
#include <termios.h> // POSIX terminal control definitions 
#include <fcntl.h>   // File control definitions
#include <string.h>
#include "SerialComm.h"

SerialComm::SerialComm()
{
  // Default setting 
  baud_rate = 9600;
  parity = 'N';
  character_size = 8;
  stop_bits = 1;
  flow_control = SerialComm::scommNO_FLOW_CONTROL;
  binary_mode = 1; 
  scomm_error = SerialComm::scomm_NO_ERROR;

  memset(&options, 0, sizeof(options));
}

SerialComm::~SerialComm()
{
  Close();
}

int SerialComm::OpenSerialPort(char *device_name)
// Open a serial device for read/write operations. 
{

  device_handle = open(device_name, O_RDWR | O_NOCTTY | O_NDELAY);

  if(device_handle < 0) 
    device_handle = open(device_name, O_RDONLY | O_NOCTTY | O_NDELAY);
  else 
    return scommREAD_WRITE;
  
  if(device_handle < 0) 
    device_handle = open(device_name, O_WRONLY | O_NOCTTY | O_NDELAY);
  else 
    return scommREAD_ONLY;
  
  if(device_handle < 0) {
    scomm_error = SerialComm::scomm_OPEN_ERROR;
    return -1;
  }
  else
    return scommWRITE_ONLY;

}

int SerialComm::InitSerialPort()
{
  // Reset the port options
  memset(&options, 0, sizeof(options));

  // Set the baud rates
  switch(baud_rate) {
    case 0: // 0 baud (drop DTR)
      cfsetispeed(&options, B0);
      cfsetospeed(&options, B0);
      break;
    case 50: 
      cfsetispeed(&options, B50);
      cfsetospeed(&options, B50);
      break;
    case 75: 
      cfsetispeed(&options, B75);
      cfsetospeed(&options, B75);
      break;
    case 110: 
      cfsetispeed(&options, B110);
      cfsetospeed(&options, B110);
      break;
    case 134: 
      cfsetispeed(&options, B134);
      cfsetospeed(&options, B134);
      break;
    case 150: 
      cfsetispeed(&options, B150);
      cfsetospeed(&options, B150);
      break;
    case 200: 
      cfsetispeed(&options, B200);
      cfsetospeed(&options, B200);
      break;
    case 300: 
      cfsetispeed(&options, B300);
      cfsetospeed(&options, B300);
      break;
    case 600: 
      cfsetispeed(&options, B600);
      cfsetospeed(&options, B600);
      break;
    case 1200: 
      cfsetispeed(&options, B1200);
      cfsetospeed(&options, B1200);
      break;
    case 1800: 
      cfsetispeed(&options, B1800);
      cfsetospeed(&options, B1800);
      break;
    case 2400: 
      cfsetispeed(&options, B2400);
      cfsetospeed(&options, B2400);
      break;
    case 4800: 
      cfsetispeed(&options, B4800);
      cfsetospeed(&options, B4800);
      break;
    case 9600: 
      cfsetispeed(&options, B9600);
      cfsetospeed(&options, B9600);
      break;
    case 19200: 
      cfsetispeed(&options, B19200);
      cfsetospeed(&options, B19200);
      break;
    case 57600: 
      cfsetispeed(&options, B57600);
      cfsetospeed(&options, B57600);
      break;
    case 115200: 
      cfsetispeed(&options, B115200);
      cfsetospeed(&options, B115200);
      break;
    default:
      scomm_error = SerialComm::scomm_BAUDRATE_ERROR;
      return -1; // Invalid baud rate
  }

  // Set the character size, parity and stop bits
  if((character_size == 8) && (parity == 'N') && (stop_bits == 1)) {
    // No parity (8N1) 
    options.c_cflag &= ~PARENB;
    options.c_cflag &= ~CSTOPB;
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS8;
    options.c_iflag = IGNPAR;
  }
  else if((character_size == 7) && (parity == 'E') && (stop_bits == 1)) {
    // Even parity (7E1) 
    options.c_cflag |= PARENB;
    options.c_cflag &= ~PARODD;
    options.c_cflag &= ~CSTOPB;
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS7;
    options.c_iflag |= (INPCK | ISTRIP);
  }
  else if((character_size == 7) && (parity == 'O') && (stop_bits == 1)) {
    // Odd parity (7O1) 
    options.c_cflag |= PARENB;
    options.c_cflag |= PARODD;
    options.c_cflag &= ~CSTOPB;
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS7;
    options.c_iflag |= (INPCK | ISTRIP);
  }
  else if((character_size == 7) && (parity == 'M') && (stop_bits == 1)) {
    // Mark parity is simulated by using 2 stop bits (7M1)
    options.c_cflag &= ~PARENB;
    options.c_cflag |= CSTOPB;
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS7;
    options.c_iflag |= (INPCK | ISTRIP);
  }
  else if((character_size == 7) && (parity == 'S') && (stop_bits == 1)) {
    // Space parity is setup the same as no parity (7S1)
    options.c_cflag &= ~PARENB;
    options.c_cflag &= ~CSTOPB;
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS7;
    options.c_iflag |= (INPCK | ISTRIP);
  }
  else {
    scomm_error = SerialComm::scomm_INVALIDPARM;
    return -1; // Invalid character size, parity and stop bits combination
  }
  
  switch(flow_control) {
    case scommHARD_FLOW :
#if defined(CRTSCTS)
      options.c_cflag |= CRTSCTS;
      break;
#else
      break; // Hard flow control is not supported
#endif

    case scommXON_XOFF :
      options.c_iflag |= (IXON | IXOFF | IXANY);
#if defined(CRTSCTS)
      options.c_cflag &= ~CRTSCTS;
#endif
      break;

    case scommSOFT_FLOW :
#if defined(CRTSCTS)
      options.c_cflag &= ~CRTSCTS;
      break;
#else
      break; // Hard flow control is not supported
#endif

    case scommNO_FLOW_CONTROL :
#if defined(CRTSCTS)
      options.c_cflag &= ~CRTSCTS;
      break;
#else
      break; // Hard flow control is not supported
#endif

    default:
      scomm_error = SerialComm::scomm_FLOWCONTROL_ERROR;
      return -1; // Invalid flow control
  }

  if(!binary_mode) { // Set the port for canonical input (line-oriented) 
    // Input characters are put into a buffer until a CR (carriage return)
    // or LF (line feed) character is received.
    options.c_lflag |= (ICANON | ECHOE);

    // Postprocess the output.
    // The ONLCR flag will map NL (linefeeds) to CR-NL on output.
    // The OLCUC flag will map characters to upper case for tty output.
    options.c_oflag = OPOST | ONLCR | OLCUC;
  }
  else { // Use raw input/output
    // Input characters are passed through exactly as they are received,
    // when they are received.
    options.c_lflag = 0;
    options.c_oflag = 0;
  }
  
  // Enable the receiver and set local mode
  options.c_cflag |= (CLOCAL | CREAD);
  
  // Initialize control characters if needed.
  // Default values can be found in /usr/include/termios.h, and are given
  // in the comments.

  options.c_cc[VTIME]    = 0;     // inter-character timer unused 
  options.c_cc[VMIN]     = 1;     // blocking read until 1 character arrives 

 

  // Set the new options for the port. The TCSANOW constant specifies
  // that all changes should occur immediately without waiting for
  // output data to finish sending or input data to finish receiving. 
  tcflush(device_handle, TCIFLUSH); // Clean the serial line
  tcsetattr(device_handle, TCSANOW, &options);

return 1; // No errors reported
}

void SerialComm::Close()
{

  close(device_handle);

}

int SerialComm::RawRead(void *buf, int bytes)
// Read a specified number of bytes from the serial port
// and return whether or not the read was completed.
// Returns the number of bytes received or -1 if an
// error occurred.
{

  bytes_read = read(device_handle, (char *)buf, bytes);
  if(bytes_read < 0) {
    scomm_error = SerialComm::scomm_RECEIVE_ERROR;
    return -1;
  }
  return (int)bytes_read;
}

int SerialComm::RawWrite(const void *buf, int bytes)
// Write a specified number of bytes to a serial port
// and return whether or not the write was complete.
// Returns the total number of bytes moved or -1 if
// an error occurred.
{
  bytes_moved = write(device_handle, (char *)buf, bytes);
  if(bytes_moved < 0) {
    scomm_error = SerialComm::scomm_TRANSMIT_ERROR;
    return -1;
  }
  return (int)bytes_moved;
}

int SerialComm::Recv(void *buf, int bytes)
// Receive a specified number of bytes from a serial port
// and do not return until all the byte have been read.
// Returns the total number of bytes read or -1 if an
// error occurred.
{
  int br = 0;               // Byte counter
  int num_read = 0;         // Actual number of bytes read
  int num_req = (int)bytes; // Number of bytes requested 
  char *p = (char *)buf;    // Pointer to the buffer

  while(br < bytes) { // Loop unitl the buffer is full
    if((num_read = RawRead(p, num_req-br)) > 0) {
      br += num_read;   // Increment the byte counter
      p += num_read;    // Move the buffer pointer for the next read
    }
    if(num_read < 0) {
      scomm_error = SerialComm::scomm_RECEIVE_ERROR;
      return -1; // An error occurred during the read
    }
  }
  
  bytes_read = br; // Undate the object's byte counter
  return bytes_read;
}

int SerialComm::Send(const void *buf, int bytes)
// Write a specified number of bytes to a serial port and do
// not return until all the bytes have been written. Returns
// the total number of bytes written or -1 if an error occurred.
{
  int bm = 0;                // Byte counter
  int num_moved = 0;         // Actual number of bytes written
  int num_req = (int)bytes;  // Number of bytes requested 
  char *p = (char *)buf;     // Pointer to the buffer

  while(bm < bytes) { // Loop unitl the buffer is empty
    if((num_moved = RawWrite(p, num_req-bm)) > 0) {
      bm += num_moved;  // Increment the byte counter
      p += num_moved;   // Move the buffer pointer for the next read
    }
    if(num_moved < 0) {
      scomm_error = SerialComm::scomm_TRANSMIT_ERROR;
      return -1; // An error occurred during the read
    }
  }
  
  bytes_moved = bm; // Update the object's byte counter
  return bytes_moved;
}

int SerialComm::InitSerialPort(char *device_name, int sp, char pr, int cs,
				 int sb, int flow, int bin_mode)
// Initialize a serial device using the specified parameters. Returns
// -1 if an error occurred during initialization or the current access
// mode of the port (scommREAD_WRITE, scommREAD_ONLY, scommREAD_WRITE).
{
  int status = OpenSerialPort(device_name); 
  if(status < 0) return -1;

  SetBaudRate(sp);
  SetCharacterSize(cs);
  SetParity(pr);
  SetStopBits(sb);
  SetFlowControl(flow);
  if(bin_mode) BinaryMode(); else CharacterMode();

  if(InitSerialPort() < 0) return -1;
  
  return status;
}



?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本伦理一区二区| 色成人在线视频| 青青草91视频| 蜜桃视频一区二区| 男女激情视频一区| 久久97超碰国产精品超碰| 午夜不卡av在线| 蜜臀av性久久久久av蜜臀妖精| 免费看欧美女人艹b| 久久精品国内一区二区三区| 免费在线看一区| 国产精品影视网| 成人永久免费视频| 色94色欧美sute亚洲线路一ni| 97se亚洲国产综合自在线观| 色噜噜夜夜夜综合网| 欧美三级三级三级| 日韩欧美国产不卡| 日本一区二区三区久久久久久久久不| 中文字幕欧美一区| 亚洲精品国久久99热| 亚洲va国产天堂va久久en| 奇米精品一区二区三区在线观看 | 欧美麻豆精品久久久久久| 精品视频在线看| 精品久久久久久久久久久院品网| 国产日产欧美一区二区三区| 亚洲精品国产高清久久伦理二区| 日韩国产欧美一区二区三区| 国产在线不卡一区| 欧洲视频一区二区| 欧美精品一区二区三区一线天视频| 国产欧美综合在线观看第十页| 亚洲精品菠萝久久久久久久| 免费成人在线网站| 一本一道久久a久久精品| 欧美人与禽zozo性伦| 亚洲国产精品国自产拍av| 夜色激情一区二区| 国产精品自拍一区| 欧美体内she精高潮| 久久久久9999亚洲精品| 亚洲成a人v欧美综合天堂| 韩国精品免费视频| 欧美区视频在线观看| 日本一区二区免费在线观看视频 | 久久日韩精品一区二区五区| 亚洲免费资源在线播放| 激情文学综合网| 欧美区一区二区三区| 成人免费在线视频观看| 黄色资源网久久资源365| 欧美色欧美亚洲另类二区| 国产精品美女久久久久aⅴ国产馆| 日韩成人免费看| 色视频欧美一区二区三区| 欧美激情艳妇裸体舞| 激情五月播播久久久精品| 在线综合+亚洲+欧美中文字幕| 综合激情成人伊人| 成人午夜伦理影院| 国产喂奶挤奶一区二区三区| 蜜臀久久久久久久| 91精品国产全国免费观看| 亚洲与欧洲av电影| 色哟哟国产精品免费观看| 亚洲欧美在线高清| 国v精品久久久网| 欧美韩国日本综合| 国产+成+人+亚洲欧洲自线| 久久久精品免费观看| 国产一区二区福利视频| 久久亚洲一区二区三区四区| 久久精品免费观看| 欧美精品一区二区在线播放| 国产主播一区二区| www久久精品| 国产成人免费av在线| 国产亲近乱来精品视频| 丁香婷婷综合色啪| 亚洲视频综合在线| 91丨九色丨蝌蚪丨老版| 亚洲六月丁香色婷婷综合久久 | 欧美日韩高清一区| 日韩经典一区二区| 日韩欧美成人午夜| 国产精品一级在线| 中文字幕制服丝袜一区二区三区| a4yy欧美一区二区三区| 亚洲激情五月婷婷| 欧美日韩1234| 国产乱一区二区| 综合自拍亚洲综合图不卡区| 欧洲av在线精品| 秋霞影院一区二区| 国产日韩欧美高清在线| 色av成人天堂桃色av| 日韩国产一区二| 国产婷婷色一区二区三区在线| 97精品国产露脸对白| 午夜欧美大尺度福利影院在线看 | 白白色亚洲国产精品| 亚洲精品一卡二卡| 日韩欧美国产麻豆| 成+人+亚洲+综合天堂| 亚洲一级不卡视频| 精品国产91乱码一区二区三区 | 91精品国产美女浴室洗澡无遮挡| 精品亚洲国内自在自线福利| 国产精品污网站| 欧美精选一区二区| 成人精品国产免费网站| 午夜国产精品影院在线观看| 国产日韩欧美不卡在线| 9191国产精品| 99久久综合色| 麻豆91精品视频| 一二三四社区欧美黄| 久久网这里都是精品| 欧美老女人第四色| av一区二区久久| 国产一二三精品| 午夜视黄欧洲亚洲| 亚洲免费观看高清完整版在线 | 99这里都是精品| 蜜臀av亚洲一区中文字幕| 亚洲免费色视频| 国产日产精品1区| 日韩精品一区国产麻豆| 欧美在线啊v一区| 北条麻妃国产九九精品视频| 国产制服丝袜一区| 美女脱光内衣内裤视频久久网站| 亚洲三级在线免费| 国产精品久久久久国产精品日日| 精品日韩一区二区三区免费视频| 欧美午夜精品一区| 91丨九色丨国产丨porny| 岛国一区二区三区| 国产一区高清在线| 韩国v欧美v亚洲v日本v| 人人爽香蕉精品| 午夜精品福利一区二区蜜股av | 欧美午夜片在线看| 色噜噜久久综合| 色国产综合视频| 一本一本大道香蕉久在线精品 | 丁香婷婷深情五月亚洲| 国产精品白丝av| 国产一区二区91| 国产精品自在欧美一区| 国产一区二区精品久久99| 九九**精品视频免费播放| 蜜臀av一区二区| 国产一区二区视频在线| 国产精品一区在线| 国产成人免费视| av电影天堂一区二区在线观看| 成人免费毛片a| 99久久精品一区二区| 91福利精品第一导航| 欧美日韩免费高清一区色橹橹| 精品污污网站免费看| 欧美色图片你懂的| 日韩欧美国产系列| 久久青草欧美一区二区三区| 国产欧美一区二区精品久导航 | 欧美日本在线观看| 日韩欧美高清一区| 久久婷婷色综合| 亚洲另类一区二区| 日本女人一区二区三区| 国产一区二区三区日韩| 本田岬高潮一区二区三区| 精品视频色一区| 久久综合一区二区| 亚洲伦理在线精品| 免费在线看成人av| 成人av在线资源| 777午夜精品视频在线播放| 久久久蜜臀国产一区二区| 亚洲精品乱码久久久久久日本蜜臀| 亚洲精品久久久蜜桃| 另类调教123区| 91亚洲午夜精品久久久久久| 欧美一区二区在线观看| 中文无字幕一区二区三区 | 国产超碰在线一区| 在线日韩国产精品| 精品1区2区在线观看| 一区二区三区在线看| 久久99精品一区二区三区三区| www..com久久爱| 欧美电影免费观看高清完整版| 一区视频在线播放| 国内久久精品视频| 欧美吻胸吃奶大尺度电影| 久久丝袜美腿综合| 日本不卡免费在线视频| 91浏览器在线视频|