According to their copyright I can post this here. Ziath made this Python code to interface with their scanner. Probably useful for someone else who needs to open a socket and wait for a message. I implemented the code and had the system working in 5 minutes.
import socket
import time
"""This class demonstrates calling DataPaq to trigger a scan and
retrieve the data from the server. To run this code start DataPaq in server
mode and generate a plate group with the class id of 1, then close DataPaq
and run the server by executing server -s in the DataPaq program files (x86)
directory to run the server. Note that you can automate this by starting the
process from Python.
This code may be freely distributed and modified, no warranty is given on
this code.
Author : Neil Benn
Copyright : Ziath 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
"""
class DataPaqRemote:
def __init__(self):
"basic constructor"
self.__readBuffer = ""
self.__s = None
self.__fs = None
self.__connected = False
def initialise(self):
"""Create a socket and connects it to DataPaq. Ensure the firewall
allows port 888 to connect to the localhost"""
if self.__connected:
raise Exception("Scanner already connected")
self.__s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__s.connect(("localhost", 8888))
self.__fs = self.__s.makefile()
self.__fs.readline()
self.__connected = True
def disconnect(self):
"""Closes the socket and sets socket objects to None"""
if not self.__connected:
raise Exception("Scanner not connected")
self.__fs.close()
self.__s.close()
self.__fs = None
self.__s = None
self.__connected = False
def getVersion(self):
"""Returns the version of the DataPaq Server"""
if not self.__connected:
raise Exception("Scanner not connected")
self.__s.sendall("VERSION\r\n")
version = self.__fs.readline()
self.__fs.readline()
return version.strip()
def getStatus(self):
"""Returns the status of the DataPaq Server"""
if not self.__connected:
raise Exception("Scanner not connected")
self.__s.sendall('STATUS\r\n')
status = self.__fs.readline()
self.__fs.readline()
return status.strip()
def scanRack(self, uid):
"""Triggers a scan and returns the scan data"""
if not self.__connected:
raise Exception("Scanner not connected")
self.__s.sendall('SCAN ' + uid + ' XML\r\n')
scanFirstLine = True
read_string = ''
while True:
line = self.__fs.readline()
if scanFirstLine:
if line.startswith('ERR'):
raise Exception('Scanner reported error ' +
adm line + self.__readLine())
scanFirstLine = False
else:
if line.startswith('OK'):
break
if line.strip() != "":
read_string += line
return read_string
if __name__ == '__main__':
"""Executes a series of queries and returns the data from the DataPaq
Server"""
print 'starting'
dpr = DataPaqRemote()
dpr.initialise()
print 'Version = ' + dpr.getVersion()
print 'Status = ' + dpr.getStatus()
print 'Calling scan'
scan_data = dpr.scanRack('1')
print 'called scan'
for line in scan_data.split('\r\n'):
print line.strip()
dpr.disconnect()
print 'disconnected'