# Roline RS232 to Ethernet and Socat

## MacGyver031

Hi folks,

I am in the process of creating modules for my automated home project. In the home-office I have a 24/7 server which has one 8port relay card connected to /dev/ttyS1. This is quite cool and I have implemented a web frontend so I can use my homepage and mobile device to switch on and off my printers, computer and other things in the home office.

Now I have bough a second 8port relay card and a Roline RS232 to Ethernet gateway (15060015). This combination will be implemented in my living room taking care of switching on/off the lights, water pump etc. BUT I have run into a problem:

```
socat pty,link=$HOME/vmodem0,raw,waitslave IP_OF_ROLINE:PORT
```

successfully connects to the relay card, BUT over 30% of the commands (commands are 4byte raw data with all combination) arrive corrupted! That means that the relay card is not switching reliably.

I have connected to a second PC to the Roline with a null-modem cable and have seen that socat -> roline link is unable to zmodem transfer data! while roline -> socat works without error!

I have the feeling that socat is not going into full (blind-)raw mode, it interprets some byte(s).

Could any one help me on this? I have used the winows-driver and the windows control-software for the relay card which seems to work. The software which works directly with the /dev/ttyS0 works fine too, so I conclude that socat must be "superfine" tuned so I can go on with my project.

Thanks.

----------

## BradN

I'm not sure if this will help you or not, but look into the stty command, it has options to configure tons of stuff like that.

That said, 30% seems high, are you sure you don't actually have the port in 7 bit or parity mode or something?

Maybe knowing the pattern of corruption would help.

----------

## TJNII

 *MacGyver031 wrote:*   

> socat -> roline link is unable to zmodem transfer data! 

 

Yea, this doesn't surprise me.  x/y/zmodem transfers are really fragile.  One of my coworkers and I disagree on the exact mechanics, with my position being that the RS232-ethernet conversion does not reliably transfer unprintable characters.  My coworkers position is that the transfer is intolerant to timing issues so the data must be on the line when the client expects it, so the bridge must buffer and implement the transfer protocol locally.  Regardless, you're probably not going to get zmodem working over a ethernet->rs232 bridge, it is a steep uphill battle.  The only thing I can recommend is make sure you have a low number of switches between the converter and the client (preferably a crossover cable for testing) and be sure to use CRC on your transfer.

You can also run RS232 over cat-5 so that you can connect your board to a machine instead of a converter.  If you really know your way around a workbench you may want to just make your own relay board that talks straight ethernet or character based RS232.

That said, why does a simple serial relay board use zmodem?

----------

## MacGyver031

Hi,

Thanks,

Port has been set correctly to 8bit, 1bit stop, parity off and controll off (as it sould be).

Pattern which doesn't work are:

0x06

0x30

0xff

and so on, I haven't yet tested others. 

```
opost=0
```

 seems not to work properly.

I will tryout stty command as soon as possible.

----------

## BradN

0x30 is ascii numeral "0", so it shouldn't be an issue of nonprintable characters.

I noticed all those values should have the same parity though, does toggling one bit in any of the failing values make it work again?

----------

## TJNII

Connect the RS232 converter to a machine via a null-modem cable and see what the converter is putting out.  That will narrow down potential problems.

----------

## MacGyver031

 *TJNII wrote:*   

> That said, why does a simple serial relay board use zmodem?

 

Hi, 

sorry for not being clear: my relayboard needs command of 4bytes (command, relayboard adress, command, xor-checksum), I have seen that the program which I use for a directly connected to the server serial port, works like a charm.

The second board is a bit far away from the server, so I bought a Roline RS232 to Ethernet adapter. When I route the commands created from the program to a socat generated virtual-com-port then the board goes gang ho on some combination of switch-state.

So I wanted to see if the communication is working well and connected the RS232-Gateway to a second computer and ran on both minicom and made some checking. There I saw that socat -> second computer x/y/z modem file transfer do not work! BUT second computer -> socat works!

So I conclude that socat has some payload interpretation (such as stuffing of 0xff to something else), which I would like to switch off. I have not yet had the chance to check the windows-driver of roline well, but I will do it if I am unable to socat work reliably.

Meanwhile I have seen that option 

```
opost=1
```

 (output processing) is making about 50% less error than  *Quote:*   

> opost=0

 . I have tested 0x00 - 0x5f and found out that 0x0f is one of the problematic byte. I am on the process of testing all byte-code and will report a.s.a.p.

----------

