[fpc-pascal] Serial to TCP gateway in FPC?

Bo Berglund bo.berglund at gmail.com
Tue Jun 27 00:28:42 CEST 2017


On Sun, 18 Jun 2017 09:04:49 +0200, Bo Berglund
<bo.berglund at gmail.com> wrote:

>So I installed
>serial2net on the RPi, making it publish the serial port as a TCP port
>(#2091). This part works OK, so whatever is sent on the TCP socket
>connection gets transferred to the RS232 serial line and vice versa.

My statement above seems to be correct, ser2net does work properly on
my RPi machine as witnessed by the fact that I can use a TCP-enabled
client software (written using Lazarus) against the controller and
operate it as intended.
The data passes through ser2net exactly as expected.

But when I hook up the serial-only client (a Delphi XE5 program) via a
relaying program I made myself (again in Lazarus) using the FPC serial
unit and Indy TcpClient objects it fails on initial connect and does
not pass into the main control.
The very strange thing is that the ser2net logs show the incoming data
from the network as being passed on to the serial port and there is
some response but then it just stops.
The protocol transfer should look as follows:

Client S/W      Controller   Action
---------------------------------------------------------
0x10       =>                Switch to remote control
           <=   0x06 (ACK)   Command accepted)
0xD1       =>                Switch to data transfer mode
           <=   0x06 (ACK)   Command accepted
<cmd>      =>                Any data transfer command
----------------------------------------------------------

I.e:
10 06 D1 06 <some command>
But it turns out to be:
10 06 D1 D1 D1

Where D1 is inbound from the client and is repeated because there is
no ACK response.

So in this case the ser2net seems to receive the command (and
therefore transmitting it via the serial port), but it does not
recognize any response...

Is there any similar experience here with ser2net?

NEXT:
It looks like I will have to rewrite my relaying program now used in
Windows for the conversion to TCP from RS232 to also work as the
replacement for ser2net on RPi3. This way I can monitor the data
better and check time intervals etc.

My problem here is the fact that the RPi is headless so the GUI
program I have written with Lazarus will not work. Instead I have to
make a console version that can run on RPi for the test and here I
have the concern that I am using Application.Processmessages, which I
believe cannot be used in a console program.
How can I replace it?


-- 
Bo Berglund
Developer in Sweden




More information about the fpc-pascal mailing list