Mitsubish FX 3U PLC 串口 连接单元
来源:互联网 发布:珠江水质监测数据 编辑:程序博客网 时间:2024/06/05 22:52
前段时间遇到一个Mitsubish FX 3U PLC ,现将PLC连接单元分享一下,希望对其他人有所启示。
unit PLC_MitsubishiFX;interfaceuses Windows, Messages, SysUtils, Classes, syncobjs,UnitCom, ACTPCCOMLib_TLB, PLC_Base, PLCCommonFunc;type TPLC_MitsubishiFX=class(TPLC) private FMyCom:TActFXCPU;{定义串口通信对象} public ConStructor Create; override; {构造函数} destructor Destroy; override; {析构函数} function Open(ComName,IpAddress: string):Integer;override;{打开PLC} function Close:Integer;override; {关闭PLC} //读PLC函数 function DoRead(Station:Integer; StartAddress:Integer; Count:Integer; Buffer:Pointer; DataType:array of TPLCDataType): Integer;override; //写PLC函数 function DoWrite(Station:Integer; StartAddress:Integer; Count:Integer; Buffer:Pointer; DataType: TPLCDataType):Integer;override;{返回值为写入成功与否}end;implementation{ TPLC_Mitsubishi }constructor TPLC_MitsubishiFX.Create;begin Inherited; FMyCom:=TActFXCPU.Create(nil); {创建串口通信对象} FMyCom.ActTimeOut:=10000;end;destructor TPLC_MitsubishiFX.Destroy;begin FMyCom.Free ;{释放串口通信对象} inherited;end;function TPLC_MitsubishiFX.Open(ComName,IpAddress: string): Integer;begin FMyCom.ActPortNumber :=strtoint(copy(comname,4,length(comname)-3)); //com1 Result:=FMyCom.Open; //该函数返回0为成功 if Result = 0 then Result := SUCCESS;end;function TPLC_MitsubishiFX.Close: Integer;begin Result := FMyCom.Close;{关闭串口通信对象} if Result = 0 then Result := SUCCESS;end;function TPLC_MitsubishiFX.DoRead(Station:Integer; StartAddress:Integer; Count:Integer; Buffer:Pointer; DataType:array of TPLCDataType): Integer;var DataInfo:TPLCStruct; //接收从Buffer传来的参数 lpdata: array[0..99] of integer; i:integer; LState:integer;begin DataInfo := PTPLCStruct(Buffer)^; try LState:=FMyCom.ReadDeviceBlock('D'+ConvertStartAddr(StartAddress),Count,lpdata[0]) ; except LState:=-1; end; FLinkState := LState =0; if LState<>0 then //读取失败的情况 begin Result:=UNSUCCESS; exit; end; for i:=0 to Count-1 do begin DataInfo.PLCInteger[i]:=lpdata[i]; end; PTPLCStruct(Buffer)^:=DataInfo; //传出读取的PLC数据 Result:=SUCCESS;end;function TPLC_MitsubishiFX.DoWrite(Station:Integer; StartAddress:Integer; Count:Integer; Buffer:Pointer; DataType: TPLCDataType): Integer;var DataInfo:TPLCStruct; //接收从Buffer传来的参数 LDataInfo :array[0..100] of integer; i:integer; LState:integer;begin DataInfo := PTPLCStruct(Buffer)^;// if DataType = dtHexInt then// for i:=0 to Count - 1 do// LDataInfo[i]:=StrToint('$'+DataInfo.PLCChar[i]) //十六进制// else for i:=0 to Count - 1 do LDataInfo[i]:=DataInfo.PLCInteger[i]; //十进制 try LState:=FMyCom.WriteDeviceBlock('D'+ConvertStartAddr(StartAddress),Count,LDataInfo[0]) ; except LState:=-1; end; FLinkState := LState = 0; if LState = 0 then result:= SUCCESS else result:=UNSUCCESS;end;end.
- Mitsubish FX 3U PLC 串口 连接单元
- FX-3U PLC串口与PC通信调试
- C# SerialPort 读写三菱FX系列PLC
- C# SerialPort 读写三菱FX系列PLC
- 三菱FX 系列PLC 编程通信协议总览
- C# SerialPort 读写三菱FX系列PLC
- 三菱FX系列PLC的modbusTCP通讯
- 西门子PLC串口使用
- PLC-串口通信实例
- 三菱PLC FX系列编程口通信的若干问题
- 三菱FX系列PLC编程口通信协议总览
- 三菱FX系列PLC编程口通信协议举例
- 三菱FX系列PLC编程口通信协议举例
- 三菱Fx系列PLC的编程口协议
- PLC编程端口以及 FX-232AW 模块的通信
- 三菱FX系列PLC编程口通信协议举例
- 三菱FX系列PLC编程口通信协议总览
- 三菱FX系列PLC编程口通信协议举例
- Android图形显示之硬件抽象层Gralloc
- 日志文件夹写满导致网站速度慢
- Win32函数传参传址传引用详解
- 5大内存区域
- 获取 yyyy-mm-dd 格式的 Date 时间类型
- Mitsubish FX 3U PLC 串口 连接单元
- HTTP协议下flowplayer任意拖动播放的实现
- CAP Confusion: Problems with ‘partition tolerance’
- PeoPle类
- Java对象初始化详解
- iOS后台定位实现
- Java序列化与反序列化(实践)
- MFC程序显示cannot open file ".\Debug\E0301.res" 无法打开资源文件
- 矩阵链乘法 算法导论