相关文章推荐
大气的电池  ·  NameError: name ...·  5 小时前    · 
不拘小节的米饭  ·  Tutorial: ML ...·  5 小时前    · 
愤怒的豆芽  ·  python ...·  48 分钟前    · 
伤情的红豆  ·  读取rtf文件python - CSDN文库·  46 分钟前    · 
闷骚的蛋挞  ·  使用pywin32 ...·  7 月前    · 
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.