Issue with RTS control via usbser.sys

  • Thread starter Thread starter Marian___
  • Start date Start date
M

Marian___

Guest

I am trying to control RTS signal on my USB-UART device on Windows 10 and found that the usbser.sys driver does not generate any USB SET_CONTROL_LINE_STATE requests for EscapeCommFunction(hndl, SETRTS) or EscapeCommFunction(hndl, CLRRTS) calls as expected. As results, RST signal is being unchanged on UART device.





My example is based on Configuring a Communications Resource - Win32 apps as following:





<code>


#include <windows.h>


#include <tchar.h>


#include <stdio.h>





int _tmain(int argc, TCHAR* argv[])


{


DCB dcb;


HANDLE hCom;


BOOL fSuccess;


TCHAR *pcCommPort = (TCHAR*)TEXT("COM9");





// Open a handle to the specified com port.


hCom = CreateFile(pcCommPort,


GENERIC_READ | GENERIC_WRITE,


0, // must be opened with exclusive-access


NULL, // default security attributes


OPEN_EXISTING, // must use OPEN_EXISTING


0, // not overlapped I/O


NULL); // hTemplate must be NULL for comm devices





if (hCom == INVALID_HANDLE_VALUE)


{


// Handle the error.


printf("CreateFile failed with error %d.\n", GetLastError());


return (1);


}





// Initialize the DCB structure.


SecureZeroMemory(&dcb, sizeof(DCB));


dcb.DCBlength = sizeof(DCB);





// Build on the current configuration by first retrieving all current


// settings.





fSuccess = GetCommState(hCom, &dcb);





if (!fSuccess)


{


// Handle the error.


printf("GetCommState failed with error %d.\n", GetLastError());


return (2);


}





// Fill in some DCB values and set the com state:


// 115,200 bps, 8 data bits, no parity, and 1 stop bit.


dcb.BaudRate = CBR_115200; // baud rate


dcb.ByteSize = 8; // data size, xmit and rcv


dcb.Parity = NOPARITY; // parity bit


dcb.StopBits = ONESTOPBIT; // stop bit


dcb.fDtrControl = DTR_CONTROL_DISABLE;


dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;





fSuccess = SetCommState(hCom, &dcb);





if (!fSuccess)


{


// Handle the error.


printf("SetCommState failed with error %d.\n", GetLastError());


return (3);


}





// Set RTS


fSuccess = EscapeCommFunction(hCom, SETRTS); // SET_CONTROL_LINE_STATE request is expected here on the USB bus, but nothing happens.





if (!fSuccess)


{


// Handle the error.


printf("GetCommState failed with error %d.\n", GetLastError());


return (2);


}





_tprintf(TEXT("RTS is set\n"));





Sleep(1000); // Sleep for one second





// Clear RTS





fSuccess = EscapeCommFunction(hCom, CLRRTS); // SET_CONTROL_LINE_STATE request is expected here on the USB bus, but nothing happens.





if (!fSuccess)


{


// Handle the error.


printf("GetCommState failed with error %d.\n", GetLastError());


return (2);


}





_tprintf(TEXT("RTS is clear\n"));





Sleep(1000); // Sleep for one second





_tprintf(TEXT("Serial port %s successfully reconfigured.\n"), pcCommPort);





return (0);


}





</code>





Expected Result: After EscapeCommFunction(hndl, SETRTS) or EscapeCommFunction(hndl, CLRRTS) calls on the USB bus, SET_CONTROL_LINE_STATE request appears which reflects the RTS change.





Actual Result: After EscapeCommFunction(hndl, SETRTS) or EscapeCommFunction(hndl, CLRRTS) calls, no SET_CONTROL_LINE_STATE request appears on the USB bus at all. As results, RST signal is being unchanged on UART device. Note: that RST can be changed if enforce the updating DTR signal right after that.


A similar question was asked several years ago, but there was not answered:
Virtual serial port (USBSER.SYS) is not sending RTS/CTS via SET_CONTROL_LINE_STATE packets.


Could you please clarify whether this is an expected behavior of usbser.sys?





Thanks,


Marian


Continue reading...
 
Back
Top