J
junye--li
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是我的程序变频器通讯控制问题)
出现的问题是:每发送信号,速率可以设定,正转一下,马上停止,报警,也未出现反馈信息.我现在找不出是那设置出错了,请大家帮忙找找原因,谢谢!
双击MSCOMM控件图标,其属性设置为(程序中也有设定,不知和这些属性有关没?):
general项中handshaking设置为0-comNone
Buffers项中InbufferSize设置为1024 ,OutBuffersize设置为 512
RThreshold设置为0,SThreshold设置为0, InputLen设置为0, EOFEnable复选框未选择
Hardware项中 PairityReplace设置?(系统设置)
NullDiscard未选 RTSEable选 DTREable选
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, OleCtrls, MSCommLib_TLB;
type
TForm1 = class(TForm)
MSCommain: TMSComm;
SpeedButton1: TSpeedButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Memo2: TMemo;
Edit2: TEdit;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure MSCommainComm(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mscommain.CommPort:=1;
mscommain.InBufferSize:=1024;
mscommain.OutBufferSize:=512;
mscommain.Settings:='19200,n,8,1';
mscommain.InBufferCount:=0;
mscommain.RThreshold:=1;
mscommain.InputLen:=0;
mscommain.DTREnable:=false;
mscommain.RTSEnable:=false;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
writestr,s,t,a1,a2:string;
temp1:integer;
begin
if not mscommain.PortOpen then
mscommain.PortOpen:=true;
mscommain.InBufferCount:=0;
mscommain.InputLen:=0;
mscommain.RThreshold:=1;
mscommain.DTREnable:=true;
mscommain.RTSEnable:=true;
mscommain.Output:=chr(5)+'00FB10002DB';//(设定通讯操作)
sleep(300);
mscommain.Output:=chr(5)+'00EE103E8FB';//设定速率
sleep(300);
mscommain.Output:=chr(5)+'00FA1027A';//设定正转
sleep(500);
end;
procedure TForm1.MSCommainComm(Sender: TObject);
var
recstr,I : Variant;
cc,pd : string ;
begin
if Mscommain.CommEvent = 2 then
begin
I:=MSCommain.InBufferCount;
MSCommain.InputLen:=I;
recstr := Mscommain.Input ;
Memo2.text := Memo2.Text+recstr;
cc := string(recstr);
Memo2.Lines.Add('MSCOMM is ok');
Memo2.Lines.Add(recstr);
pd:=copy(recstr,1,3);
sleep(100);
end;
if pd=chr(6)+'00' then
showmessage('写入数据正确!')
else
begin
if pd=chr(15)+'00'+'0' then
showmessage('计算机NAK错误:从计算机发送的通讯请求数据被检测到的连续错误次数超过规定的允许再试次数!');
if pd=chr(15)+'00'+'1' then
showmessage('奇偶校验错误:奇偶校验结果与规定的奇偶校验不相符!');
if pd=chr(15)+'00'+'2' then
showmessage('总和校验错误:计算机中的总和校验代码与变频器接收的数据不相符!');
if pd=chr(15)+'00'+'3' then
showmessage('协议错误:变频器接收的数据有文法错误,或在规定的时间内未完成数据通信,CR、LF没有按照参数的设定!');
if pd=chr(15)+'00'+'4' then
showmessage('格式错误:停止位长不符和规定!');
if pd=chr(15)+'00'+'5' then
showmessage('溢出错误:变频器完成前面的数据接收之前,从计算机又发送了新的数据!');
if pd=chr(15)+'00'+'7' then
showmessage('字符错误:接收的字符无效(在0~9、A~F的控制代码以外)!');
if pd=chr(15)+'00'+'A' then
showmessage('模式错误;试图写入的参数在计算机通讯操作模式以外或变频器在运行中!');
if pd=chr(15)+'00'+'B' then
showmessage('指令代码错误:规定的指令不存在!');
if pd=chr(15)+'00'+'C' then
showmessage('数据范围错误;规定了无效的数据用于参数写入、频率设定等!');
end;
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
memo1.Lines.Clear;
memo2.Lines.Clear;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
close;
end;
end.
出现的问题是:每发送信号,速率可以设定,正转一下,马上停止,报警,也未出现反馈信息.我现在找不出是那设置出错了,请大家帮忙找找原因,谢谢!
双击MSCOMM控件图标,其属性设置为(程序中也有设定,不知和这些属性有关没?):
general项中handshaking设置为0-comNone
Buffers项中InbufferSize设置为1024 ,OutBuffersize设置为 512
RThreshold设置为0,SThreshold设置为0, InputLen设置为0, EOFEnable复选框未选择
Hardware项中 PairityReplace设置?(系统设置)
NullDiscard未选 RTSEable选 DTREable选
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, OleCtrls, MSCommLib_TLB;
type
TForm1 = class(TForm)
MSCommain: TMSComm;
SpeedButton1: TSpeedButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Memo2: TMemo;
Edit2: TEdit;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure MSCommainComm(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mscommain.CommPort:=1;
mscommain.InBufferSize:=1024;
mscommain.OutBufferSize:=512;
mscommain.Settings:='19200,n,8,1';
mscommain.InBufferCount:=0;
mscommain.RThreshold:=1;
mscommain.InputLen:=0;
mscommain.DTREnable:=false;
mscommain.RTSEnable:=false;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
writestr,s,t,a1,a2:string;
temp1:integer;
begin
if not mscommain.PortOpen then
mscommain.PortOpen:=true;
mscommain.InBufferCount:=0;
mscommain.InputLen:=0;
mscommain.RThreshold:=1;
mscommain.DTREnable:=true;
mscommain.RTSEnable:=true;
mscommain.Output:=chr(5)+'00FB10002DB';//(设定通讯操作)
sleep(300);
mscommain.Output:=chr(5)+'00EE103E8FB';//设定速率
sleep(300);
mscommain.Output:=chr(5)+'00FA1027A';//设定正转
sleep(500);
end;
procedure TForm1.MSCommainComm(Sender: TObject);
var
recstr,I : Variant;
cc,pd : string ;
begin
if Mscommain.CommEvent = 2 then
begin
I:=MSCommain.InBufferCount;
MSCommain.InputLen:=I;
recstr := Mscommain.Input ;
Memo2.text := Memo2.Text+recstr;
cc := string(recstr);
Memo2.Lines.Add('MSCOMM is ok');
Memo2.Lines.Add(recstr);
pd:=copy(recstr,1,3);
sleep(100);
end;
if pd=chr(6)+'00' then
showmessage('写入数据正确!')
else
begin
if pd=chr(15)+'00'+'0' then
showmessage('计算机NAK错误:从计算机发送的通讯请求数据被检测到的连续错误次数超过规定的允许再试次数!');
if pd=chr(15)+'00'+'1' then
showmessage('奇偶校验错误:奇偶校验结果与规定的奇偶校验不相符!');
if pd=chr(15)+'00'+'2' then
showmessage('总和校验错误:计算机中的总和校验代码与变频器接收的数据不相符!');
if pd=chr(15)+'00'+'3' then
showmessage('协议错误:变频器接收的数据有文法错误,或在规定的时间内未完成数据通信,CR、LF没有按照参数的设定!');
if pd=chr(15)+'00'+'4' then
showmessage('格式错误:停止位长不符和规定!');
if pd=chr(15)+'00'+'5' then
showmessage('溢出错误:变频器完成前面的数据接收之前,从计算机又发送了新的数据!');
if pd=chr(15)+'00'+'7' then
showmessage('字符错误:接收的字符无效(在0~9、A~F的控制代码以外)!');
if pd=chr(15)+'00'+'A' then
showmessage('模式错误;试图写入的参数在计算机通讯操作模式以外或变频器在运行中!');
if pd=chr(15)+'00'+'B' then
showmessage('指令代码错误:规定的指令不存在!');
if pd=chr(15)+'00'+'C' then
showmessage('数据范围错误;规定了无效的数据用于参数写入、频率设定等!');
end;
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
memo1.Lines.Clear;
memo2.Lines.Clear;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
close;
end;
end.