dmesg | grep tty Yours is the last tty present This code block tries to find the right one. ''' try: hornby.connection_open('/dev/ttyACM0',115200) #<<<<<< must be changed to the right device + baud rate changed for the elink except RuntimeError as e: try: hornby.connection_open('/dev/ttyACM1',115200) #<<<<<< must be changed to the right device + baud rate changed for the elink except RuntimeError as e: hornby.connection_open('/dev/ttyACM2',115200) #<<<<<< must be changed to the right device + baud rate changed for the elink # set_debug(True) to show the data transmitted and received from the controller # Try not to worry if it goes wierd hornby.set_debug(False) # Check hardware and perform initialisation hornby.setup() # create a train object to represent each train to be controlled # parameter 1 = DCC addres # The somerset Belle (small black 6-wheeler steam train) has an ID of 3 t1 = hornby.Train(3) # Are we root? If we are not root, GPIO won't work. To stop it bombing, I # have been using "if isroot" before GPIO calls. isroot = (os.geteuid() == 0); #------------------------------- Sensor setup below -------------------------------------#
hornby.connection_open( '/dev/ttyACM0', 115200 ) #<<<<<< must be changed to the right device + baud rate changed for the elink except RuntimeError as e: try: hornby.connection_open( '/dev/ttyACM1', 115200 ) #<<<<<< must be changed to the right device + baud rate changed for the elink except RuntimeError as e: hornby.connection_open( '/dev/ttyACM2', 115200 ) #<<<<<< must be changed to the right device + baud rate changed for the elink # set_debug(True) to show the data transmitted and received from the controller # Try not to worry if it goes wierd hornby.set_debug(False) # Check hardware and perform initialisation hornby.setup() # create a train object to represent each train to be controlled # parameter 1 = DCC addres # The somerset Belle (small black 6-wheeler steam train) has an ID of 3 t1 = hornby.Train(3) # Are we root? If we are not root, GPIO won't work. To stop it bombing, I # have been using "if isroot" before GPIO calls. isroot = (os.geteuid() == 0) #------------------------------- Sensor setup below -------------------------------------# '''setting the mode of the board
hornby.py to control the model train using a Hornby Elite DCC controller ''' import web import hornby render = web.template.render('templates/') urls = ('/.*', 'control_panel') print ''' Simple Model Railway Control Server ----------------------------------- ''' app = web.application(urls, globals(), autoreload=False) hornby.set_debug(True) hornby.connection_open('/dev/ttyACM0', 9600) t1 = hornby.Train(3) a1 = hornby.Accessory(0, 2) class control_panel: def GET(self): return render.control_panel1('003 Class 108 DMU') def POST(self): data = web.input() if data.id == 'forward': t1.throttle(int(data.value), hornby.FORWARD) elif data.id == 'reverse': t1.throttle(int(data.value), hornby.REVERSE)