Bo Berglund wrote:

So now I am after a serial comm implementation for Lazarus/Fpc to work
in a Linux embedded environment which gives me these possibilities.

Yes, and as I've said before I'm using the standard serial unit plus fpSelect() without problems. Horses for courses, as we say over here.

Irrespective of what solution you choose one thing that you might need to consider is how accurately you can time things. In particular, the type of protocol that I work with needs timeouts applied from the point where the computer has actually sent the final character of a packet, so whatever code is handling your state machine (or whatever) needs to be able to see the comms subsystem at that level- not just at an abstracted event level.


function SerReadTimeout(Handle: TSerialHandle; var Buffer; mSec: LongInt): LongInt;

(* This is similar to Serial.SerRead() but adds a mSec timeout. Note that this *) (* variant returns as soon as a single byte is available, or as dictated by the *) (* timeout. *)

VAR     readSet: TFDSet;
        selectTimeout: TTimeVal;

begin
  fpFD_ZERO(readSet);
  fpFD_SET(Handle, readSet);
  selectTimeout.tv_sec:= mSec DIV 1000;
  selectTimeout.tv_usec:= mSec * 1000;
  RESULT:= 0;
  IF fpSelect(Handle + 1, @readSet, NIL, NIL, @selectTimeout) > 0 THEN
    RESULT:= fpRead(Handle, Buffer, 1)
end { SerReadTimeout } ;


function SerReadTimeout(Handle: TSerialHandle; var Buffer: ARRAY OF BYTE; count, mSec: LongInt): LongInt;

(* This is similar to Serial.SerRead() but adds a mSec timeout. Note that this *) (* variant attempts to accumulate as many bytes as are available, but does not *) (* exceed the timeout. *)


On top of those you put whatever state machines etc. that you need.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to