I am trying to convert an application that reads a serial string from AsyncPro to TMSAsync32 For some reason my enabled timer does not seem to work or trigger my second event that I am using to clean code. I used the capture demo snippet to create a sample. I have two procedures 1. To capture a raw string. 2. To clean my string of unwanted characters. (see below) I am also trying to set this up for two different devices. The first is a continuous, the second requires 'W' + #13^M to be sent to request the string from the device. I can get my procedures to work manually with out the timer and use with a button but the response is very slow. Cannot understand why the timer does not work yet it works so easy everywhere else. Maybe I need to flush buffers. Any help is appreciated.
procedure TForm1.VaComm1RxChar(Sender: TObject; Count: Integer);
var
I: Integer;
Tmp: string[10];
begin
// Flush - How can I flush.
// need to send to request string.
//:= 'W' + #13^M
//read data from comport
Tmp := VaComm1.ReadText;
Memo2.Lines.Text := Memo2.Lines.Text + Tmp;
sleep (300);
LabelRawstring.caption := tmp;
for I := 1 to Length(Tmp) do
case Tmp of
#10:; //skip this one
#13: //Waiting for this?
begin
DoEvent(FMessage);
FMessage := ''; //reset received message
end;
else //not #10 or #13
FMessage := FMessage + Tmp;
end;
end;
//////////////////////////////////////////////////////////
// Second procedure off timer to clean characters.
var
I: Integer;
L: Integer;
C: Char;
S: string;
WGT: string;
begin
WGT := '';
C := '.'; { Decimal Separator }
S := LabelRawString.caption;
L := Length(S);
for I := 1 to L do
if (S in [C,'0'..'9']) then { Only Decimal Separator & Digits }
WGT := WGT + S;
LabelWGT.caption := WGT;
end;
/////////////////////////////////////////////////