MODBUS and System air

I am thinking about using this ethernet to modbus controller:
https://www.aliexpress.com/item/Serial-server-Modbus-TCP-to-RTU-RS232-RS485-dual-serial-transfer-network/32740113824.html?spm=2114.10010108.1000013.1.JumUXE&scm=1007.13339.81019.0&pvid=4fcf1d55-6a53-4b4c-b3e4-e2953cf8b6a7&tpp=1

Or should I better stick to usb version?

I use a similar “USR” branded product with success. That has a mode that properly supports Modbus, so that your host talks to it with Modbus-TCP and it talks Modbus-RTU on the serial side.

I know nothing about ZQWL product.

I have also trialled a NNZN product with Modbus feature, but didn’t use it because of the +5v power requirement. (My real modbus slaves run at +12V)

Not all gateways have this special mode feature. If it is lacking you would need some kind of virtual serial port installing on your host so that OH binding can talk serial.

If your USB works, what advantage are you expecting?

Like this one?
USR

No. That model 300 does not mention Modbus in the blurb. You have to be careful here.

The model 410 is similar but with the Modbus TCP<>RTU gateway feature.

I use these in an industrial setting, a steel-framed warehouse 80x100m with wired ethernet.
I wouldn’t think you would need them in a home, except the odd case where you want to share an existing ethernet to an outbuilding instead of running a long wire from a USB/485 adaptor ?
Maybe the WiFi versions would be of interest though.

Hi all,

I’m using Systemair with modbus and today I have managed to read/write all inputs I was interested in. As first request was for fan speed so the simple way of doing it I came up with (I’m just a starter to OH2):

/etc/openhab2/services/modbus.cfg

serial.fan.connection=/dev/ttyUSB2:9600:8:none:1:rtu:35:5000 serial.fan.id=1 serial.fan.start=100 serial.fan.length=38 serial.fan.type=holding

No need to apply the formula in documentation if you are not reading digital inputs or coils. For all temperatures etc. holding should be used with direct register number. I did read all FAN items, so “lenght” can be only 1 for just a fan speed setup if you like. As for “9600:8:none:1” part- please check your modbus configuration from the HVAC panel, it could be different.

/etc/openhab2/items/default.items

Fan item for read and write, it reads and writes from/to the same register

/etc/openhab2/rules/default.rules

[code]rule "Process fan commands"
when
Item Fans received command
then
logInfo(“FansRules”, “Processing Fans command”)
if(receivedCommand != null) {
switch(receivedCommand) {
case “0” : sendCommand(Fans, 0)
case “1” : sendCommand(Fans, 1)
case “2” : sendCommand(Fans, 2)
case “3” : sendCommand(Fans, 3)
}
}

end

rule "Update Fan speed"
when
Item Fans changed
then
logInfo(“FansRules”, “Processing speed update”)
var currentSpeed = Fans.state as DecimalType
postUpdate(Fans, currentSpeed)
end[/code]

First rule to write a register (change fan speed) based on what you select in website, second one to update a value if you change the speed manually on HVAC (to reflect that change in website).

/etc/openhab2/sitemaps/default.sitemap

sitemap default label="Home" { Frame label="Fans" { Selection item=Fans label="Fan Speed" icon="fan" mappings=[0="Off", 1="Low", 2="Medium", 3="Max"] } }

A selectable item in webpage, changing numbers to human readable format :slight_smile:

Hope that helps someone as I was struggling to get it working. I’m using linux with USB-to-RS485 adapter from aliexpress, RJ45 cable (~8 meters) with RJ45 on one side (connecting to modbus) and 2-wire on another (connecting to USB adapter), schematics are on the Systemair modbus documentation.

Great tutorial!

How can we make usb number static so it doesn’t change on reboot or unplug?

What does this part mean?

have trouble to find the pinout, which did you use?

Can I connect it where the manual control goes?

