0

I'm trying to connect with biometric machine using socket TCP/IP. I send command CMD_DEVICE_TIME_GET for current datetime.

import socket
from struct import pack, unpack

CMD_DEVICE_TIME_GET = 0x10E

HOST = '192.168.000.100'
PORT = 5005

head1 = 0x55
head2 = 0xAA
MachineID = 1
Reserved  = 0x1979;
Command = CMD_DEVICE_TIME_GET
Length = 16
PARAM = 65534
chksum = 0

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.settimeout(10)
buf = pack('BBHHHIHH', head1, head2, MachineID, Reserved, Command, Length, PARAM, chksum)

def createChkSum(buf):
    csum = 0;
    for i in range(0, 16):
        csum += buf[i];
    return csum;

buf = pack('BBHHHIHH', head1, head2, MachineID, Reserved, Command, Length, PARAM, createChkSum(buf))

try:
    s.connect((HOST, PORT))
    s.send(buf)
except ConnectionError as e:
    print(">>>>>>>>>>>>>>Error>>>>>>>>>>>",e)

print("=====Waiting Response...........")
try:
    s.send(buf)
    while True:
        data = s.recv(1024)
        if data:
except Exception as E:
    print(">>>>>>>>>>>>>>>Exception>>>>>>",E)

Device response(variable data): \xa5Z\x01\x00r-\x1d%\x90\xcdWA\x01\x00\x00\x00\xd0\xcdWA\x0c\x06\xaaU\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x01

  • Please review stack overflow's formatting guidelines: https://stackoverflow.com/help/formatting. I updated your question to move your code inside a code block. Also, include enough code to be clear. Without including the input statement "from struct import unpack", it's not immediately obvious what you're trying to do. – RNHTTR Sep 27 '19 at 20:44
  • I don't know binary, but answers to the question linked below might be able to help you. It's python-2, but it should be close enough https://stackoverflow.com/questions/18516582/write-and-read-datetime-to-binary-format-in-python – RNHTTR Sep 27 '19 at 21:09
  • @RNHTTR I tried using struct doc but unable to unpack whole string. string \xcdWA not support any type – user12130638 Sep 28 '19 at 12:32

0 Answers0