3 #define MILVUS_EXCEPT(except, msg, ...) \ 6 snprintf(buf, 1000, msg " (in milvus::SerialComm::%s)" , ##__VA_ARGS__, __FUNCTION__); \ 23 const char *mode = mode_s.c_str();
27 case 50 : baudr = B50;
29 case 75 : baudr = B75;
31 case 110 : baudr = B110;
33 case 134 : baudr = B134;
35 case 150 : baudr = B150;
37 case 200 : baudr = B200;
39 case 300 : baudr = B300;
41 case 600 : baudr = B600;
43 case 1200 : baudr = B1200;
45 case 1800 : baudr = B1800;
47 case 2400 : baudr = B2400;
49 case 4800 : baudr = B4800;
51 case 9600 : baudr = B9600;
53 case 19200 : baudr = B19200;
55 case 38400 : baudr = B38400;
57 case 57600 : baudr = B57600;
59 case 115200 : baudr = B115200;
61 case 230400 : baudr = B230400;
63 case 460800 : baudr = B460800;
65 case 500000 : baudr = B500000;
67 case 576000 : baudr = B576000;
69 case 921600 : baudr = B921600;
71 case 1000000 : baudr = B1000000;
73 case 1152000 : baudr = B1152000;
75 case 1500000 : baudr = B1500000;
77 case 2000000 : baudr = B2000000;
79 case 2500000 : baudr = B2500000;
81 case 3000000 : baudr = B3000000;
83 case 3500000 : baudr = B3500000;
85 case 4000000 : baudr = B4000000;
87 default : printf(
"invalid baudrate\n");
98 printf(
"invalid mode:%d \"%s\"\n",(
int)strlen(mode), mode);
104 case '8': cbits = CS8;
106 case '7': cbits = CS7;
108 case '6': cbits = CS6;
110 case '5': cbits = CS5;
112 default : printf(
"invalid number of data-bits '%c'\n", mode[0]);
120 case 'n': cpar = IGNPAR;
123 case 'e': cpar = PARENB;
126 case 'o': cpar = (PARENB | PARODD);
128 default : printf(
"invalid parity '%c'\n", mode[1]);
137 case '2': bstop = CSTOPB;
139 default : printf(
"invalid number of stop bits '%c'\n", mode[2]);
145 fd_ = open(port_name.c_str(), O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
148 perror(
"unable to open comport ");
153 fcntl(
fd_, F_SETFL, 0);
160 perror(
"unable to read portsettings ");
163 memset(&new_port_settings, 0,
sizeof(new_port_settings));
165 new_port_settings.c_cflag = cbits | cpar | bstop | CLOCAL | CREAD;
166 new_port_settings.c_iflag = IGNPAR;
167 new_port_settings.c_oflag = 0;
168 new_port_settings.c_lflag = 0;
169 new_port_settings.c_cc[VMIN] = 0;
170 new_port_settings.c_cc[VTIME] = 0;
172 cfsetispeed(&new_port_settings, baudr);
173 cfsetospeed(&new_port_settings, baudr);
175 error = tcsetattr(
fd_, TCSANOW, &new_port_settings);
179 perror(
"unable to adjust portsettings ");
183 if(ioctl(
fd_, TIOCMGET, &status) == -1)
185 perror(
"unable to get portstatus");
192 if(ioctl(
fd_, TIOCMSET, &status) == -1)
194 perror(
"unable to set portstatus");
206 if(ioctl(
fd_, TIOCMGET, &status) == -1)
208 perror(
"unable to get portstatus");
211 status &= ~TIOCM_DTR;
212 status &= ~TIOCM_RTS;
214 if(ioctl(
fd_, TIOCMSET, &status) == -1)
216 perror(
"unable to set portstatus");
225 n = read(
fd_, buf, size);
236 return(write(
fd_, buf, size));
int send_byte(unsigned char)
int poll_comport(unsigned char *, int)
int send_buf(unsigned char *, int)
struct termios new_port_settings old_port_settings
int open_port(std::string port_name, int baudrate, std::string mode_s)