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.

Chad G
  • 1,063
  • 1
  • 7
  • 14
mScientist
  • 107
  • 1
  • 1
  • 6

2 Answers2

2

Try it with:

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

ser.write(serial.to_bytes(cw))
bummi
  • 109
  • 3
Steve Amor
  • 36
  • 1
2

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

tlfong01
  • 4,847
  • 3
  • 12
  • 24