Object with buffer protocol required.



  • Hello all,

    I am trying to use the UART of a WiPy 3.0 to send data to a computer. I can read data in just fine but get an error when trying to transmit data stating object with buffer protocol required. Basically I send 0xA1 then 0xFE to the WiPy module from the computer and store it in a variable uart_Rx_buffer. Later, I wish to send the second byte 0xFE back to the computer.

    definition of uart_Rx_buffer:

    uart_Rx_buffer = [0, 0]
    

    The rest of my code:

                if uart.any():       #check for data in stream receive buffer
                    uart_Rx_buffer = uart.read(2)       #read and store 2 bytes of data, this also clears the stream receive buffer
                    
                    if uart_Rx_buffer[0] == 0xA1:
                        services = BluetoothConnection.services()   #get services from connected device
                        for service in services:
                            chars = service.characteristics()       #get characteristics from services of connected device
                            for char in chars:                      #scroll through characteristics and write to any that have correct set properties
                                if (char.uuid() == 22):
                                    #char.write(chr(int(bin(uart_Rx_buffer[1]))))       #write UART data to characteristic
                                    #print(uart_Rx_buffer[1])
                                    uart.write(uart_Rx_buffer[1])       #echo data back to MSP430
    

    I've seen this thread, but the answer is to convert the data to a string.. which outputs 3 bytes, in ascii 2, 5, 4.. which is correct 254 = FE but I want to transmit one byte that is 254. How can I do this?



  • @livius Thank you so much!!! That works for me! Not sure how long it would have taken me to properly use brackets [ ].



  • @nick9995
    uart.write(bytes([uart_Rx_buffer[1]]))



  • Thanks for the reply. I did try it but I just get 0x00 transmitted out like 30 ish times...

    I had it commented out but:

    uart.write(chr(int(bin(uart_Rx_buffer[1]))))
    

    This line works to send the byte stored in uart_Rx_buffer[1] so long as the byte is stored as the decimal value.

    For example, 0xFE = 254 in decimal. If I load uart_Rx_buffer[1] with 0xFE, I just get errors no matter what I try. If I load it with 254, it works just fine.

    Since I am at my deadline for this project, I will just stick with my current solution since it is acceptable. I was hoping to solve this issue but it is more of a curiosity than necessity.



  • @nick9995 said in Object with buffer protocol required.:

    uart.write(uart_Rx_buffer[1])

    try this:
    uart.write(bytes(uart_Rx_buffer[1]))

    i write from memory i heave not device currently on hand


 

Hello World?

Pylife on Kickstarter - November 2018








Back Us On Kickstarter >

Pycom on Twitter