holdings are configured starting “serial.fan.start” and not in the connect line. After some experimenting I was able to read/write to correct registers if I take 1 off the original one. Not sure why it’s like that, maybe it’s the way it works in OH2 and it’s intentional but as I’m new to this and it just worked- I did not question it :slight_smile:

[quote=“skatun”]have trouble to find the pinout, which did you use?

Can I connect it where the manual control goes?

[/quote]

You need to connect the one marked as 2 in chapter 6 (logical diagram) and the same one (just a picture of the board itself) marked as 11 on the chapter 6.9.1. Do not touch the manual control- it will be connected with RJ11 cable to a different port on the board.
When you are connecting cable on the USB-to-Serial adapter (these 2 wires) make sure you follow the A(-) B(+) polarity shown in chapter 6.

A+ pin4 and B+ pin5 on the RJ45, however it seems like the manual control sits on the same modbus line or?, If I connect it to a splitter on the manual control I only need 1m of cable instead of running a new 15m cable to the PCB

Manual control connects to port marked 3 and modbus to port marked 11 in picture shown in chapter 6.9.1. At least on my unit. Based on the wiring diagram one could assume you can connect modbus from manual control panel also bu I did not try this as it is fixed on my unit so there was no point of connecting with splitters as I could use normal modbus port on the PCB.

So I opened up the remote panel,
Here is the pinout of the Rj 11
Pin1 = GND
Pin2 =12V
Pin3 = B
Pin 4= A

I am struggeling to get it to work… It throws me a lot of errors:

17:41:09.741 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 03 00 64 00 26 85 cf
17:41:09.742 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: CRC Error in received frame: 0 bytes:
17:41:09.744 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@dac561 (unit id 1 & transaction 249). Serial parameters: SerialParameters@858d5[portName=/dev/ttyUSB0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=5000]
17:41:09.792 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 03 00 64 00 26 85 cf
17:41:09.794 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: CRC Error in received frame: 0 bytes:
17:41:09.796 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 2/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@dac561 (unit id 1 & transaction 249). Serial parameters: SerialParameters@858d5[portName=/dev/ttyUSB0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=5000]
17:41:09.844 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 03 00 64 00 26 85 cf
17:41:09.845 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: CRC Error in received frame: 0 bytes:
17:41:09.847 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 3/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@dac561 (unit id 1 & transaction 249). Serial parameters: SerialParameters@858d5[portName=/dev/ttyUSB0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=5000]
17:41:09.849 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 3, throwing last error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@dac561. Serial parameters: SerialParameters@858d5[portName=/dev/ttyUSB0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=5000]
17:41:09.858 [ERROR] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (fan): Error getting modbus data for request net.wimpi.modbus.msg.ReadMultipleRegistersRequest@dac561. Error: I/O exception - failed to read. Endpoint ModbusSerialSlaveEndpoint@5fe948[portName=/dev/ttyUSB0]. Connection: SerialConnection@1c4776d[portName=/dev/ttyUSB0,port=/dev/ttyUSB0]
17:41:10.100 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 03 00 64 00 26 85 cf
17:41:10.105 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: CRC Error in received frame: 0 bytes:
17:41:10.109 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@934ace (unit id 1 & transaction 250). Serial parameters: SerialParameters@858d5[portName=/dev/ttyUSB0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=5000]
17:41:10.157 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 03 00 64 00 26 85 cf
17:41:10.158 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: CRC Error in received frame: 0 bytes:
17:41:10.160 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 2/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@934ace (unit id 1 & transaction 250). Serial parameters: SerialParameters@858d5[portName=/dev/ttyUSB0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=5000]
17:41:10.208 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 03 00 64 00 26 85 cf
17:41:10.209 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: CRC Error in received frame: 0 bytes:
17:41:10.211 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 3/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@934ace (unit id 1 & transaction 250). Serial parameters: SerialParameters@858d5[portName=/dev/ttyUSB0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=5000]
17:41:10.214 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 3, throwing last error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@934ace. Serial parameters: SerialParameters@858d5[portName=/dev/ttyUSB0,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=5000]

