2

I have a device that communicate via serial com port. From time to time , the device stuck and I don't have access to read any information from it.Only when I physically disconnect and re-connect the device from my computer , i can read the data again. Can I do it (disconnect and connect ) with python script?

when I tried to open the com port i print connection data:

def print_connection_data(self):
    logger.info("checking if port is opened:")
    logger.info(self.ser.isOpen())
    logger.info("checking if we have characters to read:")
    logger.info(self.ser.inWaiting())
    logger.info("getting settings dict:")
    logger.info(self.ser.getSettingsDict())

and the results are:

  • 2015-04-13 18:33:45,322 - wtests - INFO - checking if port is opened:
  • 2015-04-13 18:33:45,322 - wtests - INFO - True
  • 2015-04-13 18:33:45,323 - wtests - INFO - checking if we have characters to read:
  • 2015-04-13 18:33:45,323 - wtests - INFO - 0
  • 2015-04-13 18:33:45,323 - wtests - INFO - getting settings dict:
  • 2015-04-13 18:33:45,323 - wtests - INFO - {'parity': 'N', 'baudrate': 9600, 'bytesize': 8, 'xonxoff': False, 'interCharTimeout': None, 'rtscts': False, 'timeout': 1, 'stopbits': 1, 'dsrdtr': False, 'writeTimeout': None}
Carlos E. Ferro
  • 930
  • 10
  • 21
Oren
  • 21
  • 3
  • So the device has no external power beyond the com port otherwise? What operating system are you using? – MaxQ Apr 14 '15 at 08:25
  • the device has external power , 220V which can not be controlled . – Oren Apr 14 '15 at 08:31
  • Operating system - windows 7 – Oren Apr 14 '15 at 08:31
  • So you don't need to unplug the device entirely to get it working it again (i.e. resetting it)? – MaxQ Apr 14 '15 at 08:38
  • I'm trying to visualise the problem here... you could either unmount/mount it with [MountVol](https://technet.microsoft.com/en-us/library/bb490934.aspx) I think or you could get a separate device that has no other purpose than to pull the reset high. – MaxQ Apr 14 '15 at 08:50
  • MountVol is only for drives ? as you mention, I don't have option to reset the device otherwise (i.e. with power down) – Oren Apr 14 '15 at 08:54
  • Sorry @Oren, I'm still unclear: When you unplug the device from the computer, does it cut the power to the chip as well and cause a reset? – MaxQ Apr 14 '15 at 08:59
  • No , when I unplug the device from the computer the device is still powered. – Oren Apr 14 '15 at 09:16
  • BTW , the device is http://www.tti-test.com/products-tti/psu/ex355p.htm (this one with the USB) – Oren Apr 14 '15 at 09:17
  • Does it work flawlessly with something like [Putty](http://kb.cyberoam.com/default.asp?id=2193) and hence really only a Python problem? Otherwise you might try electronics.stackexchange.com who will be in a lot better position to debug the electronics. – MaxQ Apr 14 '15 at 09:28
  • No , it doesn't work with putty as well.I don't want to debug the electronics of the device , just want to do "cable disconnect" with python script – Oren Apr 14 '15 at 10:55
  • @Owen You can run command line from Python using the OS library. I'd ask a new question on how to restart it from command line, leaving python out of the picture for now and add that bit later. I've looked but can't find anything. – MaxQ Apr 14 '15 at 11:06
  • Thanks Mike! this exactly what I'll do (using Devcon) – Oren Apr 14 '15 at 12:40
  • @Oren I am also in same situation where my serial device stucks and do not respond from python as well as from any serial port monitor. How did you resolve your issue. Did you find a way to reset serial com port from python. I am using Ubuntu os – S Andrew Jun 07 '21 at 08:15

0 Answers0