前段时间遇到一个Mitsubish FX 3U PLC ,现将PLC连接单元分享一下,希望对其他人有所启示。

unit PLC_MitsubishiFX;

interface

uses
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 串口 连接单元的更多相关文章

  1. 西门子plc串口通讯方式

    西门子plc串口通讯的三种方式 时间:2015-10-25 14:31:55编辑:电工栏目:西门子plc 导读:西门子plc串口通讯的三种方式,分为RS485 串口通信.PPI 通信.MPI 通信,自 ...

  2. 三菱FX系列PLC教程

      标   题 日 期 点击 第一章:可编程控制器概论 2014-11-04 1401 1-0 课程概述 2014-11-05 192237 1-1 PLC的定义功能与特点 2014-11-05 16 ...

  3. WeinView 与 MITSUBISHI FX 系列 PLC 通讯范例

    1. 范例操作概述 此范例将介绍如何快捷简易地建立WEINVIEW HMI与MITSUBISHI FX系列 PLC通讯. 注意事项:通讯参数设置,通讯线接法. 2. 规划说明 (1) 新建简单 PLC ...

  4. PC软件与PLC串口通信 奇偶检验问题

    PC软件与PLC进行串口通信 波特率:19200 校验位:偶检验 数据位:8 停止位:1   现象 一,PC软件向PLC可以发送1,2,4,5,7,8,但是3,6,9发送出去后,PLC无法收到 二,使 ...

  5. C# SerialPort 读写三菱FX系列PLC

    1:串口初始化 com = , Parity.Even, , StopBits.One); 2:打开关闭串口 if (com.IsOpen) { com.Close();//关闭 } com.Open ...

  6. 三菱FX系列PLC学习

    1.PLC工作原理 PLC将程序存储在用户存储器当中, 驱动其运行, 相对比微型计算机软件, PLC程序则不同的是, 微型计算机整个流程则是从规定的开始 至结束完整工作流程.相对与PLC运行,则是从位 ...

  7. C#读写三菱Fx PLC 使用Fx 串口协议 读写Fx3U设备

    本文将使用一个Github开源的组件库技术来读写三菱 FX PLC,使用的是基于串口的实现,不需要额外的组件,读取操作只要放到后台线程就不会卡死线程,本组件支持超级方便的高性能读写操作 github地 ...

  8. stm32与三菱PLC通信

    一.三菱PLC通讯概要   三菱PLC FX系列通信结构如下图所示: 三菱PLC FX系列的通信规格如下图所示: 三菱PLC FX系列一般有以下几种通信模块,以FX2N为例: FX2N-232-BD ...

  9. 【转】常用PLC通讯协议

    三菱FX系列PLC通讯测试 发送帧(Hex): 起始(STX) 02 命令(CMD) 30 首地址(ADDRESS) 30 30 41 30 字节数(BYTES) 30 31 终止(ETX) 03 校 ...

随机推荐

  1. easyui 分页实现

    1.用datagrid 做分页显示, 依据API样例,最终解决.废话不说,datagrid分页 有一个附加的分页控件 通过在datagrid中设置pagination:true 就会显示分页 当请求是 ...

  2. ActiveX控件打包成Cab置于网页中自动下载安装(转载)

    原文出自http://www.iteye.com/topic/110834 [背景] 做过ActiveX控件的朋友都知道,要想把自己做的ActiveX控件功能放在自己的网页上使用,那么用户在客户端就必 ...

  3. mysql 变量is null 和 not exists区别

    问题: 使用游标遍历时,发现使用 select var into tmp where var=? 然后判断if tmp is null时,不能走完所有的遍历.经debug发现, 当var为空时,则跳出 ...

  4. Android android-common 常用功能和工具集合

    本文内容 环境 android-common 项目结构 演示 android-common 参考资料 android-common 主要包括如下内容: 缓存,包括图片缓存.预取缓存.网络缓存. 公共 ...

  5. Annotation注解

    概述 Annotation是JDK 5.0以后提供对元数据的支持,可以在编译.加载和运行时被读取,并执行相应的处理.所谓Annotation就是提供了一种为程序元素设置元数据的方法,可用于修饰包.类. ...

  6. ref传参时出错

    下面是一段正确的代码: //基类A public class A { public void SomeMethod(A a) { } } //派生类B public class B:A { } //在 ...

  7. char * 和 void *

    POSIX.1 将 read函数的原型做了修改,经典的定义为 int read(int filedes, char *buf, unsigned nbytes); 修改为 ssize_t read(i ...

  8. pl/sql的工具导入和代码导入

    工具导入:在导入的文件中添加导入工具.导入imp:F:\app\Administrator\product\11.1.0\db_1\BIN\imp.exe导出exp:F:\app\Administra ...

  9. ON DUPLICATE KEY UPDATE 当记录不存在时插入,当记录存在时更新

    MySQL 当记录不存在时插入,当记录存在时更新网上基本有三种解决方法.第一种:示例一:插入多条记录假设有一个主键为 client_id 的 clients 表,可以使用下面的语句:INSERTINT ...

  10. 原生js实现的放大镜效果

    这是我用原生js写的放大镜效果,与各种各样的框架技术相比,我喜欢使用原生的js,在这里,想和大家一起谈谈原生和框架技术的理解与个人喜好. <!DOCTYPE HTML><html&g ...