skip to Main Content

I’ve been trying to communicate with a piece of machinery.
I verified the COM port and baud rate and 8N1 setup and open port, etc. using manual CMD.
The manual indicates to use for start byte and / for end byte of telegram.

When I run it basically just hangs up, not sure what I’m doing wrong.

import serial char
ser = serial.Serial('COM6' , 115200)
ser.is_open
ser.write(b'p/')
s = ser.read(9)
print(s)

Code

3

Answers


  1. Chosen as BEST ANSWER

    Amazingly helpful = Saiprasad Balasubramanian + Mike67 + Bukzor + SuzukiBKing I was successful with your advice. I plan to add the conditional later, thx SB ;).

        import serial
        import time
        ser = serial.Serial('COM6' , 115200)
        ser.write(bytearray([47, 112, 92]))
        time.sleep(2)
        s = ser.read_all()
        print(s) 
    

  2. You could try it out this way. I don’t have a device to verify it

    import serial
    ser = serial.Serial('COM6' , 115200)
    
    if ser.isOpen(): # Check is Serial is Open
        ser.write(b'p/') # Write to Serial
        sleep(2) # Sleep for 2 seconds
        s = ser.read(9) # Read from Serial
    else:
       print("Serial is not open")
    
    
    Login or Signup to reply.
  3. From the manual it shows the returned codes for the "p" command as one or two characters. If you are trying to read 9 bytes with no timeout set it will hang until 9 bytes are received. Try using ser.read_all() after a short delay.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search