Dear friends this is a humble request to solve my problem with example please. I am working on RFID sensors in which i need to send Hexadecimal data to socket. here is my code
import socket
HOST = '192.168.0.115'
PORT = 20108
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
DATA = 'A5 5A 00 08 04 0C 0D 0A'
s.send(DATA)
data = s.recv(4096)
s.close()
d = data.encode('hex').upper()
print 'Received', repr(d)
this code is sending DATA in string format but i need to send the DATA in Hexadecimal format because the RFID reader can read Hexadecimal data... i already use struct.pack but it is not working for me or may be I don't know how to use it...
the DATA is same "A5 5A 00 08 04 0C 0D 0A" this but how do i send this in Hexadecimal format... for example if sock.send("") sending string. in need to send socket.send(hexadecimal)???
struct,pack()is the way to go. Show what you have done for struct.pack. You probably want to split the DATA into a list and convert the values to ints.