Problem reading USB Serial data into Windows

Post here first, or if you can't find a relevant section!
User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Problem reading USB Serial data into Windows

Postby RogerClark » Tue Mar 14, 2017 9:43 am

I'm trying to debug some Windows code that receives serial data from the USB Serial driver on windows (usbser.sys) which uses

CreateFileA(m_device.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

to open \\.\COMxx

ReadFile(m_handle, m_readBuffer, m_readLength, &bytes, &m_readOverlapped);

But ReadFile always returns 0 bytes available

The sketch which sends the data works find on the Arduino DUE, but I'm not sure if that uses usbser.sys, or whether its a custom Atmel driver


I suspect the problem is somewhere in the way that Windows reads from usbser but I'm not sure where to look.

Edit

The PC code is from here

https://github.com/g4klx/MMDVMHost

The Arduino code is here, https://github.com/juribeparada/MMDVM_HS but the Arduino code works fine with the Linux version
Last edited by RogerClark on Tue Mar 14, 2017 10:48 am, edited 1 time in total.

User avatar
BennehBoy
Posts: 388
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Problem reading USB Serial data into Windows

Postby BennehBoy » Tue Mar 14, 2017 9:59 am

This could be tangential, but the ELM327 emulator that I was using would not function on Windows 10 - this is because MS have changed the way that USB serial is handled (it may have actually been at Win7 or 8) - I had to run the emulator on XP in order for it to correctly hook a COM port.

Info from MS -> https://blogs.msdn.microsoft.com/usbcor ... indows-10/
-------------------------------------
https://github.com/BennehBoy

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Problem reading USB Serial data into Windows

Postby RogerClark » Tue Mar 14, 2017 10:50 am

BennehBoy wrote:This could be tangential, but the ELM327 emulator that I was using would not function on Windows 10 - this is because MS have changed the way that USB serial is handled (it may have actually been at Win7 or 8) - I had to run the emulator on XP in order for it to correctly hook a COM port.

Info from MS -> https://blogs.msdn.microsoft.com/usbcor ... indows-10/


Thanks

I'm running W7.

I'm pretty sure its the way the PC host program interacts with the USB serial driver.

I recall writing some PC USB Serial code some time ago, but I can't remember how I got it to work.
I think I used someone's "helper" library, rather than worrying about the low level code

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Problem reading USB Serial data into Windows

Postby RogerClark » Wed Mar 15, 2017 10:47 pm

Thanks to Daniel,

It looks like at least one of the issues is that DTR needs to be enabled for usb serial write() to work.

I looked in the core and isConnected() checks the state of DTR, which is understandable as the IDE sets DTR when the terminal is opened.

However, isConnected() is also checked in USBSerial::write() which means it won't write bytes unless DTR is set.

I recall some other users reporting issues with some terminal programs, and I suspect this is because write() does not write without DTR being set
but not all terminals set this

Apparently the Due will write to serial, regardless if DTR is set or not.

So I'm wondering if this should be changed to that write() doesnt check DTR and perhaps just checks

usb_is_connected(USBLIB) && usb_is_configured(USBLIB)


But I'll need to check what usb_is_connected() and usb_is_configured() are testing for, and whether they are both needed as well.
I suspect they still are.

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Problem reading USB Serial data into Windows

Postby RogerClark » Thu Mar 16, 2017 9:59 am

In case anyone is interested ;-)

I've updated the ZUMspot branch again and reinstated the checking for "is usb configured" and "is usb connected" by directly calling those functions from write().

So the only difference is that DTR does not need to be set before write() will work.

This still works with the ZUMspot MMDVM code.

I will need to do some more testing, but I doubt this change causes any problems at all, and just makes the core more compatible with the Due and probably the Zero.

If I get chance I'll see if I can test the STM core to see if it will send if DTR is not enabled (but I'll need to find a terminal program - possibly Coolterm which allows the DTR to be set or reset)

User avatar
zoomx
Posts: 352
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: Problem reading USB Serial data into Windows

Postby zoomx » Thu Mar 16, 2017 10:04 am

Maybe handshake is hardware instead of none?

I use Visual Studio and I don't need to set DTR when writing or reading from a serial port using USB adapters.

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Problem reading USB Serial data into Windows

Postby RogerClark » Thu Mar 16, 2017 10:25 am

zoomx wrote:Maybe handshake is hardware instead of none?

I use Visual Studio and I don't need to set DTR when writing or reading from a serial port using USB adapters.


When using Visual Studio, I had to set DTR before I could receive data from the STM32, but not all software sets DTR ( which was the problem in this case)

I did try to modify the PC ( Visual Studio) source code to enable DTR, but as I didnt write the PC code, it was easier to make the change to the core, as I think the core should probably not need DTR to be set before it will write data.

It also means the author of the PC code does not need to make a special version just to support the STM32, as they already had a version that works fine on the Due, but would not work on the STM32 before I made this change.


Return to “General discussion”

Who is online

Users browsing this forum: michael_l and 2 guests