[fpc-pascal] Question on programming serial communication.

Rainer Hantsch office at hantsch.co.at
Mon Feb 25 10:58:23 CET 2008


I decided to port a DOS program (written in BP7) to Linux, because it becomes 
hard and harder to maintain it since I completely changed to Linux. Because 
this program actually controls my central heating, this is a good project for 
summer time, where I have no pressure to get it uninterrupted working.
To give some overview:
This program uses a TSR driver named "FOSSIL", driver name X00.SYS, which 
actually does the whole low-level stuff and has some very smart features built 
in, like:
- supporting up to 8 serial ports (in DOS !!!)
- having big buffers for sending and receiving
- allowing me to transfer particuar characters or a whole block of data into
  or from the buffer
- allowing me to test how many bytes are in every buffer and how much space 
  is free (before doing a block transfer)
- allowing me to set easily communication parameters like
  baud-rate, parity, num of start-/stopbits, kind of handshaking, ...
- allowing me to flush buffers (erases all content of the Tx or Rx buffer)
- directly control and test control lines (rise/lower DTR, RING, ...)

Actually, this X00 driver was written for BBS systems with analog modems 
around 1970-1980, namely for MAXIMUS and OPUS. This BBS programs were the best 
ones at their time as far as I can remember, of course, at that time there was 
no real Internet available to the public. ;-)

So I took this driver, because it made my life easy: Actually I didn't have to 
do much more than loading the TSR (here I could pass some parameters to it, 
i.e. how many serial ports - and which ports - it should take over, then I 
simply loaded my program. 
My program was talking through a SW-Interrupt with the X00 driver, tested its 
presence, and was then able to exchange data smoothly at any desired speed. 
Perfect for me.

Michael Van Kanneyt told me a few days ago that there is some sort of TSerial 
available, but he has no details at hands, because he didn't use it. But he 
mentioned that some people are using it.

Can somebody, please, give me more details on TSerial, what it can (not) do, 
maybe a little "hello world" using it, and so forth? I definitely need 
buffering and the possibility to empty a buffer, test if it is empty 
(=everything was/is sent), and to see its content (how much is currently 
inside, to see if dataflow is actually happening or not). Of course, 
everything must work non-blocking.


Please, be so kind and help. I have a book about FreePascal (from Michael), 
but this book is too old and does not cover all the new functions of 
FreePascal, so it is somewhat problematic to me, because I write programs 
without an IDE and/or Lazarus.


  Ing. Rainer Hantsch

More information about the fpc-pascal mailing list