2

I have googled, read, experimented etc and still have had no luck sending a packet of 5 hex values over serial. Here is what I have tried:

import serial
import time

ser = serial.Serial(
    port='dev/serial0''
    baudrate=9600'
    parity=serial.PARITY_NONE'
    stopbits=serial.STOPBITS_ONE'
    bytesize=serial.EIGHTBITS,
    timeout=1
    )
#tried this
cw = b'0x55,0x18,0x03,0x06,0x01'
ser.write(serial.to_bytes(cw))

#tried this
cw = b'\x55\x18\x03\x06\x01'
ser.write(serial.to_bytes(cw)

the name of the file is serialtest.py
I've tried:
python serialtest.py

i've tried python 3:
python3 serialtest.py

it either prints out on minicom: jibberish or actually

0x55,0x18,0x03,0x06,0x01 

but I am not actually convinced this is actually hex data or just a string conversion of what is being sent. I can send the same hex packet from my windows box and the machine it is connected to does accordingly. Any help, ideas, examples, anything would be appreciated. I've wasted at least a week and a half on this.

  • Steve Amor answered the question below. His answer along with calculating the correct checksum – mScientist Apr 10 at 2:36
2

Try it with:

cw = [0x55,0x18,0x03,0x06,0x01]

ser.write(serial.to_bytes(cw))
  • still looks like it may be sending characters instead of hex. It is sending (or reading rather on the loopback in minicom) a U, which is 0x55 ascii. – mScientist Apr 8 at 20:22
  • @mScientist remember that "hex" is just a representation of a value, just as "U" (in ASCII encoding) is. – Ghanima Apr 8 at 20:29
  • how would I pass in one of the hex values as a variable? – mScientist Apr 8 at 20:56
  • You are asking a different question to the original post. cw in my example above is a Python list. If we assume that 0x03 is the hex value you want to change, you can change it with the following cw[2] = variable – Steve Amor Apr 9 at 7:46
1

sending a packet of 5 hex values, ...

I agree with the above comments that the character "U" is encoded in ASCII as "0x55".
In other words, sending "U" is the same thing as sending "0x55".

To make things as simple as possible, I have tried sending only 1 hex value, instead of 5 hex values:

  1. Repeatedly sending b'\0x55'
  2. Repeatedly sending b'\0x5a'

Below are the scope screen captures. If you think I am doing what you have been trying, I can do more examples such as sending the following:

  1. b'\0x55\0x5a\0x5a\0x5a\0x55'
  2. b'UUUUU'

You can find my python send char/hex program in the answer of the following post. Serial to Arduino totally non-responsive

send 0x55 1/2 send 0x55 2/2 send 0xa5 1/2 send 0xa5 2/2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.