def main(): global plc, motor, nozzle, level, contact # Initialise simulator reactor.callInThread(runWorld) # Initialise motor, nozzle, level and contact components motor['server'] = Server(MOTOR_SERVER_IP, port=MOTOR_SERVER_PORT) reactor.listenTCP( MOTOR_SERVER_PORT, motor['server'], interface=MOTOR_SERVER_IP, ) nozzle['server'] = Server(NOZZLE_SERVER_IP, port=NOZZLE_SERVER_PORT) reactor.listenTCP( NOZZLE_SERVER_PORT, nozzle['server'], interface=NOZZLE_SERVER_IP, ) level['server'] = Server(LEVEL_SERVER_IP, port=LEVEL_SERVER_PORT) reactor.listenTCP( LEVEL_SERVER_PORT, level['server'], interface=LEVEL_SERVER_IP, ) contact['server'] = Server(CONTACT_SERVER_IP, port=CONTACT_SERVER_PORT) reactor.listenTCP(CONTACT_SERVER_PORT, contact['server'], interface=CONTACT_SERVER_IP) # Initialise plc component plc['server'] = Server(PLC_SERVER_IP, port=PLC_SERVER_PORT) reactor.listenTCP(PLC_SERVER_PORT, plc['server'], interface=PLC_SERVER_IP) plc['motor'] = Client(MOTOR_SERVER_IP, port=MOTOR_SERVER_PORT) plc['nozzle'] = Client(NOZZLE_SERVER_IP, port=NOZZLE_SERVER_PORT) plc['level'] = Client(LEVEL_SERVER_IP, port=LEVEL_SERVER_PORT) plc['contact'] = Client(CONTACT_SERVER_IP, port=CONTACT_SERVER_PORT) # Run World reactor.run()
from modbus import ConnectionException # - World environement from world import * ######################################### # Logging ######################################### logging.basicConfig() log = logging.getLogger() log.setLevel(logging.INFO) ##################################### # Move and fill code ##################################### client1 = Client(PLC_SERVER_IP, port=PLC_SERVER_PORT) client2 = Client(LEVEL_SERVER_IP, port=LEVEL_SERVER_PORT) client3 = Client(CONTACT_SERVER_IP, port=CONTACT_SERVER_PORT) client4 = Client(NOZZLE_SERVER_IP, port=NOZZLE_SERVER_PORT) try: client1.connect() client2.connect() client3.connect() client4.connect() while True: rq = client1.write(PLC_TAG_RUN, 1) # Run Plant, Run! rq = client2.write(LEVEL_TAG_SENSOR, 0) # Level Sensor rq = client3.write(CONTACT_TAG_SENSOR, 0) # Contact Sensor rq = client4.write(NOZZLE_TAG_RUN, 1) # Contact Sensor except KeyboardInterrupt:
# - Attack communication from modbus import ClientModbus as Client from modbus import ConnectionException # - World environement from world import * ######################################### # Logging ######################################### logging.basicConfig() log = logging.getLogger() log.setLevel(logging.INFO) ##################################### # Never stop code ##################################### client = Client(PLC_SERVER_IP, port=PLC_SERVER_PORT) try: client.connect() while True: rq = client.write(PLC_TAG_RUN, 1) # Run Plant, Run! rq = client.write(PLC_TAG_CONTACT, 0) # Contact Sensor rq = client.write(PLC_TAG_LEVEL, 1) # Level Sensor except KeyboardInterrupt: client.close() except ConnectionException: print "Unable to connect / Connection lost"
def __init__(self, address, port): Gtk.Window.__init__(self, title="Bottle-filling factory - HMI - VirtuaPlant") self.set_border_width(HMI_SCREEN_WIDTH) self.client = Client(address, port=port) elementIndex = 0 # Grid grid = Gtk.Grid() grid.set_row_spacing(15) grid.set_column_spacing(10) self.add(grid) # Main title label label = Gtk.Label() label.set_markup( "<span weight='bold' size='x-large'>Bottle-filling process status</span>" ) grid.attach(label, 0, elementIndex, 2, 1) elementIndex += 1 # Bottle in position label bottlePositionLabel = Gtk.Label("Bottle in position") bottlePositionValue = Gtk.Label() grid.attach(bottlePositionLabel, 0, elementIndex, 1, 1) grid.attach(bottlePositionValue, 1, elementIndex, 1, 1) elementIndex += 1 # Nozzle status label nozzleStatusLabel = Gtk.Label("Nozzle Status") nozzleStatusValue = Gtk.Label() grid.attach(nozzleStatusLabel, 0, elementIndex, 1, 1) grid.attach(nozzleStatusValue, 1, elementIndex, 1, 1) elementIndex += 1 # Motor status label motorStatusLabel = Gtk.Label("Motor Status") motorStatusValue = Gtk.Label() grid.attach(motorStatusLabel, 0, elementIndex, 1, 1) grid.attach(motorStatusValue, 1, elementIndex, 1, 1) elementIndex += 1 # Level hit label levelHitLabel = Gtk.Label("Level Hit") levelHitValue = Gtk.Label() grid.attach(levelHitLabel, 0, elementIndex, 1, 1) grid.attach(levelHitValue, 1, elementIndex, 1, 1) elementIndex += 1 # Process status processStatusLabel = Gtk.Label("Process Status") processStatusValue = Gtk.Label() grid.attach(processStatusLabel, 0, elementIndex, 1, 1) grid.attach(processStatusValue, 1, elementIndex, 1, 1) elementIndex += 1 # Connection status connectionStatusLabel = Gtk.Label("Connection Status") connectionStatusValue = Gtk.Label() grid.attach(connectionStatusLabel, 0, elementIndex, 1, 1) grid.attach(connectionStatusValue, 1, elementIndex, 1, 1) elementIndex += 1 # Run and Stop buttons runButton = Gtk.Button("Run") stopButton = Gtk.Button("Stop") runButton.connect("clicked", self.setProcess, 1) stopButton.connect("clicked", self.setProcess, 0) grid.attach(runButton, 0, elementIndex, 1, 1) grid.attach(stopButton, 1, elementIndex, 1, 1) elementIndex += 1 # VirtuaPlant branding virtuaPlant = Gtk.Label() virtuaPlant.set_markup("<span size='small'>VirtuaPlant - HMI</span>") grid.attach(virtuaPlant, 0, elementIndex, 2, 1) # Attach Value Labels self.processStatusValue = processStatusValue self.connectionStatusValue = connectionStatusValue self.levelHitValue = levelHitValue self.motorStatusValue = motorStatusValue self.bottlePositionValue = bottlePositionValue self.nozzleStatusValue = nozzleStatusValue self.resetLabels() GObject.timeout_add_seconds(HMI_SLEEP, self.update_status)