# How to ensure reliable RS-232 connection?



## m4rtin (Oct 18, 2010)

I have a configuration file for a network device(2100 lines). This device is configurable only over console line. If I copy chunks of those lines into terminal(I use _minicom_), there will be mistakes (sometimes some characters missing, space characters added etc). Hardware flow control and software flow control doesn't help either(as I use RS232-to-USB converter, I'm even not sure, if RTS and CTS signals are implemented). I tried with _cu_ utility, but same issues appeared. There will be mistakes even if I copy in ~100 line parts. What causes those missing/added characters? Is there a terminal emulation program under BSD, which supports pausing before each byte/line transfer? :OOO


----------



## SirDice (Oct 18, 2010)

See if the device supports zmodem or xmodem file transfer.


----------



## wblock@ (Oct 18, 2010)

m4rtin said:
			
		

> I have a configuration file for a network device(2100 lines). This device is configurable only over console line. If I copy chunks of those lines into terminal(I use _minicom_), there will be mistakes (sometimes some characters missing, space characters added etc). Hardware flow control and software flow control doesn't help either(as I use RS232-to-USB converter, I'm even not sure, if RTS and CTS signals are implemented). I tried with _cu_ utility, but same issues appeared. There will be mistakes even if I copy in ~100 line parts. What causes those missing/added characters?



Baud rate mismatch, parity mismatch, start/stop bits mismatch, unshielded cable, ground wire in cable not connected, cable run near RF interference source.  RS232 sucks.  Try a different USB-serial adapter if you can.  Lower baud rates are more forgiving.



> Is there a terminal emulation program under BSD, which supports pausing before each byte/line transfer? :OOO



It would not be hard to do that in a script.  But check the parameters listed above first.


----------



## m4rtin (Oct 18, 2010)

SirDice said:
			
		

> See if the device supports zmodem or xmodem file transfer.


unfortunately it doesn't.



			
				wblock said:
			
		

> Baud rate mismatch, parity mismatch, start/stop bits mismatch, unshielded cable, ground wire in cable not connected, cable run near RF interference source.  RS232 sucks.  Try a different USB-serial adapter if you can.  Lower baud rates are more forgiving.
> It would not be hard to do that in a script.  But check the parameters listed above first.


Baud-rate, parity and start/stop bits are checked. I tried to keep the serial cable away from other cables, but there are still few errors(about one missing character or unnecessary space character for every 1000 characters). *SirDice*, I thought about script as well. Something which copies line after a line from a file and sends those lines to TxD. "sleep 1" after each line  However, _minicom_ is clearly not scriptable. Any suggestions?


----------



## SirDice (Oct 18, 2010)

If this is a network device I'm sure you can (temporarily) activate one of it's interfaces, assign an IP address to it and scp or tftp the configuration file.


----------



## aragon (Oct 18, 2010)

wblock said:
			
		

> Try a different USB-serial adapter if you can.


This is the most likely culprit IMHO.


----------



## m4rtin (Oct 26, 2010)

*wblock*, *aragon*,
I tried with three different USB-to-RS232 adapters. Two of those were _noname_ adapters and one was _Trendnet TU-S9_. 

One of those _noname_ adapters and _Trendnet_ one used the same chip(PL-2303HX) and are identified as "Prolific Technology Inc USB-Serial controller". Other _noname_ adapter is identified as "FTDI USB serial converter". 

However, at least one of those USB-to-RS232 has ground wire clearly present- in addition to Vcc, D-, D+ and GND cables, there is an additional wire, which is soldered to USB-A connector in one end and to the DE-9 connector in the other end. PL-2303HX based USB-to-RS232 adapters should support hardware flow control as well, because PL-2303HX supports RTS and CTS(PL-2303HX datasheet http://www.stkaiser.de/anleitung/files/PL2303.pdf). 

Console cable is ~1m long and I keep it away from other cables in order to avoid electromagnetic interference. Maybe buffers of USB-to-RS232 adapters get filled..or something like this..I mean if I copy line-by-line, I have had never any issues. On the other hand, if I copy chunks of lines, there are constantly some characters missing or few added. All additional ideas/suggestions are most welcome 

Isn't there a terminal emulation program under BSD, which supports pausing before each byte/line transfer? Or any hints, how to script something like this? :OOO


----------



## wblock@ (Oct 26, 2010)

m4rtin said:
			
		

> However, _minicom_ is clearly not scriptable. Any suggestions?



Looks like it is...  Has expect and sleep commands, too.  The nice way to do this is to wait (expect) the command prompt from the other end after each line.


----------



## jalla (Oct 26, 2010)

Did you try tip(1)?
As a general solution to scripting interactive programs you could take a look at lang/expect.


----------



## aragon (Oct 26, 2010)

m4rtin said:
			
		

> Isn't there a terminal emulation program under BSD, which supports pausing before each byte/line transfer? Or any hints, how to script something like this? :OOO


Perhaps chat(8) can help you.


----------



## m4rtin (Oct 24, 2011)

Thank you for all the answers. Finally I went with the _socat_ solution:


```
while read line; do echo $line | socat - /dev/cuau0,raw,echo=0; sleep 2; done < configuration-file.txt
```

..and it works fine As you can see, it pauses for 2s after each command.

Just for out of interest, why do errors(some characters missing, space characters added etc) appear in case of chunks of configuration lines are pasted into terminal? I connected this device directly to my PC's serial port(skipping the RS232-to-USB converter) and still in case I copy even ~100 line chunks, the errors will sometimes appear :OOO


----------

