Modbus error

0

I'm getting the following error when attempting to send a request to a modbus port.

2021-02-07T20:21:16.051Z [INFO] (pool-2-thread-40) aws.greengrass.Modbus: protocol_adapter.py:365,Client connecting.... {serviceInstance=0, serviceName=aws.greengrass.Modbus, currentState=RUNNING}
2021-02-07T20:21:16.053Z [ERROR] (pool-2-thread-27) aws.greengrass.Modbus: sync.py:341,Could not configure port: (22, 'Invalid argument'). {serviceInstance=0, serviceName=aws.greengrass.Modbus, currentState=RUNNING}
2021-02-07T20:21:16.067Z [ERROR] (pool-2-thread-27) aws.greengrass.Modbus: sync.py:341,Could not configure port: (22, 'Invalid argument'). {serviceInstance=0, serviceName=aws.greengrass.Modbus, currentState=RUNNING}
2021-02-07T20:21:16.067Z [INFO] (pool-2-thread-40) aws.greengrass.Modbus: protocol_adapter.py:369,Connected. {serviceInstance=0, serviceName=aws.greengrass.Modbus, currentState=RUNNING}

Here is my config for the modbus component:
"aws.greengrass.Modbus": {
"version": "2.0.3",
"configurationUpdate": {
"merge": {
"lambdaExecutionParameters": {
"EnvironmentVariables": {
"ModbusLocalPort": "/dev/usb/hiddev0"
}
},
"containerMode": "NoContainer"
}
}
},

Initially, I got a permissions error, but then I did ran chmod 777 on /dev/usb/hiddev0. This fixed the permissions error, but then it gave the "Could not configure port" error.

Below is my publishing component:
com.example.pubModbus.py:

ipc_utils = myUtils.IPCUtils()
connection = ipc_utils.connect()
ipc_client = client.GreengrassCoreIPCClient(connection)
topic = "modbus/adapter/request"
messageInput = '{"request": {"operation": "ReadCoilsRequest","device": 1,"address": 1,"count": 1 },"id": "MyRequest"}'
request = PublishToTopicRequest()
request.topic = topic
publish_message = PublishMessage()
publish_message.binary_message = BinaryMessage()
publish_message.binary_message.message = bytes(messageInput, "utf-8")
request.publish_message = publish_message
operation = ipc_client.new_publish_to_topic()
operation.activate(request)
future = operation.get_response()
future.result(TIMEOUT)

In the above publisher, I tried to use a JsonMessage() instead of BinaryMessage(), but that caused a runtime error in the publisher component.

Also, the usb device is in the /dev/bus/usb/001/00x location. Here is a information on the device:
udevadm info /dev/bus/usb/002/007
P: /devices/pci0000:00/0000:00:06.0/usb2/2-2
N: bus/usb/002/007
E: BUSNUM=002
E: DEVNAME=/dev/bus/usb/002/007
E: DEVNUM=007
E: DEVPATH=/devices/pci0000:00/0000:00:06.0/usb2/2-2
E: DEVTYPE=usb_device
E: DRIVER=usb
E: ID_BUS=usb
E: ID_MM_DEVICE_IGNORE=1
E: ID_MODEL=5161
E: ID_MODEL_ENC=5161
E: ID_MODEL_FROM_DATABASE=USB to Serial
E: ID_MODEL_ID=5161
E: ID_REVISION=0003
E: ID_SERIAL=0665_5161
E: ID_USB_INTERFACES=:030000:
E: ID_VENDOR=0665
E: ID_VENDOR_ENC=0665
E: ID_VENDOR_FROM_DATABASE=Cypress Semiconductor
E: ID_VENDOR_ID=0665
E: MAJOR=189
E: MINOR=134
E: PRODUCT=665/5161/3
E: SUBSYSTEM=usb
E: TYPE=0/0/0
E: USEC_INITIALIZED=9372104378

I have also tried to create a usb serial adapter by running:
sudo modprobe usbserial vendor=0x0665 product=0x5161
This had no effect and did not report any results in dmesg.

Any help would be appreciated. Thanks.

DarrenB
gefragt vor 3 Jahren259 Aufrufe
4 Antworten
0

I kind of recall that the suggest default port number of Modbus-TCP was 502. Port 22 is usually used for SSH. So the port 22 might be already occupied or reserved for SSH service or deamon. Changing the port from 22 to other unused port number might fix the error.

Try the below to see if you have ssh deamon, sshd, occupying port number 22.
netstat -antp|grep ssh

Edited by: jx2900 on Feb 7, 2021 3:24 PM

jx2900
beantwortet vor 3 Jahren
0

Thanks. My ubuntu VM is not running ssh on 22.

DarrenB
beantwortet vor 3 Jahren
0

I have traced the error to a call in the modbus lambda component:

    try:  
        orig_attr = termios.tcgetattr(self.fd)  
        iflag, oflag, cflag, lflag, ispeed, ospeed, cc = orig_attr  
    except termios.error as msg:      # if a port is nonexistent but has a /dev file, it'll fail here  
        raise SerialException("Could not configure port: {}".format(msg))  

According to the docs on the tcgetattr(), it requires a tty device input. I believe that my issue is that a serial bus adapter is not getting created for my attached usb device.
https://www.programcreek.com/python/example/836/termios.tcsetattr
https://docs.python.org/3/library/termios.html

DarrenB
beantwortet vor 3 Jahren
0

The problem is that my device's usb connection is not modbus or serial. I will have to take a different approach with connectivity.

DarrenB
beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen