温控器Modbus协议通讯设计样例更新
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
DELPHI SPCOMM温控器Modbus协议通讯设计
——QQ:64782489陈建光unit Unit1;
----
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SPComm, ExtCtrls,StrUtils;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ComboBox1: TComboBox;
Label2: TLabel;
GroupBox1: TGroupBox;
Label3: TLabel;
ComboBox2: TComboBox;
Memo2: TMemo;
GroupBox2: TGroupBox;
Button4: TButton;
Button5: TButton;
Label5: TLabel;
Button6: TButton;
Label1: TLabel;
Label6: TLabel;
Label4: TLabel;
Label7: TLabel;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
ComboBox5: TComboBox;
Comm1: TComm;
GroupBox3: TGroupBox;
Panel1: TPanel;
Panel2: TPanel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label15: TLabel;
Panel3: TPanel;
Panel4: TPanel;
Button7: TButton;
Button9: TButton;
Button10: TButton;
Timer1: TTimer;
Label14: TLabel;
Panel5: TPanel;
Label16: TLabel;
Edit1: TEdit;
Label17: TLabel;
Edit2: TEdit;
Label18: TLabel;
Edit3: TEdit;
Label19: TLabel;
Edit4: TEdit;
Edit5: TEdit;
Label20: TLabel;
Label21: TLabel;
Edit6: TEdit;
Button8: TButton;
Label22: TLabel;
Edit7: TEdit;
Button12: TButton;
Edit8: TEdit;
Label23: TLabel;
Edit9: TEdit;
Label25: TLabel;
Panel6: TPanel;
Edit10: TEdit;
Label24: TLabel;
Edit11: TEdit;
Label26: TLabel;
Label27: TLabel;
Button11: TButton;
Button13: TButton;
Timer2: TTimer;
procedure SetComPort();
----
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Word);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
----
procedure Timer1Timer(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
//function CalCRC16(AData:array of Byte;AStart,AEnd:Integer):Word;
//function returnCRC16(vStr1:String):String;
private
{ Private declarations }
public
{ Public declarations }
end;
----
var
Form1: TForm1;
viewstring:string; //定义全局字符串
rbuf,sbuf:array of byte; //定义全局可变字节数组
Cur_Qry_Str: array[1..32] of string; //当前查询字符串
Btn_Qry_Str,Tmr_Qry_Str:array[1..32] of string; //按钮、定时器返回字符串数组
Btn_Rtn_Str,Tmr_Rtn_Str:array[1..32] of string; //按钮、定时器返回字符串数组
cur_wd,Cur_wd_p,set_wd,Cur_Mode,Open_sta:array[1..32] of integer; //设置当前温度、设置温度、开关状态数组
implementation
{$R *.dfm}
//=============此处用于自动获取系统的串口数目以及名称,调用api函数实现相关功能=====================
procedure EnumComPorts(Ports: TStrings);
var