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.