Does this means that the USB port is wrong or is it something else?
I tried doing this:

|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 4                                                                                        80M
        |__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=usbfs, 12M

then I plugged in the dongle

[17:28:12] pi@openHABianPi2:~$ sudo lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=usbfs, 12M
        |__ Port 4: Dev 5, If 0, Class=Vendor Specific Class, Driver=ch341, 12M
[17:33:07] pi@openHABianPi2:~$  ls /dev/tty*
/dev/tty    /dev/tty13  /dev/tty19  /dev/tty24  /dev/tty3   /dev/tty35  /dev/tty40  /dev/tty46  /dev/tty51  /dev/tty57  /dev/tty62    /dev/ttyprintk
/dev/tty0   /dev/tty14  /dev/tty2   /dev/tty25  /dev/tty30  /dev/tty36  /dev/tty41  /dev/tty47  /dev/tty52  /dev/tty58  /dev/tty63    /dev/ttyS0
/dev/tty1   /dev/tty15  /dev/tty20  /dev/tty26  /dev/tty31  /dev/tty37  /dev/tty42  /dev/tty48  /dev/tty53  /dev/tty59  /dev/tty7     /dev/ttyUSB0
/dev/tty10  /dev/tty16  /dev/tty21  /dev/tty27  /dev/tty32  /dev/tty38  /dev/tty43  /dev/tty49  /dev/tty54  /dev/tty6   /dev/tty8
/dev/tty11  /dev/tty17  /dev/tty22  /dev/tty28  /dev/tty33  /dev/tty39  /dev/tty44  /dev/tty5   /dev/tty55  /dev/tty60  /dev/tty9
/dev/tty12  /dev/tty18  /dev/tty23  /dev/tty29  /dev/tty34  /dev/tty4   /dev/tty45  /dev/tty50  /dev/tty56  /dev/tty61  /dev/ttyAMA0
[17:35:40] pi@openHABianPi2:~$ dmesg | grep tty
[    0.000000] Kernel command line: 8250.nr_uarts=1 dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2709.boardrev=0xa02082 bcm2709.serial=0xc6cdb751 smsc95xx.macaddr=B8:27:EB:CD:B7:51 bcm2708_fb.fbswap=1 bcm2709.uart_clock=48000000 vc_mem.mem_base=0x3ea00000 vc_mem.mem_size=0x3f000000  dwc_otg.lpm_enable=0 console=ttyS0,115200 kgdboc=ttyS0,115200 console=tty1 elevator=deadline net.ifnames=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
[    0.001317] console [tty1] enabled
[    0.839016] console [ttyS0] disabled
[    0.840403] 3f215040.uart: ttyS0 at MMIO 0x3f215040 (irq = 59, base_baud = 31250000) is a 16550
[    1.621370] console [ttyS0] enabled
[    3.474022] 3f201000.uart: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
[   10.049806] systemd[1]: Expecting device dev-ttyS0.device...
[   10.557358] systemd[1]: Starting system-getty.slice.
[   10.566884] systemd[1]: Created slice system-getty.slice.
[   10.574352] systemd[1]: Starting system-serial\x2dgetty.slice.
[   10.584749] systemd[1]: Created slice system-serial\x2dgetty.slice.
[  641.323074] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0
[  694.578890] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[197120.581891] [  490]     0   490     1110       30       6       0        0             0 agetty
[197120.594687] [  511]     0   511     1370      220       7       0        0             0 agetty
[391518.767389] [  490]     0   490     1110       30       6       0        0             0 agetty
[391518.779894] [  511]     0   511     1370       30       7       0        0             0 agetty
[578720.176689] [  490]     0   490     1110       30       6       0        0             0 agetty
[578720.189125] [  511]     0   511     1370       29       7       0        0             0 agetty
[762320.608835] [  490]     0   490     1110       30       6       0        0             0 agetty
[762320.621248] [  511]     0   511     1370       29       7       0        0             0 agetty
[775046.477450] usb 1-1.4: ch341-uart converter now attached to ttyUSB0

