J
jinms
Unregistered / Unconfirmed
GUEST, unregistred user!
我使用SPCOMM控件连接汇邦的转速表,发送完读测量值的数据后,没有返回值,
转速表连在我机器的COM1口上;
我用我的发送程序发送数据,没问题,COM1发的数据,COM2用超级终端显示都能正确收到;
其中读测量值的数据格式和转速表返回的数据格式如下:
主方发送帧格式信息如下:
地址 代码 地址 字数 CRC16
01 03 高位 低位 高位 低位 高位 低位
00 04 00 03 40 CA
------------------------------------------------------------------------------
从方应答发送帧格式信息如下:
地址 代码 数据字节长度 数据 CRC16
01 03 06 00 03 0D 41 00 02 79 84
-------------------------------------------------------------------------------
各位大侠帮我看看问题可能出在哪里,代码如下:
-------------------------------------------------------------------------------
unit Unt_send;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SPComm, StdCtrls, Buttons, ExtCtrls, CPort;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Timer1: TTimer;
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
BitBtn2: TBitBtn;
Edit3: TEdit;
Label1: TLabel;
Edit4: TEdit;
Label2: TLabel;
Edit5: TEdit;
Label3: TLabel;
CheckBox1: TCheckBox;
Edit6: TEdit;
Label4: TLabel;
Comm1: TComm;
ComPort1: TComPort;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Comm1.StartComm;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
tmpStr :string;
fg :Boolean;
begin
if BitBtn1.Caption='发送数据'then
begin
BitBtn1.Caption :='停止';
tmpStr :='010300040003';
Comm1.WriteCommData(pchar(tmpStr) , length(tmpStr));
end
else begin
BitBtn1.Caption :='发送数据';
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Comm1.StopComm;
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
tmpStr :string;
begin
SetLength(tmpStr , BufferLength);
Move(Buffer^,Pchar(tmpStr)^,BufferLength);
memo1.Lines.Add(tmpStr);
end;
end.
转速表连在我机器的COM1口上;
我用我的发送程序发送数据,没问题,COM1发的数据,COM2用超级终端显示都能正确收到;
其中读测量值的数据格式和转速表返回的数据格式如下:
主方发送帧格式信息如下:
地址 代码 地址 字数 CRC16
01 03 高位 低位 高位 低位 高位 低位
00 04 00 03 40 CA
------------------------------------------------------------------------------
从方应答发送帧格式信息如下:
地址 代码 数据字节长度 数据 CRC16
01 03 06 00 03 0D 41 00 02 79 84
-------------------------------------------------------------------------------
各位大侠帮我看看问题可能出在哪里,代码如下:
-------------------------------------------------------------------------------
unit Unt_send;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SPComm, StdCtrls, Buttons, ExtCtrls, CPort;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Timer1: TTimer;
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
BitBtn2: TBitBtn;
Edit3: TEdit;
Label1: TLabel;
Edit4: TEdit;
Label2: TLabel;
Edit5: TEdit;
Label3: TLabel;
CheckBox1: TCheckBox;
Edit6: TEdit;
Label4: TLabel;
Comm1: TComm;
ComPort1: TComPort;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Comm1.StartComm;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
tmpStr :string;
fg :Boolean;
begin
if BitBtn1.Caption='发送数据'then
begin
BitBtn1.Caption :='停止';
tmpStr :='010300040003';
Comm1.WriteCommData(pchar(tmpStr) , length(tmpStr));
end
else begin
BitBtn1.Caption :='发送数据';
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Comm1.StopComm;
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
tmpStr :string;
begin
SetLength(tmpStr , BufferLength);
Move(Buffer^,Pchar(tmpStr)^,BufferLength);
memo1.Lines.Add(tmpStr);
end;
end.