last day (14 days later) » 

2:41 PM
0
Q: Reconnecting with pySerial

RaevenI'm trying to write a function which continuously reads serial input. The function must be able to handle unexpected disconnections from the serial port and reconnect when possible. Despite reading several question posts on stackOverflow and looking through the pySerial documentation, I have yet ...

 
How are you exiting the program?
 
I'm not exiting the program. I'm trying to write the program so that it continues to run, even if the connection is lost.
 
Sorry, I misunderstood "leaving the program run". So what does happen when you disconnect whatever's connected to the port?
 
I have my output in the post. Do you need clarification?
 
Do you ever disconnect the device from your computer while the program is running?
 
2:41 PM
Yes, that's how I got my output.
 
So to make sure I fully understand your problem: After you disconnect the device, it continues to output "Writing Data...", or does it stop completely?
 
It stops completely.
 
I moved this to chat to avoid clogging the comments.
I am also misunderstanding what you're doing with the "serialPort -1" argument in your Serial object initialization. I thought that argument was a string, and either way why would you want to subtract it by 1?
 
It's not a string and because pySerial counts serial ports starting at 0
 
Perhaps it's different because I was working with Modems, but I always used that argument as a string. For example "COM60" or something like that. But I never tested it like that anyway and I don't think that's the problem so no big deal.
 
2:51 PM
Alright
 
I'm going to get a device and test it. I think I know what the issue is but I want to be sure.
 
Thank you
 
Hm, it works perfectly for me.
I don't know what kind of device you're using, I'm just testing it on my Arduino.
 
I just went back to my idle window and saw that it had reconnected. I guess it works but it just takes a while...
 
Some serial devices can be very slow.
 
2:58 PM
Hmmm
Alright then
thanks for everything
!
 
Sorry I didn't actually give you a specific solution, haha. No problem.
 
Haha I just appreciate the time
 

last day (14 days later) »