{
#ifdef RLUNIX
struct termios buf;
fd = open(devicename, O_RDWR | O_NOCTTY | O_NDELAY);
if(
fd < 0) {
return -1; }
buf.c_cflag = speed | CLOCAL | CREAD;
if(rtscts == 1) buf.c_cflag |= CRTSCTS;
if(bits == 7) buf.c_cflag |= CS7;
else buf.c_cflag |= CS8;
if(stopbits == 2) buf.c_cflag |= CSTOPB;
buf.c_lflag = IEXTEN;
buf.c_oflag = OPOST;
buf.c_cc[VMIN] = 1;
buf.c_cc[VTIME] = 0;
#ifndef PVMAC
buf.c_line = 0;
#endif
buf.c_iflag = IGNBRK | IGNPAR | IXANY;
if(tcsetattr(
fd, TCSAFLUSH, &buf) < 0) {
return -1; }
if(block == 1) fcntl(
fd, F_SETFL, fcntl(
fd, F_GETFL, 0) & ~O_NONBLOCK);
#endif
#ifdef __VMS
struct dsc$descriptor_s dsc;
int status;
dsc.dsc$w_length = strlen(devicename);
dsc.dsc$a_pointer = (char *) devicename;
dsc.dsc$b_class = DSC$K_CLASS_S;
dsc.dsc$b_dtype = DSC$K_DTYPE_T;
if(status != SS$_NORMAL) return -1;
#endif
#ifdef RLWIN32
DWORD ccsize;
COMMCONFIG cc;
int baudrate,ret;
char devname[100];
if(strlen(devicename) > 80) return -1;
sprintf(devname,"\\\\.\\%s",devicename);
devname,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
0,
0
);
if(
hdl == INVALID_HANDLE_VALUE)
{
printf("CreateFile(%s) failed\n",devicename);
return -1;
}
baudrate = CBR_9600;
if(speed ==
B50 ) baudrate = 50;
if(speed ==
B75 ) baudrate = 75;
if(speed ==
B110 ) baudrate = CBR_110;
if(speed ==
B134 ) baudrate = 134;
if(speed ==
B150 ) baudrate = 150;
if(speed ==
B200 ) baudrate = 200;
if(speed ==
B300 ) baudrate = CBR_300;
if(speed ==
B600 ) baudrate = CBR_600;
if(speed ==
B1200 ) baudrate = CBR_1200;
if(speed ==
B1800 ) baudrate = 1800;
if(speed ==
B2400 ) baudrate = CBR_2400;
if(speed ==
B4800 ) baudrate = CBR_4800;
if(speed ==
B9600 ) baudrate = CBR_9600;
if(speed ==
B19200 ) baudrate = CBR_19200;
if(speed ==
B38400 ) baudrate = CBR_38400;
if(speed ==
B57600 ) baudrate = CBR_57600;
if(speed ==
B115200 ) baudrate = CBR_115200;
if(speed ==
B230400 ) baudrate = 230400;
if(speed ==
B460800 ) baudrate = 460800;
if(speed ==
B500000 ) baudrate = 500000;
if(speed ==
B576000 ) baudrate = 576000;
if(speed ==
B921600 ) baudrate = 921600;
if(speed ==
B1000000) baudrate = 1000000;
if(speed ==
B1152000) baudrate = 1152000;
if(speed ==
B1500000) baudrate = 1500000;
if(speed ==
B2000000) baudrate = 2000000;
if(speed ==
B2500000) baudrate = 2500000;
if(speed ==
B3000000) baudrate = 3000000;
if(speed ==
B3500000) baudrate = 3500000;
if(speed ==
B4000000) baudrate = 4000000;
GetCommConfig(
hdl,&cc,&ccsize);
cc.dcb.DCBlength = sizeof(DCB);
cc.dcb.BaudRate = baudrate;
cc.dcb.fBinary = 1;
cc.dcb.fParity = 1;
cc.dcb.fOutxCtsFlow = 0;
if(rtscts == 1) cc.dcb.fOutxCtsFlow = 1;
cc.dcb.fOutxDsrFlow = 0;
cc.dcb.fDtrControl = DTR_CONTROL_DISABLE;
cc.dcb.fDsrSensitivity = 0;
cc.dcb.fTXContinueOnXoff = 1;
cc.dcb.fNull = 0;
cc.dcb.fRtsControl = RTS_CONTROL_DISABLE;
if(rtscts == 1) cc.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
cc.dcb.fAbortOnError = 0;
cc.dcb.ByteSize = bits;
cc.dcb.Parity = 0;
cc.dcb.StopBits = ONESTOPBIT;
if(stopbits==2) cc.dcb.StopBits = TWOSTOPBITS;
cc.dwProviderSubType = PST_RS232;
ret = SetCommConfig(
hdl,&cc,
sizeof(cc));
if(ret == 0)
{
printf("SetCommConfig ret=%d devicename=%s LastError=%d\n",ret,devicename,GetLastError());
return -1;
}
#endif
#ifdef RM3
RmEntryStruct CatEntry;
int iStatus;
RmIOStatusStruct DrvSts;
RmBytParmStruct PBlock;
static UCD_BYT_PORT Ucd_byt_drv;
ushort uTimeBd;
uint uMode;
unsigned char cByte;
char byt_com[32];
if (strcmp(devicename,"COM1") == 0)
{
strcpy(byt_com,"BYT_COM1");
com = 0x3f8;
}
else if(strcmp(devicename,"COM2") == 0)
{
strcpy(byt_com,"BYT_COM2");
com = 0x2f8;
}
else
{
printf("Error: devicename=%s unknown\n",devicename);
return -1;
}
if( RmGetEntry( RM_WAIT, byt_com, &CatEntry ) != RM_OK )
{
printf( "Error: %s device not found\n", byt_com);
return -1;
}
device = (int) ((ushort) CatEntry.ide);
unit = (int) CatEntry.id;
if( RmIO( BYT_RESERVE, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock ) < 0 )
{
printf( "Error: Unable to reserve %s device\n", byt_com);
return -1;
}
baudrate = 9600;
if(speed ==
B50 ) baudrate = 50;
if(speed ==
B75 ) baudrate = 75;
if(speed ==
B110 ) baudrate = 110;
if(speed ==
B134 ) baudrate = 134;
if(speed ==
B150 ) baudrate = 150;
if(speed ==
B200 ) baudrate = 200;
if(speed ==
B300 ) baudrate = 300;
if(speed ==
B600 ) baudrate = 600;
if(speed ==
B1200 ) baudrate = 1200;
if(speed ==
B1800 ) baudrate = 1800;
if(speed ==
B2400 ) baudrate = 2400;
if(speed ==
B4800 ) baudrate = 4800;
if(speed ==
B9600 ) baudrate = 9600;
if(speed ==
B19200 ) baudrate = 19200;
if(speed ==
B38400 ) baudrate = 38400;
if(speed ==
B57600 ) baudrate = 57600;
if(speed ==
B115200 ) baudrate = 115200;
if(speed ==
B230400 ) baudrate = 230400;
if(speed ==
B460800 ) baudrate = 460800;
if(speed ==
B500000 ) baudrate = 500000;
if(speed ==
B576000 ) baudrate = 576000;
if(speed ==
B921600 ) baudrate = 921600;
if(speed ==
B1000000) baudrate = 1000000;
if(speed ==
B1152000) baudrate = 1152000;
if(speed ==
B1500000) baudrate = 1500000;
if(speed ==
B2000000) baudrate = 2000000;
if(speed ==
B2500000) baudrate = 2500000;
if(speed ==
B3000000) baudrate = 3000000;
if(speed ==
B3500000) baudrate = 3500000;
if(speed ==
B4000000) baudrate = 4000000;
uTimeBd = 748800 / baudrate;
uMode = 0x1000 | DATA_8 | STOP_1 | NOPARITY;
PBlock.string = 0;
PBlock.strlen = 0;
PBlock.buffer = (char *)&Ucd_byt_drv;
PBlock.timlen = sizeof(UCD_BYT_PORT);
PBlock.status = 0;
iStatus = RmIO( BYT_CREATE_NEW, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock );
Ucd_byt_drv.mobyte[5] |= (ushort) (uMode & 0xFFu);
Ucd_byt_drv.header.timout = timeout;
PBlock.string = (char*) &Ucd_byt_drv;
PBlock.strlen = sizeof(UCD_BYT_PORT);
PBlock.buffer = 0;
PBlock.timlen = 0;
PBlock.status = 0;
iStatus = RmIO( BYT_CREATE_NEW, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock );
cByte = inbyte( com + 0x03 );
outbyte( com + 0x03, (unsigned char)(cByte | 0x80) );
outbyte( com + 0x00, (ushort) LOW (uTimeBd) );
outbyte( com + 0x01, (ushort) HIGH (uTimeBd) );
outbyte( com + 0x03, cByte );
if( iStatus ) printf( "BYT_CREATE_NEW (set ucb): Error status = %X\n", iStatus );
#endif
return 0;
}