Il 23/10/2017 21:33, Sven Barth via Lazarus ha scritto:
How do you pass the SendMessage() method to your thread? And how does
the code look that calls it?
The SendMessage() method belongs to the main thread only, and is
supposed to execute only in the main thread context.
It fills up a buffer (TBuffer), and sets a SendLen value and an OkToSend
boolean to true.
The buffer and SendLen are written by the main thread and read from the
serial thread. OkToSend is set by the main thread and reset by the
serial thread.
TBuffer, SendLen and OkToSend are public variables not belonging to any
object.
The code looks like that:
......
TBuffer[J] := Etx;
inc(J);
SendLen := J;
OKToSend := True;
if not SendCreated then begin
SendCreate;
end;
if Send.suspended then
Send.Resume;
Application.ProcessMessages;
end;
The serial thread checks for OkToSend, sets it to false, and takes care
of sending the message and getting an answer. Once it's done it posts a
message for the main thread and suspends itself.
SendMessage() isn't invoked any more until the serial thread has managed
to send the message, and to receive an answer, or the communication has
timed out.
Giuliano
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus