Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending command via Arduino USB port causes reset (DTR) #9

Closed
bluespider42 opened this issue Sep 20, 2016 · 9 comments
Closed

Sending command via Arduino USB port causes reset (DTR) #9

bluespider42 opened this issue Sep 20, 2016 · 9 comments

Comments

@bluespider42
Copy link

bluespider42 commented Sep 20, 2016

Continued from: thijse/Arduino-CmdMessenger#11

When I send a simple acknowledge type message to the Arduino through the built-in USB/Serial interface it causes a reset of the Arduino.
However if I connect a external USB/Serial convertor directly to the Tx/Rx pins of the Arduino then it works , no problem.
The Arduino USB/Serial port works normally when not using CmdMessenger (ie for looking at debugging messages in tera term).

I suspect it is due to the DTR line being toggled on opening the connection.
I did try adding in a self.comm.setDTR(value) into the arduino.py of PyCmdMessenger but I think that was only having an affect after the port was opened (and after the reset had occurred).

@harmsm
Copy link
Owner

harmsm commented Sep 22, 2016

Sorry for the delay -- been busy doing my real job!

Can I get a quick clarification? Does the reset occur on connection or on sending the message? In other words, does it reset when you create the arudino object:

arduino = PyCmdMessenger.ArduinoBoard("/dev/ttyACM0",baud_rate=9600)

or when you actually send the message?

@harmsm
Copy link
Owner

harmsm commented Sep 23, 2016

Just poked around a bit on this. I'm not sure how you implemented self.comm.setDTR when you tried it. If this was done after the serial.Serial(STUFF) call in arduino.py, the port would indeed open before the setDTR took effect.

I just added a disable_dtr flag to the Arduino class on the add-dtr-flag branch. It will call setDTR before opening the port and should, I think, fix your problem. I don't have an arudino handy at the moment, but if you want to try it, the branch is here:

https://github.com/harmsm/PyCmdMessenger/tree/add-dtr-flag

@bluespider42
Copy link
Author

Thanks - I'm pretty sure it was on the port open rather than on sending a command.
I updated my version of PyCmdMessenger to the new branch and get the traceback below:

Traceback (most recent call last):
  File "myfile.py", line ##, in <module>
    arduino = PyCmdMessenger.ArduinoBoard(port, baud_rate=115200)
  File "...\arduino.py", line 65, in __init__
    self.open()
  File "...\arduino.py", line 159, in open
    self.comm.open()
  File "...\serial\serialwin32.py", line 39, in open
    raise SerialException("Port must be configured before it can be used.")
serial.serialutil.SerialException: Port must be configured before it can be used.

I'll have a go at fixing this at the weekend as this might even be within the remit of my limited python skill-set!

@harmsm
Copy link
Owner

harmsm commented Sep 23, 2016

Thanks for debug info. I can poke around with it this weekend as well.
I'll be able to actually plug an arduino in to my machine, rather than
hypothesizing about what should happen :). My guess is that a few more
attributes need to be set in serial.Serial instance before the
self.comm.open() call.

I don't have any windows boxes, though, so having your work on a windows
machine is quite helpful. Sometimes *nix and windows behave differently,
even in python.

Best,

Mike

On Sep 23, 2016 8:30 AM, "bluespider42" notifications@github.com wrote:

Thanks - I'm pretty sure it was on the port open rather than on sending a
command.
I updated my version of PyCmdMessenger to the new branch and get the
traceback below:

Traceback (most recent call last):
File "myfile.py", line ##, in
arduino = PyCmdMessenger.ArduinoBoard(port, baud_rate=115200)
File "...\arduino.py", line 65, in init
self.open()
File "...\arduino.py", line 159, in open
self.comm.open()
File "...\serial\serialwin32.py", line 39, in open
raise SerialException("Port must be configured before it can be used.")
serial.serialutil.SerialException: Port must be configured before it can be used.

I'll have a go at fixing this at the weekend as this might even be within
the remit of my limited python skill-set!


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEuQepu-UBDvX9il6vyY0c71kl29Gkhkks5qs_CVgaJpZM4KBjYv
.

@bluespider42
Copy link
Author

Just a note that setDTR() is deprecated now.

@bluespider42
Copy link
Author

Line 155
self.comm.device = self.device
should be
self.comm.port = self.device

@harmsm
Copy link
Owner

harmsm commented Sep 27, 2016

I worked on it this weekend with an arudino. The current version of the add-dtr-flag branch now runs and uses the correct method to set the DTR flag before opening, according the the pyserial API. Unfortunately, this still always resets the arduino when using my linux machine as a host. This may be a linux-specific issue, so it will hopefully work on your windows machine. If it works, please let me know. If it doesn't work, this problem might not be fixable without modding pyserial or switching serial libraries -- both of which are outside of my current bandwidth. Thanks for your interest in the library and help troubleshooting this issue.

@bluespider42
Copy link
Author

Hello, just tested this and it works fine on a Mega2560 and a FeatherM0 on windows 10 x64.
Eventually the device will be interfaced with a linux based machine so I will probably run into this issue again!
Thanks for your help.

Also spotted a typo in arduino.py #L95

@ozra
Copy link

ozra commented Oct 9, 2016

This is not much help, but, the pyserial PlatFormSpecific code looks short enough that it might not be too hard.
Just a quick glance points me to this line: https://github.com/pyserial/pyserial/blob/master/serial/serialposix.py#L271.

Anyway, just thought I'd throw that ball in the air. I'll code my own serial-lib, because I decided to use my own lang for interfacing with the arduino, so I can't be of help here, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants