Communicate with inverter via RS-232 to Ethernet gateway MOXA NPort 5110A

Hi folks,
my actual setup consists of a PV power plant using a Studer Xtender XTM 4000-48 battery inverter and the corresponding RS-232 interface (Xcom-232i) to control the device. I would like to use the MOXA NPort Ethernet bridge instead of plain RS-232 communication due to the rather large distance (> 20m) between the inverter and the Raspberry Pi running Node-RED v3.0.2.

I'm actually stuck pretty much at the beginning: While I was able to setup a simple TCP listener which obviously connects fine, but can't send any data to the device. It's due to my lack of knowledge about setting up a TCP/IP connection on low-level base, especially in this special case when it's initiated by the device to be controlled (TCP client mode). As a web developer, I'm usually using more high-level programming languages like JavaScript, C# and .NET Core.

Can anybody explain to me how to do this or give me a guideline or link to a respective tutorial, where I can gain some more expertise?
I want to know how to establish a bidirectional TCP/IP connection with this gateway as well as read and write data from/to it correctly, which means in human-readable string format.

Thanks for any support in advance.
Please feel free to ask any detail of my setup.
I guess, a flow JSON of my still rather simple setup (tcp-in node --> debug node) does not shed much light on this specific case, as it is rather useless without the hardware involved.

I did some quick searches, this Studer device appears to be talking in modbus (which is RS-485), the ethernet bridge appears to support this protocol.

Perhaps the modbus node can help you to connect/read/write ? I am not familiar with this protocol and you will need protocol documentation from Studer (see the Xcom-485i download link under "software and updates"). There are some modbus experts here on the forum who might be able to assist.

Can you also show us the setup page of the device to demonstrate how you have configured it to talk to the inverter ? With these things the devil is normally in the detail

Craig

Thanks for the fast reply!

@bakman2: Studer provides different solutions (RS-232 / RS-485 / LAN / CAN) regarding controlling their devices, but it's definitely RS-232 over Ethernet (TCP) in my case as I am using the Xcom-LAN module, which actually are two "concatenated" devices: The aforementioned Xcom-232i and the MOXA NPort 5110A Ethernet gateway attached to it - as shown in the following picture:

There is a separate RS-232 protocol specification available on the Studer website which I naturally already studied.
Unfortunately, it does not contain any information about how to communicate with the MOXA Ethernet gateway that sits in between the Xcom-232 and Node-RED in my case. So my main issue is how to send a request to the Studer components if the communication handshake has to be done by the Ethernet gateway (which MOXA calls TCP Client mode in their manual - see page 68.

[As the forum software does only let me post two links per message, I had to split it up - sorry for that...]

Currently, the Ethernet gateway configuration looks like this - and communication with the Studer web portal backend server (xcom.studer-innotec.com - see Destination IP address 1) works without any problem.


Therefore, communication with the inverter is 100% possible that way. I simply don't know how to do it in a "low-level" way...
The MOXA device is running on IP 192.168.0.6 and will send all incoming serial data to the destinations entered in that configuration page. Moreover, it will initiate a connection to those hosts on its own.

My still very simple Node-RED demo setup currently looks like this:


As written in my initial post, the TCP in node obviously receives a connection on port 4001 within a second after the flow has been deployed. Changing it to any other port results in 0 connections being shown permanently, so I guess this configuration is OK...

When I enter the Studer web portal and start a remote control session in the web (which can only be done manually in a simple GUI - so automating things is not possible that way), I can see and also change all settings of the inverter. While doing so, I can see the RS-232 messages being transferred shown in the Node-RED debug log (as shown in my screenshot).
But what I did not manage to do is actively sending a simple request to the Ethernet gateway / Studer inverter myself within Node-RED. As the TCP communication is always initiated by the Ethernet gateway, I don't know how to send something to it - my knowledge about TCP is obviously too limited...
That's where I need a first hint.

I guess decoding the rather complex byte stream (which appears in two blocks instead of just a single one in the debug log for reasons I don't actually know) will also become quite a task, but I managed to do so already with another native RS-232 device (EMUS BMS system used on my PV battery bank)...

I hope those additional information help you see my actual problem a little more clearly. Please feel free to ask any additional details I might still have forgotten.

Hi again,

after some more reading, trying and fiddling around with the TCP nodes, I finally managed to set up a working communication with the MOXA Ethernet bridge (and hence the Studer inverter behind it) :tada:

My current (very simple) flow looks like this:

Flow

I send a simple (currently still static from the example in the specification) request as byte buffer to the TCP out node

which then leads to the matching / expected response in the TCP in node which listens on port 4001

So it now boils down to "just" writing the corresponding software to build & encode requests and decode the responses.
As said before, I am not really deep into those low-level coding, unfortunately.
Therefore, I am currently stuck at the checksum calculation which is pretty hard for me to understand.
This is the corresponding chapter in the specification:

And that's for example the two checksums in a request:

The header_checksum is calculated over all data from start_byte until (and including) data_length.
The data_checksum is then calculated over the whole frame_data.

Although this is definitely not a Node-RED specific question, I still hope that somebody is willing to support me in writing the necessary (generic) checksum function...

After taking another close look at the specification and twisting my head, I came up with the following first draft of a checksum calculation function:

function computeChecksum(buffer) {
    let a = 255;
    let b = 0;

    for (let i = 0; i < buffer.length; i++) {
        a = (a + buffer[i]) % 256;
        b = (b + a) % 256;
    }

    let checksum = Buffer.alloc(2);
    checksum[0] = a; // should be 0x6F, but is 0x19 (= 25 as decimal)
    checksum[1] = b; // should be 0x71, but is 0x68 (= 104 as decimal)

    return checksum;
}

Unfortunately (but as expected), the output is not correct when I put the header buffer of the example mentioned in the specification into it.
But maybe I'm already close and someone can spot the mistake - at least I have tried something and hope it was worth it...

After some more fiddling around, I can answer the question myself: The checksum calculation above works just fine.

It was just pure stupidity: I accidentally included the first start_byte (0xAA) in the buffer I passed to the function which is actually not involved in the header_checksum (my red box in the picture above is wrong and should start at the frame_flags byte) according to the specification:

image

(see chapter 3.3 on page 7)

Without that byte, the result is correct - so sorry for wasting your time...

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.