105 if(
fd != -1)
return -1;
106 fd = open(devicename, O_RDWR | O_NOCTTY | O_NDELAY);
107 if(
fd < 0) {
return -1; }
113 buf.c_cflag = speed | CLOCAL | CREAD;
114 if(rtscts == 1) buf.c_cflag |= CRTSCTS;
115 if(bits == 7) buf.c_cflag |= CS7;
116 else buf.c_cflag |= CS8;
117 if(stopbits == 2) buf.c_cflag |= CSTOPB;
118 if(parity ==
rlSerial::ODD) buf.c_cflag |= (PARENB | PARODD);
120 buf.c_lflag = IEXTEN;
127 buf.c_iflag = IGNBRK | IGNPAR | IXANY;
128 if(tcsetattr(
fd, TCSAFLUSH, &buf) < 0) {
return -1; }
132 if(block == 1) fcntl(
fd, F_SETFL, fcntl(
fd, F_GETFL, 0) & ~O_NONBLOCK);
133 tcflush(
fd,TCIOFLUSH);
138 struct dsc$descriptor_s dsc;
141 dsc.dsc$w_length = strlen(devicename);
142 dsc.dsc$a_pointer = (
char *) devicename;
143 dsc.dsc$b_class = DSC$K_CLASS_S;
144 dsc.dsc$b_dtype = DSC$K_DTYPE_T;
146 if(status != SS$_NORMAL)
return -1;
155 if(strlen(devicename) > 80)
return -1;
156 sprintf(devname,
"\\\\.\\%s",devicename);
159 GENERIC_READ | GENERIC_WRITE,
166 if(
hdl == INVALID_HANDLE_VALUE)
168 printf(
"CreateFile(%s) failed\n",devicename);
173 if(speed ==
B50 ) baudrate = 50;
174 if(speed ==
B75 ) baudrate = 75;
175 if(speed ==
B110 ) baudrate = CBR_110;
176 if(speed ==
B134 ) baudrate = 134;
177 if(speed ==
B150 ) baudrate = 150;
178 if(speed ==
B200 ) baudrate = 200;
179 if(speed ==
B300 ) baudrate = CBR_300;
180 if(speed ==
B600 ) baudrate = CBR_600;
181 if(speed ==
B1200 ) baudrate = CBR_1200;
182 if(speed ==
B1800 ) baudrate = 1800;
183 if(speed ==
B2400 ) baudrate = CBR_2400;
184 if(speed ==
B4800 ) baudrate = CBR_4800;
185 if(speed ==
B9600 ) baudrate = CBR_9600;
186 if(speed ==
B19200 ) baudrate = CBR_19200;
187 if(speed ==
B38400 ) baudrate = CBR_38400;
188 if(speed ==
B57600 ) baudrate = CBR_57600;
189 if(speed ==
B115200 ) baudrate = CBR_115200;
190 if(speed ==
B230400 ) baudrate = 230400;
191 if(speed ==
B460800 ) baudrate = 460800;
192 if(speed ==
B500000 ) baudrate = 500000;
193 if(speed ==
B576000 ) baudrate = 576000;
194 if(speed ==
B921600 ) baudrate = 921600;
195 if(speed ==
B1000000) baudrate = 1000000;
196 if(speed ==
B1152000) baudrate = 1152000;
197 if(speed ==
B1500000) baudrate = 1500000;
198 if(speed ==
B2000000) baudrate = 2000000;
199 if(speed ==
B2500000) baudrate = 2500000;
200 if(speed ==
B3000000) baudrate = 3000000;
201 if(speed ==
B3500000) baudrate = 3500000;
202 if(speed ==
B4000000) baudrate = 4000000;
205 GetCommConfig(
hdl,&cc,&ccsize);
210 cc.dcb.DCBlength =
sizeof(DCB);
211 cc.dcb.BaudRate = baudrate;
214 cc.dcb.fOutxCtsFlow = 0;
215 if(rtscts == 1) cc.dcb.fOutxCtsFlow = 1;
216 cc.dcb.fOutxDsrFlow = 0;
217 cc.dcb.fDtrControl = DTR_CONTROL_DISABLE;
218 cc.dcb.fDsrSensitivity = 0;
219 cc.dcb.fTXContinueOnXoff = 1;
224 cc.dcb.fRtsControl = RTS_CONTROL_DISABLE;
225 if(rtscts == 1) cc.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
226 cc.dcb.fAbortOnError = 0;
231 cc.dcb.ByteSize = bits;
235 cc.dcb.StopBits = ONESTOPBIT;
236 if(stopbits==2) cc.dcb.StopBits = TWOSTOPBITS;
243 cc.dwProviderSubType = PST_RS232;
248 ret = SetCommConfig(
hdl,&cc,
sizeof(cc));
251 printf(
"SetCommConfig ret=%d devicename=%s LastError=%ld\n",ret,devicename,GetLastError());
258 RmEntryStruct CatEntry;
260 RmIOStatusStruct DrvSts;
261 RmBytParmStruct PBlock;
262 static UCD_BYT_PORT Ucd_byt_drv;
271 if (strcmp(devicename,
"COM1") == 0)
273 strcpy(byt_com,
"BYT_COM1");
276 else if(strcmp(devicename,
"COM2") == 0)
278 strcpy(byt_com,
"BYT_COM2");
283 printf(
"Error: devicename=%s unknown\n",devicename);
291 if( RmGetEntry( RM_WAIT, byt_com, &CatEntry ) != RM_OK )
293 printf(
"Error: %s device not found\n", byt_com);
297 device = (int) ((ushort) CatEntry.ide);
298 unit = (int) CatEntry.id;
303 if( RmIO( BYT_RESERVE, (
unsigned)(device), (
unsigned)(unit), 0u, 0u, &DrvSts, &PBlock ) < 0 )
305 printf(
"Error: Unable to reserve %s device\n", byt_com);
313 if(speed ==
B50 ) baudrate = 50;
314 if(speed ==
B75 ) baudrate = 75;
315 if(speed ==
B110 ) baudrate = 110;
316 if(speed ==
B134 ) baudrate = 134;
317 if(speed ==
B150 ) baudrate = 150;
318 if(speed ==
B200 ) baudrate = 200;
319 if(speed ==
B300 ) baudrate = 300;
320 if(speed ==
B600 ) baudrate = 600;
321 if(speed ==
B1200 ) baudrate = 1200;
322 if(speed ==
B1800 ) baudrate = 1800;
323 if(speed ==
B2400 ) baudrate = 2400;
324 if(speed ==
B4800 ) baudrate = 4800;
325 if(speed ==
B9600 ) baudrate = 9600;
326 if(speed ==
B19200 ) baudrate = 19200;
327 if(speed ==
B38400 ) baudrate = 38400;
328 if(speed ==
B57600 ) baudrate = 57600;
329 if(speed ==
B115200 ) baudrate = 115200;
330 if(speed ==
B230400 ) baudrate = 230400;
331 if(speed ==
B460800 ) baudrate = 460800;
332 if(speed ==
B500000 ) baudrate = 500000;
333 if(speed ==
B576000 ) baudrate = 576000;
334 if(speed ==
B921600 ) baudrate = 921600;
335 if(speed ==
B1000000) baudrate = 1000000;
336 if(speed ==
B1152000) baudrate = 1152000;
337 if(speed ==
B1500000) baudrate = 1500000;
338 if(speed ==
B2000000) baudrate = 2000000;
339 if(speed ==
B2500000) baudrate = 2500000;
340 if(speed ==
B3000000) baudrate = 3000000;
341 if(speed ==
B3500000) baudrate = 3500000;
342 if(speed ==
B4000000) baudrate = 4000000;
343 uTimeBd = 748800 / baudrate;
348 uMode = 0x1000 | DATA_8 | STOP_1 | NOPARITY;
355 PBlock.buffer = (
char *)&Ucd_byt_drv;
356 PBlock.timlen =
sizeof(UCD_BYT_PORT);
359 iStatus = RmIO( BYT_CREATE_NEW, (
unsigned)(device), (
unsigned)(unit), 0u, 0u, &DrvSts, &PBlock );
364 Ucd_byt_drv.mobyte[5] |= (ushort) (uMode & 0xFFu);
369 Ucd_byt_drv.header.timout = timeout;
374 PBlock.string = (
char*) &Ucd_byt_drv;
375 PBlock.strlen =
sizeof(UCD_BYT_PORT);
380 iStatus = RmIO( BYT_CREATE_NEW, (
unsigned)(device), (
unsigned)(unit), 0u, 0u, &DrvSts, &PBlock );
385 cByte = inbyte( com + 0x03 );
386 outbyte( com + 0x03, (
unsigned char)(cByte | 0x80) );
391 outbyte( com + 0x00, (ushort) LOW (uTimeBd) );
392 outbyte( com + 0x01, (ushort) HIGH (uTimeBd) );
397 outbyte( com + 0x03, cByte );
399 if( iStatus ) printf(
"BYT_CREATE_NEW (set ucb): Error status = %X\n", iStatus );
enum rlSerial::@4 ttystate
struct termios save_termios
unsigned short int vms_channel