def config(self,
               socket_ip='192.168.2.99',
               socket_port=502,
               comport='COM5',
               baud=9600,
               device_id=0x01):
        if self.port_type == 'modbus_tcp':
            self.socket_ip = socket_ip
            self.socket_port = socket_port
            self.device_id = device_id
            self.port = modbus_umodbus.device_tcp()
            self.port.config(device_id=self.device_id,
                             socket_ip=self.socket_ip,
                             socket_port=self.socket_port,
                             signed_type=True)

        elif self.port_type == 'modbus_rtu':
            self.comport = comport
            self.baud = baud
            self.device_id = device_id
            self.port = modbus_umodbus.device_rtu()
Ejemplo n.º 2
0
#!/usr/bin/env python3
import modbus_umodbus
import time
import signal



# modbus TCP
slave_ip = '192.168.2.88'
slave_port = 8899

my_plc = modbus_umodbus.device_tcp()
my_plc.config(device_id=0x01, socket_ip=slave_ip, socket_port=slave_port, signed_type=True)

print(my_plc.device_id)
print(my_plc.tcp_socket)
print(my_plc.socket_ip)
print(my_plc.socket_port)

"""     
# modbus RTU
my_plc = modbus_umodbus.device_rtu()
my_plc.config(device_id=0x01, port='COM13', baudrate=9600, signed_type=False)

print(my_plc.device_id)
print(my_plc.serialport)
"""

_ADDRESS_OFFSET_COIL = 64512     # %Y of wecon PLC
_ADDRESS_OFFSET_DISCRETE_INPUT = 63488  # %X of wecon PLC
_ADDRESS_OFFSET_ANALOG_INPUT = 0
Ejemplo n.º 3
0
import modbus_umodbus
import time
import signal

slave_ip = '10.10.100.254'
slave_port = 8899

psa0350_dimmer = modbus_umodbus.device_tcp()
psa0350_dimmer.config(device_id=0x01,
                      socket_ip=slave_ip,
                      socket_port=slave_port,
                      signed_type=True)

print(psa0350_dimmer.device_id)
print(psa0350_dimmer.tcp_socket)
print(psa0350_dimmer.socket_ip)
print(psa0350_dimmer.socket_port)
"""
    This section is used to demo output percentage control of psa0350_dimmer using device_rtu.write_register()
    User need to enter the percentage from terminal
"""

print("Test write function...")
stopFlag = 0
while stopFlag == 0:
    userInput = input("Enter write value or 'q' for exit : ")

    if userInput != 'q':
        write_value = int(userInput)
        """
        if write_value > 99: