Esempio n. 1
0
    def test_udp_server_initialize(self):
        protocol = ModbusUdpProtocol(store=None)
        self.assertEqual(protocol.control.Identity.VendorName, '')

        identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
        protocol = ModbusUdpProtocol(store=None, identity=identity)
        self.assertEqual(protocol.control.Identity.VendorName, 'VendorName')
Esempio n. 2
0
    def test_modbus_server_factory(self):
        """ Test the base class for all the clients """
        factory = ModbusServerFactory(store=None)
        self.assertEqual(factory.control.Identity.VendorName, '')

        identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
        factory = ModbusServerFactory(store=None, identity=identity)
        self.assertEqual(factory.control.Identity.VendorName, 'VendorName')
Esempio n. 3
0
 def test_udp_server_close(self):
     """ test that the synchronous UDP server closes correctly """
     with patch.object(socket.socket, 'bind') as mock_socket:
         identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
         server = ModbusUdpServer(context=None, identity=identity)
         server.threads.append(Mock(**{'running': True}))
         server.server_close()
         self.assertEqual(server.control.Identity.VendorName, 'VendorName')
         self.assertFalse(server.threads[0].running)
Esempio n. 4
0
    def test_serial_server_connect(self):
        with patch.object(serial, 'Serial') as mock_serial:
            mock_serial.return_value = "socket"
            identity = ModbusDeviceIdentification(info={0x00: 'VendorName'})
            server = ModbusSerialServer(context=None, identity=identity)
            self.assertEqual(server.socket, "socket")
            self.assertEqual(server.control.Identity.VendorName, 'VendorName')

            server._connect()
            self.assertEqual(server.socket, "socket")

        with patch.object(serial, 'Serial') as mock_serial:
            mock_serial.side_effect = serial.SerialException()
            server = ModbusSerialServer(None)
            self.assertEqual(server.socket, None)
Esempio n. 5
0
    def __init__(self, datablock, identity):
        threading.Thread.__init__(self)
        self.do_stop = threading.Event()

        self.ip = None
        self.port = None
        self.id = None

        self.srv = None
        self.context = None
        self.datablock = datablock

        self.framer = ModbusSocketFramer
        self.context = ModbusServerContext(slaves=self.datablock.store,
                                           single=True)

        self.identity = ModbusDeviceIdentification()
        self.identity.VendorName = identity["vendorname"]
        self.identity.ProductCode = identity["productcode"]
        self.identity.VendorUrl = identity["vendorurl"]
        self.identity.ProductName = identity["productname"]
        self.identity.ModelName = identity["modelname"]
        self.identity.MajorMinorRevision = '0.3'
Esempio n. 6
0
# will map to (1-8)::
#
# store = ModbusSlaveContext(..., zero_mode=True)
#---------------------------------------------------------------------------#
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [17]*100),
co = ModbusSequentialDataBlock(0, [17]*100),
hr = ModbusSequentialDataBlock(0, [17]*100),
ir = ModbusSequentialDataBlock(0, [17]*100))
context = ModbusServerContext(slaves=store, single=True)
#---------------------------------------------------------------------------#
# initialize the server information
#---------------------------------------------------------------------------#
# If you don't set this or any fields, they are defaulted to empty strings.
#---------------------------------------------------------------------------#
identity = ModbusDeviceIdentification()
# identity.VendorName = {'0': 'Pymodbus'}

# identity.VendorName = 'Pymodbus'
# identity.ProductCode = 'PM'
# identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
# identity.ProductName = 'Pymodbus Server'
# identity.ModelName = 'Pymodbus Server'
# identity.MajorMinorRevision = '1.0'
#---------------------------------------------------------------------------#
# run the server you want
#---------------------------------------------------------------------------#
StartTcpServer(context, identity=None, address=("localhost", 502))
#StartUdpServer(context, identity=identity, address=("localhost", 502))
#StartSerialServer(context, identity=identity, port='/dev/pts/3', framer=ModbusRtuFramer)
#StartSerialServer(context, identity=identity, port='/dev/pts/3', framer=ModbusAsciiFramer)
Esempio n. 7
0
 def setUp(self):
     """
     Initializes the test environment
     """
     values = dict((i, '') for i in range(10))
     identity = ModbusDeviceIdentification(info=values)
Esempio n. 8
0
#
# The slave context can also be initialized in zero_mode which means that a
# request to address(0-7) will map to the address (0-7). The default is
# False which is based on section 4.4 of the specification, so address(0-7)
# will map to (1-8)::
#
# store = ModbusSlaveContext(..., zero_mode=True)
#---------------------------------------------------------------------------#
store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [17] * 100),
                           co=ModbusSequentialDataBlock(0, [17] * 100),
                           hr=ModbusSequentialDataBlock(0, [17] * 100),
                           ir=ModbusSequentialDataBlock(0, [17] * 100))
context = ModbusServerContext(slaves=store, single=True)
#---------------------------------------------------------------------------#
# initialize the server information
#---------------------------------------------------------------------------#
# If you don't set this or any fields, they are defaulted to empty strings.
#---------------------------------------------------------------------------#
identity = ModbusDeviceIdentification()
identity.VendorName = 'Pymodbus'
identity.ProductCode = 'PM'
identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
identity.ProductName = 'Pymodbus Server'
identity.ModelName = 'Pymodbus Server'
identity.MajorMinorRevision = '1.0'
#---------------------------------------------------------------------------#
# run the server you want
#---------------------------------------------------------------------------#
# Tcp:
StartTcpServer(context, identity=None, address=("localhost", 5020))