44 struct termios new_port_settings,
53 case 50 : baudr = B50;
55 case 75 : baudr = B75;
57 case 110 : baudr = B110;
59 case 134 : baudr = B134;
61 case 150 : baudr = B150;
63 case 200 : baudr = B200;
65 case 300 : baudr = B300;
67 case 600 : baudr = B600;
69 case 1200 : baudr = B1200;
71 case 1800 : baudr = B1800;
73 case 2400 : baudr = B2400;
75 case 4800 : baudr = B4800;
77 case 9600 : baudr = B9600;
79 case 19200 : baudr = B19200;
81 case 38400 : baudr = B38400;
83 case 57600 : baudr = B57600;
85 case 115200 : baudr = B115200;
87 case 230400 : baudr = B230400;
89 case 460800 : baudr = B460800;
91 case 500000 : baudr = B500000;
93 case 576000 : baudr = B576000;
95 case 921600 : baudr = B921600;
97 case 1000000 : baudr = B1000000;
99 default : printf(
"invalid baudrate\n");
104 Cport = open(comport, O_RDWR | O_NOCTTY | O_NDELAY);
107 perror(
"unable to open comport ");
111 error = tcgetattr(
Cport, &old_port_settings);
115 perror(
"unable to read portsettings ");
118 memset(&new_port_settings, 0,
sizeof(new_port_settings));
120 new_port_settings.c_cflag = baudr | CS8 | CLOCAL | CREAD;
121 new_port_settings.c_iflag = IGNPAR;
122 new_port_settings.c_oflag = 0;
123 new_port_settings.c_lflag = 0;
124 new_port_settings.c_cc[VMIN] = 0;
125 new_port_settings.c_cc[VTIME] = 0;
126 error = tcsetattr(
Cport, TCSANOW, &new_port_settings);
130 perror(
"unable to adjust portsettings ");
142 #ifndef __STRICT_ANSI__ 143 if(size>SSIZE_MAX) size = (int)SSIZE_MAX;
145 if(size>4096) size = 4096;
148 n = read(
Cport, buf, size);
158 n = write(
Cport, &byte, 1);
165 int SendBuf(
unsigned char *buf,
int size)
167 return(write(
Cport, buf, size));
174 tcsetattr(
Cport, TCSANOW, &old_port_settings);
196 status = ioctl(
Cport, TIOCMGET, &status);
198 if(status&TIOCM_CTS)
return(1);
214 COMMTIMEOUTS Cptimeouts;
216 char comport_path[32];
217 sprintf(comport_path,
"\\\\.\\%s", comport);
221 case 110 : strcpy(baudr,
"baud=110 data=8 parity=N stop=1");
223 case 300 : strcpy(baudr,
"baud=300 data=8 parity=N stop=1");
225 case 600 : strcpy(baudr,
"baud=600 data=8 parity=N stop=1");
227 case 1200 : strcpy(baudr,
"baud=1200 data=8 parity=N stop=1");
229 case 2400 : strcpy(baudr,
"baud=2400 data=8 parity=N stop=1");
231 case 4800 : strcpy(baudr,
"baud=4800 data=8 parity=N stop=1");
233 case 9600 : strcpy(baudr,
"baud=9600 data=8 parity=N stop=1");
235 case 19200 : strcpy(baudr,
"baud=19200 data=8 parity=N stop=1");
237 case 38400 : strcpy(baudr,
"baud=38400 data=8 parity=N stop=1");
239 case 57600 : strcpy(baudr,
"baud=57600 data=8 parity=N stop=1");
241 case 115200 : strcpy(baudr,
"baud=115200 data=8 parity=N stop=1");
243 case 128000 : strcpy(baudr,
"baud=128000 data=8 parity=N stop=1");
245 case 230400 : strcpy(baudr,
"baud=230400 data=8 parity=N stop=1");
247 case 256000 : strcpy(baudr,
"baud=256000 data=8 parity=N stop=1");
249 case 460800 : strcpy(baudr,
"baud=460800 data=8 parity=N stop=1");
251 case 500000 : strcpy(baudr,
"baud=500000 data=8 parity=N stop=1");
253 case 921600 : strcpy(baudr,
"baud=921600 data=8 parity=N stop=1");
255 case 1000000 : strcpy(baudr,
"baud=1000000 data=8 parity=N stop=1");
257 default : printf(
"invalid baudrate\n");
262 Cport = CreateFileA(comport_path,
263 GENERIC_READ|GENERIC_WRITE,
270 if(Cport==INVALID_HANDLE_VALUE)
272 printf(
"unable to open comport\n");
277 memset(&port_settings, 0,
sizeof(port_settings));
278 port_settings.DCBlength =
sizeof(port_settings);
280 if(!BuildCommDCBA(baudr, &port_settings))
282 printf(
"unable to set comport dcb settings\n");
287 if(!SetCommState(Cport, &port_settings))
289 printf(
"unable to set comport cfg settings\n");
294 Cptimeouts.ReadIntervalTimeout = MAXDWORD;
295 Cptimeouts.ReadTotalTimeoutMultiplier = 0;
296 Cptimeouts.ReadTotalTimeoutConstant = 0;
297 Cptimeouts.WriteTotalTimeoutMultiplier = 0;
298 Cptimeouts.WriteTotalTimeoutConstant = 0;
300 if(!SetCommTimeouts(Cport, &Cptimeouts))
302 printf(
"unable to set comport time-out settings\n");
315 if(size>4096) size = 4096;
320 ReadFile(Cport, buf, size, (LPDWORD)((
void *)&n), NULL);
330 WriteFile(Cport, &byte, 1, (LPDWORD)((
void *)&n), NULL);
342 if(WriteFile(Cport, buf, size, (LPDWORD)((
void *)&n), NULL))
361 GetCommModemStatus(Cport, (LPDWORD)((
void *)&status));
363 if(status&MS_CTS_ON)
return(1);
int OpenComport(char *comport, int baudrate)
int PollComport(unsigned char *buf, int size)
int SendBuf(unsigned char *buf, int size)
int SendByte(unsigned char byte)