I know that something that worked in a previous version and now doesn't is always a bug.
Anyway: When this open_com subroutine is used for opening COM ports on Pelles C 7.0 versions it runs fine, on 8.0 it can't receive anything:
//Prototype:
HANDLE open_com(int com_port, int baud, char *info_str);
HANDLE Com_id;
HANDLE Com_id_drv;
//Later on:
Com_id_drv = open_com(Blwtbl.com, Drivebaud, Brate);
Com_id = open_com(Sensorcom, 9600, Xrate);
//Subroutine:
HANDLE open_com(int com_port, int baud, char *info_str)
{
DCB dcb_com;
COMMTIMEOUTS comtimeout;
HANDLE port_handle = (HANDLE) -1;
strcpy(info_str, "unintialized");
if(com_port != 0)
{
sprintf(info_str, "COM%1d:", com_port);
port_handle = CreateFile(info_str, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
sprintf(info_str, "COM%1d:%d,n,8,1", com_port, baud);
if(port_handle <=(void *) 0)
{
MessageBox(Wsetup, "COM Port Open Error", "ERROR", MB_OK);
//setup_event("Cannot access COM Port");
}
else
{
BuildCommDCB(info_str, &dcb_com);
dcb_com.fOutX = 0;
dcb_com.fInX = 0;
dcb_com.Parity = NOPARITY;
dcb_com.BaudRate = baud;
dcb_com.ByteSize = 8;
dcb_com.StopBits = ONESTOPBIT;
dcb_com.fParity = 0;
dcb_com.fOutxCtsFlow = 0;
dcb_com.fOutxDsrFlow = 0;
SetCommState(port_handle, &dcb_com);
comtimeout.ReadIntervalTimeout = MAXDWORD;
comtimeout.ReadTotalTimeoutMultiplier =0;
comtimeout.ReadTotalTimeoutConstant = 0;
comtimeout.WriteTotalTimeoutMultiplier = 0;
comtimeout.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(port_handle, &comtimeout);
FlushFileBuffers(port_handle);
}
}
return port_handle;
}
void close_com(HANDLE com_id)
{
if(com_id != (void *) 0)
{
CloseHandle(com_id);
com_id = (void *) 0;
}
}
//And example data request:
sprintf(buf, "#%01d\r", 1);
mk_ucase(buf);
WriteFile(Com_id, buf, strlen(buf), &Written, NULL);
//And the read that fails on 8.0 but works on 7.0:
temp = ReadFile(Com_id, buf, 256, &nReadChars, 0);
The I/O device has LED's on transmit and receive.
In both version, the LED's are showing data going out and responses coming back in.
The only difference is that with 8.0 the data does not get sensed by ReadFile.
So I assume that something in a library must be functioning differently.