-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuhf-test.py
executable file
·50 lines (43 loc) · 1.16 KB
/
uhf-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import socket
import time
host = '192.168.1.190'
port = 6000
#####Perintah######
# scan
INVENTORY1 = '06 FF 01 00 06' # membaca TID
INVENTORY2 = '04 FF 0F' #Membaca EPC
#crc
PRESET_Value = 0xFFFF
POLYNOMIAL = 0x8408
def crc(cmd):
cmd = bytes.fromhex(cmd)
uiCrcValue = PRESET_Value
for x in range((len(cmd))):
uiCrcValue = uiCrcValue ^ cmd[x]
for y in range(8):
if (uiCrcValue & 0x0001):
uiCrcValue = (uiCrcValue >> 1) ^ POLYNOMIAL
else:
uiCrcValue = uiCrcValue >> 1
crc_H = (uiCrcValue >> 8) & 0xFF
crc_L = uiCrcValue & 0xFF
cmd = cmd + bytes([crc_L])
cmd = cmd + bytes([crc_H])
return cmd
def send_cmd(cmd):
s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
s.connect((host, port))
message = crc(cmd)
s.sendall(message)
data = s.recv(64)
response_hex = data.hex().upper()
hex_list = [response_hex[i:i + 2] for i in range(0, len(response_hex), 2)]
hex_space = ' '.join(hex_list)
print(hex_space)
s.close()
while True:
send_cmd(INVENTORY1)
send_cmd(INVENTORY2)
time.sleep(1)