Any ideas?

@ZyXEL can you confirm what error codes you got when it was wrong usb port or register number. Its either wiring wrong, bad usb dongle, wrong usb port or wrong register, howe er the error code gives me no clue which one of these it is. Any ideas how to figure that out?

@ZyXEL What modbus binding do you use? 1.10?

I’m struggling with this as well. I’ve tried a cheap ch341 device as well as a ftdi device, but I can’t get any of them to work…

I hooked up pin4 to B and pin5 to A and plugged the RJ45 into the connector on the top of my VTR300. Sounds about right? Used the suggested config further up, but no luck…

For those who got it to work, how is the modbus config on the villavent unit? I noticed there is a meny under modbus which is called “gateway”, and on mine it says “not present”. Not sure what it means or if it is relevant.

So today i connected my usb modem directly to my laptop and used baudrate 9600 in the arduino serial monitor and this came out:

UUU⸮⸮]⸮⸮⸮UU⸮]]R]U⸮Pu⸮P⸮

at rapid speed, does that mean the wiring works?, when i swapped A and B nothing came out.

Same rubbish when I changed the setting to 19200 in the systemair, is this normal. Is it some kind of binary prototcol and not ascii?

Sounds to me like you are getting data. RTU is not ASCII from what I can tell, so its probably right. I don’t get anything out of my serial adapter though, so I must be doing something wrong…

For reference, I have this udev rule to create softlink, set permissions and owner for the serial device:
SUBSYSTEM==“tty”, ATTRS{idVendor}==“0403”, ATTRS{idProduct}==“6001”, OWNER=“openhab”, MODE=“0600”, SYMLINK+=“modbus”

This gives me:
ls -al /dev/ttyUSB0 /dev/modbus
lrwxrwxrwx 1 root root 7 sep. 19 22:22 /dev/modbus -> ttyUSB0
crw------- 1 openhab dialout 188, 0 sep. 22 09:51 /dev/ttyUSB0

In /etc/defaults/openhab2 I also have:
EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/modbus"

Which is something I understand is often necessary for making serial ports work in openhab. I have a similar setup for my zwave dongle which works, so I think this should be sufficient.

I asked system air and they said I need to connect it to the modbus port and not the control panel port, so I need to take the saw to get of the lid to connect the wires, I will see what I manage todo by the end of the month…

When you get connected, you can test this tool:
http://www.focus-sw.com/fieldtalk/modpoll.html

I dont get any data, but I have probably f***ed up somewhere… Going to check the internal wiring since I have connected to the plug at the top.

Hi, I get this error:

2017-09-30 13:47:32.390 [ERROR] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (fan): Error getting modbus data for request net.wimpi.modbus.msg.ReadMultipleRegistersRequest@1eb21e1. Error: I/O exception - failed to read. Endpoint ModbusSerialSlaveEndpoint@1386d57[portName=/dev/ttyUSB0]. Connection: SerialConnection@14a68b8[portName=/dev/ttyUSB0,port=/dev/ttyUSB0]

Is wiring or USB port wrong?

I have two usb things attached:

[13:39:39] pi@openHABianPi2:~$ lsusb
Bus 001 Device 005: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
Bus 001 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
[13:40:36] pi@openHABianPi2:~$ sudo lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=usbfs, 12M
        |__ Port 4: Dev 5, If 0, Class=Vendor Specific Class, Driver=ch341, 12M
[13:40:45] pi@openHABianPi2:~$ ls /dev/ttyUSB*
/dev/ttyUSB0
[13:42:12] pi@openHABianPi2:~$

how to know which is usb0 and not?

Your USB devices have different drivers. You can check which driver is used for a device by using:

udevadm info --query=all /dev/ttyUSB0

You can find something like:

E: ID_USB_DRIVER=ch341

Which will match the Driver from lsusb -t