--- /dev/null
+import os, termios
+from time import sleep
+import logging
+
+class SerialClientException(Exception): pass
+
+class SerialClient:
+ BaudRates = {
+ 110: termios.B110,
+ 300: termios.B300,
+ 600: termios.B600,
+ 1200: termios.B1200,
+ 2400: termios.B2400,
+ 4800: termios.B4800,
+ 9600: termios.B9600,
+ 19200: termios.B19200,
+ 38400: termios.B38400,
+ 57600: termios.B57600,
+ 115200: termios.B115200,
+ }
+
+ def __init__(self, port = '/dev/ttyS0', baud = 9600):
+ self.port = port
+ self.baud = baud
+ try:
+ self.handle = os.open(port, os.O_RDWR)
+ except:
+ raise SerialClientException('Unable to open port')
+ self.oldmode = termios.tcgetattr(self.handle)
+ cc = [0]*len(self.oldmode[6])
+ cc[termios.VMIN] = 1
+ cc[termios.VTIME] = 0
+ termios.tcsetattr(self.handle, termios.TCSANOW,
+ [
+ termios.IGNPAR, # c_iflag
+ 0, # c_oflag
+ termios.CS8|termios.CLOCAL|termios.CREAD, # c_cflag
+ 0, # c_lflag
+ self.BaudRates[self.baud], # c_ispeed
+ self.BaudRates[self.baud], # c_ospeed
+ cc])
+ self.rfh = os.fdopen(self.handle, 'r')
+ self.wfh = os.fdopen(self.handle, 'w')
+ self.wfh.write('B\n')
+
+ def get_fh(self):
+ return (self.rfh, self.wfh)
+
+ def __del__(self):
+ pass
+
if USE_DB: import pg
from time import time, sleep
from popen2 import popen2
-from LATClient import LATClient, LATClientException
+#from LATClient import LATClient, LATClientException
+from SerialClient import SerialClient, SerialClientException
from VendingMachine import VendingMachine, VendingException
from MessageKeeper import MessageKeeper
from HorizScroll import HorizScroll
time_to_autologout = time() + 8
def connect_to_vend(options, cf):
- # Open vending machine via LAT?
+ # Open vending machine via serial.
+ logging.info('Connecting to vending machine using serial')
+ serialclient = SerialClient(port = '/dev/ttyS1', baud = 9600)
+ return serialclient.get_fh()
+
if options.use_lat:
logging.info('Connecting to vending machine using LAT')
latclient = LATClient(service = cf.ServiceName, password = cf.ServicePassword, server_name = cf.ServerName, connect_password = cf.ConnectPassword, priv_password = cf.PrivPassword)
while True:
try:
rfh, wfh = connect_to_vend(options, config_opts)
- except (LATClientException, socket.error), e:
+ except (SerialClientException, socket.error), e:
(exc_type, exc_value, exc_traceback) = sys.exc_info()
del exc_traceback
logging.error("Connection error: "+str(exc_type)+" "+str(e))