int connectRobot(struct robot *rbt, int comPort)
{
char portname[20];
sprintf(portname,"COM%d",comPort);
//sprintf(portname,"\\\\.\\COM%d",comPort);
hSerialPort[rbt->serialConnection] = CreateFileA(portname,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (hSerialPort[rbt->serialConnection] == INVALID_HANDLE_VALUE) return -1;
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(hSerialPort[rbt->serialConnection], &dcbSerialParams)) return -2;
dcbSerialParams.BaudRate = 115200;
dcbSerialParams.ByteSize = 8;
dcbSerialParams.StopBits = ONESTOPBIT;
dcbSerialParams.Parity = NOPARITY;
comt.ReadIntervalTimeout = 500;
SetCommTimeouts( hSerialPort[rbt->serialConnection], &comt);
if (!SetCommState(hSerialPort[rbt->serialConnection], &dcbSerialParams)) return -3;
rbt->port=comPort;
rbt->connected=1;
return 0;
}
int connectRobot(struct robot *rbt, int comPort)
{
char portname[20];
sprintf(portname,"COM%d",comPort);
//sprintf(portname,"\\\\.\\COM%d",comPort);
hSerialPort[rbt->serialConnection] = CreateFileA(portname,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (hSerialPort[rbt->serialConnection] == INVALID_HANDLE_VALUE) return -1;
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(hSerialPort[rbt->serialConnection], &dcbSerialParams)) return -2;
dcbSerialParams.BaudRate = 115200;
dcbSerialParams.ByteSize = 8;
dcbSerialParams.StopBits = ONESTOPBIT;
dcbSerialParams.Parity = NOPARITY;
comt.ReadIntervalTimeout = 500;
SetCommTimeouts( hSerialPort[rbt->serialConnection], &comt);
if (!SetCommState(hSerialPort[rbt->serialConnection], &dcbSerialParams)) return -3;
rbt->port=comPort;
rbt->connected=1;
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks