0

I'm trying to send 10 bits thought raspberry pi USB port splitting them in two bytes and manipulating the first for identifying it with this code:

import serial
ser = serial.Serial(
    port='/dev/ttyACM0',
    baudrate = 38400,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
    )

while 1:
    val=input()

    a= bytes((val>>8) | 0xA0)
    a1=bytes(val & 0x00ff)

    ser.write(a)
    ser.write(a1)

but it seems to send the ASCII code instead of the binary data and I don't find a way to solve the problem! Can anybody help me please?? Thanks a lot!

1 Answer 1

1

I've now solved the problem, the right code is:

val=input()

a= chr((val>>8) | 0xA0)
a1=chr(val & 0x00ff)

ser.write(a)
ser.write(a1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.