send hexadecimal package variable UART - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: send hexadecimal package variable UART (/thread-30655.html) |
send hexadecimal package variable UART - santos20 - Oct-30-2020 Hello , guys i am new using python i would like to send a package of hexadecimal values using the uart the problem it is two of the values are variables i have done a lot of research and i cant find anything it will be really helpful here is my code basically i am trying to send this
contition=True while contition: main_input = int(input("select a number: ")) if main_input == 13: contition == False break elif main_input == 1: light_val = int(input("insert the new threshold value: ")) a = (1, 10, light_val) csum = sum(a) csum = hex( csum^ 0xFF) print(csum) b = hex(light_val) c = hex(10) d = hex(1) e = hex(65) y = (e, c, d, b, csum) x = b'\x41\x0A\x01\x05\EF' #ser.write(x) #ser.write(Y) print(Y) else: print(" Not Valid choice")thanks a lot RE: send hexadecimal package variable UART - bowlofred - Oct-30-2020 Are you trying to send string (ascii) representations or are you trying to send byte values? To send a ten, do you want to send a numeric 10, or an ascii "1" followed by an ascii "0"? The "output" you show above is a bytes object (so numeric), while you have hex() calls all over your code which is creating strings. RE: send hexadecimal package variable UART - Larz60+ - Oct-30-2020 bolofred is correct. for unsigned bytes: hexadecimal is the base 16 representation of byte (8 bits) data decimal is base 10 octal base 8 binary base 2 char is value assigned to first 127 bits of a byte, or all 256 bits if extended ascii is used. html is decimal value, zero padded, preceeded with &# Example: Each is a representation of the same byte value.
|