Commit 039b14f5 authored by axel.maurer's avatar axel.maurer
Browse files

find device for windows and raspi

parent b6182958
......@@ -21,8 +21,8 @@ UNKNOWN_READER_ERROR = 800
OK = 0
SER_PORT_NAME = 'Elatec'
SER_PORT_PRODUCT = 'TWN4'
SER_PORT_MANUFACTURER = 'Elatec'
class SerialConnection:
......@@ -62,10 +62,11 @@ class SerialConnection:
def read(self):
try:
readResult=self.ser.read()
readResult = self.ser.read()
time.sleep(0.2)
if self.ser.in_waiting > 0:
self.resultStr = readResult + self.ser.read(self.ser.in_waiting)
self.resultStr = readResult + \
self.ser.read(self.ser.in_waiting)
self.returnMsg = self.resultStr
self.returnCode = OK
self.ser.flushInput()
......@@ -94,7 +95,11 @@ class CardReader:
if comports:
comportsList = list(comports())
for port in comportsList:
if port.manufacturer.startswith(SER_PORT_NAME):
# if port.product
if port.product is not None and port.product.startswith(SER_PORT_PRODUCT):
self.serPort = port[0]
break
if port.manufacturer is not None and port.manufacturer.startswith(SER_PORT_MANUFACTURER):
self.serPort = port[0]
break
if not self.serPort:
......@@ -122,7 +127,8 @@ class CardReader:
self.serCon.write(b"".join([opCode.encode(), ','.encode(), format(
opParmLen, '02X').encode(), opParmStr.encode()]), 0.0)
else:
self.serCon.write(b"".join([opCode.encode(), ','.encode(), opParmStr.encode()]), 0.0)
self.serCon.write(
b"".join([opCode.encode(), ','.encode(), opParmStr.encode()]), 0.0)
else:
self.serCon.write(opCode.encode(), 0.0)
self.returnCode = OK
......@@ -131,7 +137,7 @@ class CardReader:
self.returnMsg = ''
return(self.returnCode)
def read(self,timeout=None):
def read(self, timeout=None):
self.serCon.ser.timeout = timeout
if self.serCon.read() == OK:
resultBytes = self.serCon.getReturnMsg()
......@@ -168,7 +174,7 @@ class CardReader:
if retCode != OK:
logging.debug(f'Error on DoOp read: {retCode}')
return retCode
def cancelOp(self):
self.serCon.ser.write(b'x'+b'\r')
sleep(0.1)
......@@ -177,7 +183,6 @@ class CardReader:
self.serCon.ser.reset_input_buffer()
self.serCon.ser.reset_output_buffer()
def clear(self):
if self.serCon.ser.in_waiting > 0:
self.read()
......@@ -186,8 +191,6 @@ class CardReader:
self.serCon.ser.close()
if __name__ == "__main__":
logging.basicConfig(
format='%(asctime)s - %(message)s', level=logging.DEBUG)
......@@ -197,5 +200,5 @@ if __name__ == "__main__":
sys.exit()
# actSeconds = str(int(time.time()))
cardReader.doOp(f'01')
print(cardReader.getReturnCode(),cardReader.getReturnMsg())
cardReader.clear()
\ No newline at end of file
print(cardReader.getReturnCode(), cardReader.getReturnMsg())
cardReader.clear()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment