Python- hex to bytes for passing to a socket address

Question:

I am trying to send a byte command to an RFID connected to a Raspberry Pi.
the code i’m using is

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('192.168.0.178', 4001)
sock.connect(server_address)

cmd=bytes.fromhex('A00372')
sock.sendall(cmd)
s=sock.recv(1024 * 4)
print(s) 

if i check what cmd is, it is returned as b’xa0x03r’ instead of b’xa0x03x72′

any help will be appreciated

I’ve tried researching but with not much luck including
binascii.hexlify(cmd).decode(‘utf-8’)

Asked By: LappyDog

||

Answers:

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('192.168.0.178', 4001)
sock.connect(server_address)

cmd = bytes.fromhex('A0 03 72')
sock.sendall(cmd)
s = sock.recv(1024 * 4)
print(s)

Does this worked?

Answered By: ItsMe
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.