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

**URL:** https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509
**Category:** Hardware
**Created:** [16 August 2022 16:38 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509 "2022-08-16T16:38:50Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![FNW2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fnw2022/32/66307_2.png) [@FNW2022](https://discourse.nodered.org/u/FNW2022)
#### Post date: [16 August 2022 16:38 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/1 "2022-08-16T16:38:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [17 August 2022 06:08 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/2 "2022-08-17T06:08:34Z")

</div>

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](https://flows.nodered.org/node/node-red-contrib-modbus) 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](https://www.studer-innotec.com/en/downloads/) under "software and updates"). There are some modbus experts here on the forum who might be able to assist.

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [17 August 2022 06:16 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/3 "2022-08-17T06:16:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![FNW2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fnw2022/32/66307_2.png) [@FNW2022](https://discourse.nodered.org/u/FNW2022)
#### Post date: [17 August 2022 07:21 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/4 "2022-08-17T07:21:36Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8ca69c0fe64bc150b42c3804b2750abe111eaf91.jpeg)

There is a separate [RS-232 protocol specification](https://www.studer-innotec.com/media/document/0/technical-specification-xtender-serial-protocol-v1.6.32.zip) 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](https://moxa.com/getmedia/87fa02cb-73d5-4cd9-a1e0-8663f1637df5/moxa-nport-5000-series-manual-v6.7.pdf) - see page 68.

---

<div class="post-metadata">

### Author: ![FNW2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fnw2022/32/66307_2.png) [@FNW2022](https://discourse.nodered.org/u/FNW2022)
#### Post date: [17 August 2022 07:22 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/5 "2022-08-17T07:22:25Z")

</div>

[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](http://xcom.studer-innotec.com) - see _Destination IP address 1_) works without any problem.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d295300be9638c446b8ca1ac2b9aaee6a224158.png)  
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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c36e97ea32a61ebf2251c52d402d951a13ea2d98.png)  
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...

---

<div class="post-metadata">

### Author: ![FNW2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fnw2022/32/66307_2.png) [@FNW2022](https://discourse.nodered.org/u/FNW2022)
#### Post date: [17 August 2022 07:23 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/6 "2022-08-17T07:23:03Z")

</div>

When I enter the [Studer web portal](https://portal.studer-innotec.com/) 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.

---

<div class="post-metadata">

### Author: ![FNW2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fnw2022/32/66307_2.png) [@FNW2022](https://discourse.nodered.org/u/FNW2022)
#### Post date: [22 August 2022 09:08 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/7 "2022-08-22T09:08:26Z")

</div>

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) 🎉

My current (very simple) flow looks like this:

![Flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b0cf637537900bdea5bc5b475449d12aee82a05b.png)

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

 ![Request](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e257ab26f16209a178be7f588244f4c372c7b7bd.png)

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

 ![Response](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b09133af9e1ca7b542574db8732217ec1603c463.png)

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:

 ![Checksum Algorithm](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e535ff2eafff9a3488d84246014617d788d60fc.png)

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

 ![Checksum contents](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/7/57f89a80f5d1c09c8ab58886d58c403b9efe115b.png)

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...

---

<div class="post-metadata">

### Author: ![FNW2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fnw2022/32/66307_2.png) [@FNW2022](https://discourse.nodered.org/u/FNW2022)
#### Post date: [22 August 2022 22:16 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/8 "2022-08-22T22:16:05Z")

</div>

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:

```auto
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...

---

<div class="post-metadata">

### Author: ![FNW2022](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fnw2022/32/66307_2.png) [@FNW2022](https://discourse.nodered.org/u/FNW2022)
#### Post date: [25 August 2022 17:43 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/9 "2022-08-25T17:43:11Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/53d0fa76c7c218d72487b7eff33c6882970cbfb4.png)

(see chapter 3.3 on page 7)

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [8 September 2022 17:43 UTC](https://discourse.nodered.org/t/communicate-with-inverter-via-rs-232-to-ethernet-gateway-moxa-nport-5110a/66509/10 "2022-09-08T17:43:14Z")

</div>

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