def main(): """main""" #create the object for getting CPU data data_collector = SystemDataCollector(5) #create the thread in charge of calling the data collector system_monitor = WorkerThread(data_collector.collect) #create the modbus TCP simulator and one slave #and one block of analog inputs simu = Simulator(TcpServer()) slave = simu.server.add_slave(1) slave.add_block("Cpu", defines.ANALOG_INPUTS, 0, 10) try: LOGGER.info("'quit' for closing the server") #start the data collect system_monitor.start() #start the simulator! will block until quit command is received simu.start() except Exception as excpt: print excpt finally: #close the simulator simu.close() #stop the data collect system_monitor.stop()
print block if id(block) == id(switch_block): print "setting switch block" print slice print values print "Leaving setblock_hook\n" return None if __name__ == "__main__": print "temp is %d" % queryTemperature() #create the object for getting CPU data data_collector = SystemDataCollector(5) #create the thread in charge of calling the data collector system_monitor = WorkerThread(data_collector.collect) #create the modbus TCP simulator and one slave #and one block of analog inputs simu = Simulator(TcpServer()) slave = simu.server.add_slave(1) slave.add_block("Temp", ANALOG_INPUTS, 0, 10) slave.add_block("switch", modbus_tk.defines.COILS, 100, 10) switch_block = slave._get_block("switch") print "switch block" print switch_block install_hook('modbus.ModbusBlock.setitem', setblock_hook) # modbus.Slave.handle_read_coils_request # modbus.Slave.handle_read_discrete_inputs_request
cpu = wmi.InstancesOf('Win32_Processor') for (_cpu, i) in zip(cpu, xrange(10)): value = _cpu.Properties_('LoadPercentage').Value cpu_usage = int(str(value)) if value else 0 #execute a RPC command for changing the value self._simu.set_values(1, "Cpu", i, (cpu_usage, )) except Exception, excpt: LOGGER.debug("SystemDataCollector error: %s", str(excpt)) time.sleep(0.1) if __name__ == "__main__": #create the object for getting CPU data data_collector = SystemDataCollector(5) #create the thread in charge of calling the data collector system_monitor = WorkerThread(data_collector.collect) #create the modbus TCP simulator and one slave #and one block of analog inputs simu = Simulator(TcpServer()) slave = simu.server.add_slave(1) slave.add_block("Cpu", ANALOG_INPUTS, 0, 10) try: LOGGER.info("'quit' for closing the server") #start the data collect system_monitor.start() #start the simulator! will block until quit command is received simu.start()