相关文章推荐
有情有义的大白菜  ·  python ...·  1 月前    · 
完美的馒头  ·  python QTreeWidget ...·  4 周前    · 
失眠的烤红薯  ·  python qt textBrowser ...·  3 周前    · 
帅气的领带  ·  【Pyspark ...·  1 周前    · 
近视的橙子  ·  python ...·  1 周前    · 
玩足球的毛巾  ·  MediaScannerConnection ...·  1 年前    · 
爱笑的花生  ·  PHP 中 cURL ...·  1 年前    · 
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.