コード例 #1
0
    def setUp(self):
        HOST, PORT = "localhost", 9999

        # Creating Transductor Model and Energy Transductor
        t_model = TransductorModel()
        t_model.name = "TR 4020"
        t_model.transport_protocol = "UDP"
        t_model.serial_protocol = "Modbus RTU"
        t_model.register_addresses = [[4, 0], [68, 1]]
        t_model.save()

        transductor = EnergyTransductor()
        transductor.serie_number = "1"
        transductor.description = "Test"
        transductor.model = t_model
        transductor.ip_address = HOST
        transductor.save()

        # Setting instance attributes
        self.t_model = t_model
        self.transductor = transductor
        self.modbus_rtu = ModbusRTU(self.transductor)
        self.udp_protocol = UdpProtocol(serial_protocol=self.modbus_rtu,
                                        timeout=0.5,
                                        port=9999)

        # Starting UDP server via thread
        self.server = SocketServer.UDPServer((HOST, PORT), UDPHandler)
        self.server_thread = threading.Thread(target=self.server.serve_forever)
        self.server_thread.start()
コード例 #2
0
    def test_change_transductor_model(self):
        t_model_1 = self.t_model

        transductor = self.create_energy_transductor(1, "Test",
                                                     "111.111.111.111",
                                                     t_model_1)

        t_model_2 = TransductorModel()
        t_model_2.name = "Transductor Model 2"
        t_model_2.transport_protocol = "TCP/IP"
        t_model_2.serial_protocol = "Mosbus"
        t_model_2.register_addresses = [[100, 0], [105, 1]]
        t_model_2.save()

        url = reverse('transductor:edit',
                      kwargs={'transductor_id': transductor.id})

        params = {
            'serie_number': 2,
            'ip_address': '222.222.222.222',
            'description': 'Another Test',
            'model': t_model_2.id
        }

        self.client.post(url, params)

        transductor = EnergyTransductor.objects.get(
            ip_address='222.222.222.222')

        self.assertEqual(2, transductor.serie_number)
        self.assertEqual("Another Test", transductor.description)
        self.assertEqual(t_model_2, transductor.model)
コード例 #3
0
 def setUp(self):
     t_model = TransductorModel()
     t_model.name = "TR 4020"
     t_model.internet_protocol = "UDP"
     t_model.serial_protocol = "Modbus RTU"
     t_model.register_addresses = [68, 70, 72, 74, 76, 78, 80, 82, 84, 88, 90, 92]
     t_model.save()
コード例 #4
0
    def setUp(self):
        t_model = TransductorModel()
        t_model.name = "TR 4020"
        t_model.transport_protocol = "UDP"
        t_model.serial_protocol = "Mosbus RTU"
        t_model.measurements_type = "EnergyMeasurements"
        t_model.register_addresses = [[68, 0], [70, 1]]
        t_model.save()

        self.t_model = t_model
コード例 #5
0
    def setUp(self):
        t_model = TransductorModel()
        t_model.name = "TR 4020"
        t_model.internet_protocol = "UDP"
        t_model.serial_protocol = "Modbus RTU"
        t_model.register_addresses = [68, 70, 72, 74, 76, 78,
                                      80, 82, 84, 88, 90, 92]
        t_model.save()

        transductor = EnergyTransductor()
        transductor.serie_number = "1"
        transductor.description = "Test"
        transductor.creation_date = timezone.now()
        transductor.model = t_model
        transductor.ip_address = "111.111.111.111"
        transductor.save()
コード例 #6
0
    def setUp(self):
        t_model = TransductorModel()
        t_model.name = "TR 4020"
        t_model.transport_protocol = "UDP"
        t_model.serial_protocol = "Modbus RTU"
        t_model.register_addresses = [[68, 0], [70, 1]]
        t_model.save()

        self.t_model = t_model

        transductor = EnergyTransductor()
        transductor.serie_number = "1"
        transductor.description = "Test"
        transductor.model = t_model
        transductor.ip_address = "111.111.111.111"
        transductor.save()

        self.transductor = transductor

        self.create_energy_measurements()
コード例 #7
0
    def setUp(self):
        t_model = TransductorModel()
        t_model.name = "TR 4020"
        t_model.transport_protocol = "UdpProtocol"
        t_model.serial_protocol = "ModbusRTU"
        t_model.register_addresses = [[4, 0], [68, 1]]
        t_model.measurements_type = "EnergyMeasurements"
        t_model.save()

        self.t_model = t_model

        transductor = EnergyTransductor()
        transductor.serie_number = "1"
        transductor.description = "Test"
        transductor.model = t_model
        transductor.ip_address = "111.111.111.111"
        transductor.broken = False
        transductor.save()

        self.transductor = transductor

        self.modbus_rtu = ModbusRTU(self.transductor)
コード例 #8
0
    def test_raise_exception_on_create_messages_with_wrong_address(self):
        wrong_address = [[4, 2]]

        t_model = TransductorModel()
        t_model.name = "Test Model"
        t_model.transport_protocol = "UDP"
        t_model.serial_protocol = "Modbus RTU"
        t_model.register_addresses = wrong_address
        t_model.save()

        transductor = EnergyTransductor()
        transductor.serie_number = "2"
        transductor.description = "Test 2"
        transductor.creation_date = timezone.now()
        transductor.model = t_model
        transductor.ip_address = "222.222.222.222"
        transductor.save()

        modbus = ModbusRTU(transductor)

        with self.assertRaises(RegisterAddressException):
            modbus.create_messages()