[SOLVED] USB Serial communication fails after repeated queries

rekh127:

dlinear:
I think the problem is with the driver on the PC. I'm attaching waveforms I collected from the Arduino (pins 1 and 2) showing the data being sent/received and I can see signals on the USB lines (differential and occurring much much faster). But I still can't receive data (can send).

I can use the "devcon" command from Microsoft to reset the Arduino USB port from the command line, and this resets the serial communication. I have to waive the white flag and use this hack as a solution, but this is hardly solved.

Could you detail what you're doing with the devcon command? I think I've been having this same issue and haven't found anyway to fix it. Is it a disable/enable command on the arduino.? Maybe you can just post the code that you run? Thank you for your help.

With pleasure. It was complicated for me because you need Administrator permissions to reset the USB port and I don't want my program to run with Admin permissions. Thus, I had to add a task to the "Task Scheduler" in windows, and checked the "Run with highest privileges" option under Security options. This allowed me to bypass the UAC in windows.

In the task scheduler, under actions, I added a task to "Start a program", and put the path to devcon.exe. The important part is to add an argument to restart "USB\VID_2341&PID_0043&REV_0001"

Thus, I run the command

devcon.exe restart "USB\VID_2341&PID_0043&REV_0001"

Then in matlab, I issue the command (under the same user)

schtasks /run /TN "NAME_OF_TASK"

where NAME_OF_TASK is the name of the scheduled task.

Critically, I must close the port first and also wait 3 seconds before reopening the serial connection. I didn't test the minimum amount of wait time, but I know you need some time because without the delay, it wouldn't work.

I've been testing this all weekend, and now my program recovers from this failure gracefully.