Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Working on raspberry with Arduino connected over USB. Communicating over python with minimalmodbus library Trying to make reconnection when Arduino was unplugged for a while.
I tried to repeat the connection code again on error, didn't helped.
Is there any function to reconnect on the serial connection lost?
minimalmodbus.baudrate = 9600
instr = minimalmodbus.Instrument('COM5', 1)
instr.serial.baudrate=9600
instr.debug=False
You may be facing this problem because you are not closing the COM port. Therefore, you can try first closing that by using below command:
instrument.close_port_after_each_call= True
Your code should look like this:
minimalmodbus.baudrate = 9600
instr = minimalmodbus.Instrument('COM5', 1)
instr.serial.baudrate=9600
instr.debug=False
instr.close_port_after_each_call= True
except:
print('please check your connection')
More Here
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.