Send bytes in Python with serial
Question: 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!


Answer: 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)
    

