input_line = 0 def read_callback(*msg): if msg[1] is True and msg[0] == input_line: # if signal is high and address is 0 defective = random.randint(0,4) if defective == 0: print "Part defective" mws.triggerInput(1,3.0)# args: address , time to raise level - default 0.5 else: print "Part OK" mws.triggerInput(0,3.0)# args: address , time to raise level - default 0.5 mws = ModbusWrapperServer(port) mws.startServer() # handler to exit on ctrl+c def signal_handler(signal, frame): print('You pressed Ctrl+C!') mws.stopServer() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) print('Press Ctrl+C') mws.stateChangeListener(input_line) # listens to line 0 of baxter mws.state_changed.connect(read_callback) # links a callback signal.pause()
# THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of the FreeBSD Project. from time import sleep from modbus_wrapper_server import ModbusWrapperServer if __name__ == "__main__": port = 502 # default modbus port # Init modbus server with specific port mws = ModbusWrapperServer(port) # Starts the server in a non blocking call mws.startServer() print "Server started" print "setting line 0 to True" mws.setDigitalInput(0, 1) # args: address , value. sets address to value print "waiting for line 0 to be set to True" result = mws.waitForCoilOutput( 0, 10 ) # args: address,timeout in sec. timeout of 0 is infinite. waits until address is true if result: print "got line 0 is True from baxter" else: print "timeout waiting for signal on line 0"