Sailwork
Posts: 22
Joined: Wed May 19, 2021 10:36 pm

Serial communication

Thu Sep 16, 2021 4:42 pm

Hello, I want to send command use PELCO-D protocol with UART interface. I alredy use class Serial for connection settings like:

Code: Select all

import time
import serial
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT, initial = GPIO.HIGH)
send = serial.Serial(
    port ='/dev/serial0',
    baudrate = 9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1 
    )
And I want to send with UART special command for example: FF 01 00 04 3F 00. How can I implement this? I tried to write code like this:

Code: Select all

i = [255,1,0,4,63,0]
for x in i:
 send.write(x)
 time.sleep(0.1)
GPIO.output(7, GPIO.LOW)
GPIO.cleanup()
but it doesnt work. Any ideas? What I do wrong? Please help.

User avatar
scruss
Posts: 4477
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Serial communication

Thu Sep 16, 2021 5:37 pm

Try using:

Code: Select all

 send.write(bytes([x]))
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Sailwork
Posts: 22
Joined: Wed May 19, 2021 10:36 pm

Re: Serial communication

Fri Sep 17, 2021 3:40 pm

scruss wrote:
Thu Sep 16, 2021 5:37 pm
Try using:

Code: Select all

 send.write(bytes([x]))
Thank you for help with this

Return to “Python”