Проблема решилась. Оказалось зависало при вызове writefile
Сделал явное определение структуры dcb и проблема исчезла
Код | port=CreateFile("COM2",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if(port==INVALID_HANDLE_VALUE) printf("Unable to open port\n");
dcb.DCBlength=sizeof(DCB); //BuildCommDCB("baud=9600 parity=N data=8 stop=1",&dcb); //dcb.fNull=TRUE;
// Get the default port setting information. GetCommState (port, &dcb);
// Change the DCB structure settings. dcb.BaudRate = 9600; // Current baud dcb.fBinary = TRUE; // Binary mode; no EOF check dcb.fParity = TRUE; // Enable parity checking dcb.fOutxCtsFlow = FALSE; // No CTS output flow control dcb.fOutxDsrFlow = FALSE; // No DSR output flow control dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type dcb.fDsrSensitivity = FALSE; // DSR sensitivity dcb.fTXContinueOnXoff = TRUE; // XOFF continues Tx dcb.fOutX = FALSE; // No XON/XOFF out flow control dcb.fInX = FALSE; // No XON/XOFF in flow control dcb.fErrorChar = FALSE; // Disable error replacement dcb.fNull = FALSE; // Disable null stripping dcb.fRtsControl = RTS_CONTROL_ENABLE; // RTS flow control dcb.fAbortOnError = FALSE; // Do not abort reads/writes on error dcb.ByteSize = 8; // Number of bits/byte, 4-8 dcb.Parity = NOPARITY; // 0-4=no,odd,even,mark,space dcb.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2
ct.ReadIntervalTimeout=10; ct.ReadTotalTimeoutMultiplier=ct.ReadTotalTimeoutConstant=0; ct.WriteTotalTimeoutMultiplier=ct.WriteTotalTimeoutConstant=0;
SetCommState(port,&dcb); SetCommTimeouts(port,&ct); PurgeComm(port,PURGE_TXCLEAR|PURGE_RXCLEAR); SetupComm(port,256,256);
WriteFile(port,sBuf,strlen(sBuf),&bc,NULL);
CloseHandle(port);
|
|