K
kudruu
Hello,
I am having a problem configuring a certain port on my computer. I
want to loop through a list of active ports and listen to the one that
is giving me the data packets I need.
Right now it loops through the ports just fine but upon trying to
configure the ports with //./COMx configuration, SetCommState believes
that a port is valid even if it's not and then the program freezes at
ReadFile.
My port configuration is as follows:
BOOL updateConnection( HANDLE hndl )
{
time_t TimeSec = 0;
DCB dcb = {0};
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = 230400; // BAUDRATE(TTYInfo);
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
dcb.fErrorChar = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fAbortOnError = FALSE;
dcb.wReserved = 0;
dcb.XonLim = 1;
dcb.XoffLim = 256;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT; // STOPBITS(TTYInfo);
dcb.EvtChar = EV_RXCHAR;
dcb.fParity = FALSE;
dcb.EofChar = '\n';
if (!SetCommState( hndl, &dcb)) //This does not fail where
expected
{
return FALSE;
}
getAllRs232( 0 );
return goodMSG;
}
BOOL listenOnActivePort(int nBus)
{
.... //Declarations
....//Loop to cycle through active ports
{
....//Try port without "\\.\" COM configuration
strcpy(&tempString,"\\\\.\\");
strcat(&tempString,activecomports[port]);
strcpy(activecomports[port],&tempString);
(HANDLE)fd[nBus] = CreateFile(activecomports[port], GENERIC_READ, 0,
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
if( updateConnection( (HANDLE)fd[nBus] ) == 1)
{
return TRUE;
}
}
The first step of getAllRs232 is to determine the number of bytes in
the packet being sent, by calling:
ReadFile( (HANDLE)fd, (LPVOID)buf, (DWORD)bufSiz,
(LPDWORD)&nBytesRead, NULL );
This is where my program hangs up. I want it to cycle through the
ports and ultimately (on this specific computer) listen to port
configuration \\.\COM31, however it hangs up on the readfile on the
first instance (\\.\COM12). Is there a reason why SetCommState is not
returning an error for my specific configuration? There should not be
any data coming off any port now except COM31 or COM32.
Thank you very much in advance for any help!
I am having a problem configuring a certain port on my computer. I
want to loop through a list of active ports and listen to the one that
is giving me the data packets I need.
Right now it loops through the ports just fine but upon trying to
configure the ports with //./COMx configuration, SetCommState believes
that a port is valid even if it's not and then the program freezes at
ReadFile.
My port configuration is as follows:
BOOL updateConnection( HANDLE hndl )
{
time_t TimeSec = 0;
DCB dcb = {0};
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = 230400; // BAUDRATE(TTYInfo);
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
dcb.fErrorChar = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fAbortOnError = FALSE;
dcb.wReserved = 0;
dcb.XonLim = 1;
dcb.XoffLim = 256;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT; // STOPBITS(TTYInfo);
dcb.EvtChar = EV_RXCHAR;
dcb.fParity = FALSE;
dcb.EofChar = '\n';
if (!SetCommState( hndl, &dcb)) //This does not fail where
expected
{
return FALSE;
}
getAllRs232( 0 );
return goodMSG;
}
BOOL listenOnActivePort(int nBus)
{
.... //Declarations
....//Loop to cycle through active ports
{
....//Try port without "\\.\" COM configuration
strcpy(&tempString,"\\\\.\\");
strcat(&tempString,activecomports[port]);
strcpy(activecomports[port],&tempString);
(HANDLE)fd[nBus] = CreateFile(activecomports[port], GENERIC_READ, 0,
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
if( updateConnection( (HANDLE)fd[nBus] ) == 1)
{
return TRUE;
}
}
The first step of getAllRs232 is to determine the number of bytes in
the packet being sent, by calling:
ReadFile( (HANDLE)fd, (LPVOID)buf, (DWORD)bufSiz,
(LPDWORD)&nBytesRead, NULL );
This is where my program hangs up. I want it to cycle through the
ports and ultimately (on this specific computer) listen to port
configuration \\.\COM31, however it hangs up on the readfile on the
first instance (\\.\COM12). Is there a reason why SetCommState is not
returning an error for my specific configuration? There should not be
any data coming off any port now except COM31 or COM32.
Thank you very much in advance for any help!