Example #1
0
 def __init__(self):
     """Constructor"""
     
     Simulator.__init__(self, modbus_tcp.TcpServer())
     
     # create a slave and block
     slave = self.server.add_slave(1)
     slave.add_block("foo", HOLDING_REGISTERS, 0, 100)
Example #2
0
    def __init__(self, *args, **kwargs):
        """Constructor"""
        Simulator.__init__(self, *args, **kwargs)
        # add a new command: cv will make possible to change a value
        self.add_command("cv", self.change_value)

        # create a slave and block
        slave = self.server.add_slave(1)
        slave.add_block("foo", HOLDING_REGISTERS, 0, 100)
Example #3
0
    def __init__(self):
        """Constructor"""
        Simulator.__init__(self)
        # add a new command: cv will make possible to change a value
        self.add_command("cv", self.change_value)

        # create a slave and block
        slave = self.server.add_slave(1)
        slave.add_block("foo", HOLDING_REGISTERS, 0, 100)
Example #4
0
    def __init__(self, mode, port, baud=None, hostname=None, verbose=None):
        self.rtu = None
        self.mode = mode
        if self.mode == 'rtu' and baud and port:
            self.rtu = serial.Serial(port=port, baudrate=baud)
            Simulator.__init__(self, ModbusRtuServer(self.rtu))
            # timeout is too fast for 19200 so increase a little bit
            self.server._serial.timeout *= 2
            self.server._serial.interCharTimeout *= 2
            LOGGER.info('Initializing modbus %s simulator: baud = %d port = %s parity = %s' % (self.mode, baud, port, self.rtu.parity))
            LOGGER.info('stop bits = %d xonxoff = %d' % (self.rtu.stopbits, self.rtu.xonxoff))
        elif self.mode == 'tcp' and hostname and port:
            Simulator.__init__(self, TcpServer(address=hostname, port=port))
            LOGGER.info('Initializing modbus %s simulator: addr = %s port = %s' % (self.mode, hostname, port))
        else:
            raise ModbusSimError('Unknown mode: %s' % (mode))

        self.server.set_verbose(True)