Home > Back-end >  DELPHI XE 10.4 serial port communication, cannot send data
DELPHI XE 10.4 serial port communication, cannot send data

Time:03-15

Excuse me each great god, DELPHI XE 10.4 serial communication control?
Can I use SPCOMM 3.1, a serial port receives the data, but can not send data, send back to normal, not an error, is not to send data,
Sending code:
S: AnsiString.
S:=mmoSend. Text;
FComm. WriteCommData (@ S [1], length (S));
SPCOMM control implementation:
The function TComm. WriteCommData (pDataToWrite: PChar; DwSizeofDataToWrite: Word) : Boolean;
Var
Buffer: Pointer;
The begin
If (WriteThread & lt;> Nil) and (dwSizeofDataToWrite & lt;> 0) then
The begin
Buffer:=Pointer (LocalAlloc (LPTR, dwSizeofDataToWrite + 1));
, Buffer Move (pDataToWrite ^ ^, dwSizeofDataToWrite);
FSendDataEmpty:=False;
If PostThreadMessage (WriteThread. ThreadID, PWM_COMMWRITE,
WPARAM (dwSizeofDataToWrite), LPARAM (Buffer)) then
The begin
Result:=True;
The Exit
End
end;

Result:=False
end;

CodePudding user response:

Not in the post box?

The function TComm. WriteCommData (pDataToWrite: PChar; DwSizeofDataToWrite: Word) : Boolean;
This parameter is Pchar, AnsiSting, you send the wrong

S: AnsiString.="S: a String;

CodePudding user response:

FComm. WriteCommData (@ S [1], length (S));
Don't write, direct PChar (S).

CodePudding user response:

Still can't send data:
Try this way below:
Var
S: a string;
Call:
FComm. WriteCommData (PChar (S), length (S));
Don't complain, but not sending data,
Also try:
Var
P: pchar;
P:='ABC';
FComm. WriteCommData (P, length (P));
Also is not an error, but not to send data,
  • Related