Home > Back-end >  DELPHI questions about MSCOMM
DELPHI questions about MSCOMM

Time:09-21

The younger brother in my test using mscomm control, encounter problems as follows:
1, receive full length is not fixed, but the length of each return point is fixed in the 11, such as only one point is back to 11, there are two points is 22,,,
2, I hope is on the return value judgment, if received 11 value for A specified action (read memory address) and displayed in the EDIT, are also likely to receive at the same time, the length is 11,33,55 here when the time is very short, such as the return value is O (00.111.1) read the address, and A return value is O (00.112.1), read the address B may return values at the same time is O (00.111.1) O (00.112.1) O (00.113.1) O (00.114.1), how individual judgment and the read address?
Write the code as follows:


The begin
With MSComm1 do
The begin
CommPort:=3;//using Com3
Settings:='9600, n, 8, 1;//set the communication port parameter
InputLen:=0;//set the Input at a time from the receive buffer to read all bytes
InBufferCount:=0;//remove accept buffer
OutBufferCount:=0;//remove the send buffer
InBufferSize:=512;//sets the send buffer to 2 bytes
RThreshold:= 11 ;//set to accept 11 bytes produces OnComm event
An InputMode:=ComInputModeText;//set to accept data model for binary way
PortOpen:=True;
end;
If MSComm1.Com mEvent=comEvReceive then//accept events //here is should use a loop to check
Sleep (20);
The begin
Buffer:=MSComm1. Input;//receive the data read
STemp:=buffer;
Edt26. Text:=stemp + ', ';
{
If label1. Caption='I' (00017, 1) THEN
The begin
Label2. Caption:='detected signal;
Label2. Color:=clyellow;
End
The else
The begin
Label2. Caption:='no signal was detected;
Label2. Color:=cllime;
end;
end;
}
end;

Trouble you can give the complete code, and explain the key part, thank you

CodePudding user response:

Don't understand as you describe, receiving data processing, is in accordance with the agreement,
Suggest using CPORT controls

CodePudding user response:

Don't see where is difficult, is not some basic string processing

CodePudding user response:

Data is normal ah, to segment the string,

CodePudding user response:

Your data to establish the Com data pool (buffer), in this way, you can capture the data regularly,

CodePudding user response:

I didn't say understand, each signal in the complete output is I (00001, 1) or I (00001, 0), on behalf of 001 receive or disconnected; Because in in milliseconds affection cases there will be several signals come in at the same time, each signal is 11 characters in length, if in 001 received or disconnect at the same time, the signal of 002 came in, so will cause the signal is not complete, such as: I (haven't got here at 00001, 1 (00002, 1) I also sent to the buffer format will be incomplete, normal is the I (00001, 1) I (00002, 1), I was (00001, i. (00002, 1), I changed the if pos (', 017, 1, label1. Caption), can be removed, but the effect is not ideal, to remove the address of the error is very big (address all correct,

CodePudding user response:

The details and the code is as follows:
With MSComm1 do
The begin
CommPort:=3;//using Com3
Settings:='9600, n, 8, 1;//set the communication port parameter
InputLen:=0;//set the Input at a time from the receive buffer to read all bytes
InBufferCount:=0;//remove accept buffer
OutBufferCount:=0;//remove the send buffer
InBufferSize:=512;//sets the send buffer to 2 bytes
RThreshold:=11;//set to accept 11 bytes produces OnComm event
An InputMode:=ComInputModeText;//set to accept data model for binary way
PortOpen:=True;
end;
end;

Procedure TForm1. Tmr2Timer (Sender: TObject);
The begin
Dengzt:=myini ReadString (' LIGHT ', 'LIGHT', ');
If dengzt='GREEN' then
The begin
If Pos (' 006, 0 'edt26. Text) & gt; 0 then
The begin
Readprocessmemory (jb, pointer ($7 f6b4064), @ cunfaz, SizeOf (cunfaz), shijiz);
Edt6. Text:=floattostr (integer (cunfaz)/1000);
Edt6. Color:=clYellow;
End
Else if Pos (', 006, 1 'edt26. Text) & gt; 0 then
The begin
Edt6. Color:=clBtnFace;
The end;
end;

end;

Procedure TForm1. Tmr3Timer (Sender: TObject);
The begin
Dengzt:=myini ReadString (' LIGHT ', 'LIGHT', ');
If dengzt='GREEN' then
The begin
If Pos (' 007, 0 'edt26. Text) & gt; 0 then
The begin
Readprocessmemory (jb, pointer ($7 f6b4064), @ cunfaz, SizeOf (cunfaz), shijiz);
Edt7. Text:=floattostr (integer (cunfaz)/1000);
Edt7. Color:=clYellow;
End
Else if Pos (', 007, 1 'edt26. Text) & gt; 0 then
The begin
Edt7. Color:=clBtnFace;
end;
end;
end;

Procedure TForm1. Tmr4Timer (Sender: TObject);
The begin
Dengzt:=myini ReadString (' LIGHT ', 'LIGHT', ');
If dengzt='GREEN' then
The begin
If Pos (' 008, 0 'edt26. Text) & gt; 0 then
The begin
Readprocessmemory (jb, pointer ($7 f6b4064), @ cunfaz, SizeOf (cunfaz), shijiz);
Edt8. Text:=floattostr (integer (cunfaz)/1000);
Edt8. Color:=clYellow;
End
Else if Pos (', 008, 1 'edt26. Text) & gt; 0 then
The begin
Edt8. Color:=clBtnFace;
end;
end;
end;

End.


  • Related