上传者: hwy2000
|
上传时间: 2021-11-29 14:27:45
|
文件大小: 657KB
|
文件类型: -
delphi串口读写台达plc PLC台达DELPHI通讯MODBUS
procedure TfrmMain.btnReadMClick(Sender: TObject);
var
sStr:String;
i:Integer;
begin
for i:= 0 to 1279 do
Begin
kmtPLC.SendData('0102'+IntToHex(i+$800,4)+'0001'); //取输出状态
sStr:=kmtPLC.ReadResFromPort();
if sStr'' then
Begin
memo1.Lines.Add('M'+IntToHex(i,4)+'-'+FormatFloat('0000',i)+'-'+Copy(sStr,1,Length(sStr)-2));
End;
End;
end;
procedure TfrmMain.SpeedButton4Click(Sender: TObject);
var
sStr:String;
begin
kmtPLC.SendData('0103'+IntToHex(StrToInt(edtDAddr.Text)+$1000,4)+'0001');
sStr:=kmtPLC.ReadResFromPort();
if sStr'' then
Begin
edtDValue.Text:=sStr;
End;
end;