Home > Back-end >  DELPHI control SPCOMM to a serial port to send data failed
DELPHI control SPCOMM to a serial port to send data failed

Time:09-17

Procedure TfrmMain. StratClick (Sender: TObject);
Var
Viewstring: string;
I: integer;
Commflg: Boolean;
Rbuf, sbuf: an array of byte [0.. 1];

//rbuf, sbuf: an array of byte=[0.. 12] ($10, $12, $12, $65, $63, $74, $42, at $61, $6 e, $60 and $25 and $14, $85);
The begin
/////////////////////////
If Edit22. Text="' then
='COM4 frmMain.Comm2.Com mName:'
The else
FrmMain.Comm2.Com mName:=Edit22. Text;
FrmMain.Com m2. BaudRate:=9600;
FrmMain.Com m2. ParityCheck:=false;//parity
FrmMain.Com m2. ByteSize:=_8;
FrmMain.Com m2. Parity:=Even;
FrmMain.COM M2. StopBits:=_1;
//Comm2. SendDataEmpty:=True;
FrmMain.Com m2. StopComm;
FrmMain.Com m2. StartComm;
///////////////////////////////

Viewstring:=';
Commflg:=true;

Sbuf [0] :=1;//boot

If not frmMain.com m2. Writecommdata (@ sbuf [0], 1) then
The begin
//Label4. Caption:=GetLastError;
Commflg:=false;
Label4. Caption:='startup information sent 2 error;
End
The else
The begin
Label4. Caption:='send 2 successful startup information;
The end;
Edit10. SetFocus;
Comm2. StopComm;

CodePudding user response:

Texting, two kinds of modes:
It is need special module, a similar phone module, text messages,
Second, through a dedicated web site, send text messages,

Purchasing mobile simulation, a Demo and Dll,

CodePudding user response:

FrmMain.Com m2. BaudRate:=9600;
FrmMain.Com m2. ParityCheck:=false;//parity
FrmMain.Com m2. ByteSize:=_8;
FrmMain.Com m2. Parity:=Even;
FrmMain.COM M2. StopBits:=_1;

This several Settings you need to pay attention to, you can use the tool to test parameters are correct, such as baud rate 9600 is correct,

CodePudding user response:

Writecommdata baud rate, the success of this function and it doesn't matter,
The if not frmMain.com m2. Writecommdata (@ sbuf [0], 1) then changed to
If not frmMain.com m2. Writecommdata (@ sbuf, 1) then
Have a try,

CodePudding user response:

Supplement: I share "weighing instrument data analytical control code" involves a large number of serial port operations,

CodePudding user response:

You need to provide you with SPCOMM and Delphi version, different versions, the use of the function writecommdata existence difference, in particular the Delphi XE version later,

CodePudding user response:

If not frmMain.com m2. Writecommdata (sbuf [0], 1), then try this

CodePudding user response:

Isn't close a serial port too early, data has not been sent out,
  • Related