前段时间遇到一个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. EEPlat 的 后台业务处理模型

    后台处理包括数据处理.业务逻辑及业务流程等服务端操作的部分.相关的元模型包括业务对象元模型.业务对象属性元模型.服务元模型.參数元模型.业务规则元模型.工作流元模型.例如以下图所看到的:   业务对象 ...

  2. mysql myisam 锁表问题<转>

    转自http://yafei001.iteye.com/blog/1841258 锁是计算机协调多个进程或线程并发访问某一资源的机制 .在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用 ...

  3. java07循环结构

    public class WhileTest { // while循环结构 public static void main(String[] args) { System.out.println(&q ...

  4. spring03autowire属性

    1.创建需要的实体类 public class Student { //学生实体类 private String name; //姓名 private Integer age; //年龄 privat ...

  5. css08盒子模型

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. C#学习(三)

    通过类创建对象的过程称为类的实例化 匿名类型提供了一种方便的方法,可用来将一组只读属性封装到单个对象中,而无需首先显式定义一个类型. 要将匿名类型或包含匿名类型的集合作为参数传递给某一方法,可将参数作 ...

  7. Html.RenderPartial与Html.RenderAction区别(转)

    Html.RenderPartial与Html.RenderAction这两个方法都是用来在界面上嵌入用户控件的. Html.RenderPartial是直接将用户控件嵌入到界面上: <%Htm ...

  8. html行内元素 和 块状元素 总结

    块状元素 address - 地址blockquote - 块引用center - 举中对齐块dir - 目录列表div - 常用块级容易,也是CSS layout的主要标签dl - 定义列表fiel ...

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

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

  10. Undefined symbols for architecture x86_64:

    真机运行正常, 但要在模拟器运行的时候, 编译就报错了: 解决方法: 1.将Build Settings的Architectures修改为arm7 armv7s.Xcode7默认是加上arm64的,但 ...