[fpc-pascal] Serial to TCP gateway in FPC?
Lukasz Sokol
el.es.cr at gmail.com
Tue Jun 27 12:10:12 CEST 2017
On 26/06/17 23:28, Bo Berglund wrote:
[...]
>
> 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?
>
>
If you are comfortable with thread programming, you could
have a thread handle the hardware / serial handling
(by keeping the 'messages' in a 'queue' or 'queues' (one outbound, one inbound).
The serial handling thread would poll the serial port and handle serial sending timing etc,
and put the received data into the rx 'queue'. Depending on how fast the serial communications
are, the thread could then ThreadSwitch to give up the reminder of its time slice if not needed,
and sleep for the rest of the time.
Then your main program would periodically check the queues and depending on whether it needs
to do something or not, will do it and then threadswitch() and sleep(),
The main thread would then be responsible for network / hi level 'protocol' communication,
data conversion
(e.g. you could assume network data 'text' encoded in base64, or even text based json,
that is then converted to/from binary form for serial)
IIRC some network handling components/libraries use threads of their own.
If you wanted to use 'just' network sockets, you'd probably need to handle
network 'low level' communications in threads anyway.
hope this makes (some) sense
_l.
More information about the fpc-pascal
mailing list