frangoteam / FUXA

Web-based Process Visualization (SCADA/HMI/Dashboard) software
https://frangoteam.org
MIT License
2.49k stars 741 forks source link

[BUG] Modbus RTU communication 4800bps time out before completion #1107

Open harvie256 opened 3 months ago

harvie256 commented 3 months ago

When a Modbus RTU device is setup with a baud of 4800, FUXA does not wait long enough for the transmission to complete before throwing an error, e.g.: "2024-03-10T04:59:22.271Z [ERR] 'Weather Station' _readMemory error! Error: Data length error, expected 7 got 1"

The device was tested with Qmodbus and python minimalmodbus library, and both worked as expected.

The serial traffic was sniffed, and verified all communication on the wire was happening as it should.

The issue was resolved by changing the device to use 9600 baud and updating FUXA. FUXA now collects data as expected. However this isn't a real fix, as lower baud rates are sometimes needed to communicate with devices at the end of long cable runs.

It looks like somewhere there is a timeout that is occurring after only the first byte is received.

Thanks

tranquilo commented 3 months ago

When you configured the Modbus RTU device on FUXA, did you specify the other parameters besides baudRate? Code reference:


        try {
            if (type === ModbusTypes.RTU) {
                const rtuOptions = {
                    baudRate: parseInt(data.property.baudrate),
                    dataBits: parseInt(data.property.databits),
                    stopBits: parseFloat(data.property.stopbits),
                    parity: data.property.parity.toLowerCase()                    
                }```
harvie256 commented 3 months ago

Yes, everything was set correctly.

External to FUXA, writing to the device to change baud rate to 9600, then changing in the baud rate in FUXA with NO other changes fixed the issue.

Where actually is the timeout for this transaction set? I went hunting but couldn't find it (my knowledge of JS isn't great.) If I knew where the timeout was set I could modify and verify if that resolved the issue by changing the device back to 4800.

unocelli commented 3 months ago

Hi, I'm not sure but could be a problem with the read delay. can you try to change the delay for example to 100 milli: change fuxa\server\runtime\devices\modbus\index.js line 122 and 131 with readVarsfnc.push(await delay(100));

harvie256 commented 3 months ago

Thanks I'll give it try over the weekend!

dtx1234 commented 2 months ago

hi,@harvie256 ,Have you solved this problem?I have the same problem.

unocelli commented 1 month ago

Hi, I added the possibility to set a frame delay that maybe can help (in master branch), would be nice to try and give me feedback

harvie256 commented 1 month ago

Sorry I'm overseas for a few weeks, but will defiantly try it when I'm back.