Mitsubish FX 3U PLC 串口 连接单元
前段时间遇到一个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 串口 连接单元的更多相关文章
- 西门子plc串口通讯方式
西门子plc串口通讯的三种方式 时间:2015-10-25 14:31:55编辑:电工栏目:西门子plc 导读:西门子plc串口通讯的三种方式,分为RS485 串口通信.PPI 通信.MPI 通信,自 ...
- 三菱FX系列PLC教程
标 题 日 期 点击 第一章:可编程控制器概论 2014-11-04 1401 1-0 课程概述 2014-11-05 192237 1-1 PLC的定义功能与特点 2014-11-05 16 ...
- WeinView 与 MITSUBISHI FX 系列 PLC 通讯范例
1. 范例操作概述 此范例将介绍如何快捷简易地建立WEINVIEW HMI与MITSUBISHI FX系列 PLC通讯. 注意事项:通讯参数设置,通讯线接法. 2. 规划说明 (1) 新建简单 PLC ...
- PC软件与PLC串口通信 奇偶检验问题
PC软件与PLC进行串口通信 波特率:19200 校验位:偶检验 数据位:8 停止位:1 现象 一,PC软件向PLC可以发送1,2,4,5,7,8,但是3,6,9发送出去后,PLC无法收到 二,使 ...
- C# SerialPort 读写三菱FX系列PLC
1:串口初始化 com = , Parity.Even, , StopBits.One); 2:打开关闭串口 if (com.IsOpen) { com.Close();//关闭 } com.Open ...
- 三菱FX系列PLC学习
1.PLC工作原理 PLC将程序存储在用户存储器当中, 驱动其运行, 相对比微型计算机软件, PLC程序则不同的是, 微型计算机整个流程则是从规定的开始 至结束完整工作流程.相对与PLC运行,则是从位 ...
- C#读写三菱Fx PLC 使用Fx 串口协议 读写Fx3U设备
本文将使用一个Github开源的组件库技术来读写三菱 FX PLC,使用的是基于串口的实现,不需要额外的组件,读取操作只要放到后台线程就不会卡死线程,本组件支持超级方便的高性能读写操作 github地 ...
- stm32与三菱PLC通信
一.三菱PLC通讯概要 三菱PLC FX系列通信结构如下图所示: 三菱PLC FX系列的通信规格如下图所示: 三菱PLC FX系列一般有以下几种通信模块,以FX2N为例: FX2N-232-BD ...
- 【转】常用PLC通讯协议
三菱FX系列PLC通讯测试 发送帧(Hex): 起始(STX) 02 命令(CMD) 30 首地址(ADDRESS) 30 30 41 30 字节数(BYTES) 30 31 终止(ETX) 03 校 ...
随机推荐
- Android AIDL图解
代码来自:http://www.cnblogs.com/mandroid/archive/2011/02/26/1965428.html (XXX.AIDL自动生成的IXXX.java类中 ...
- Ubuntu启动时直接进入命令行模式
直接粘命令吧 sudo vim /etc/init/lightdm.conf 注释掉下面的内容 start on ((filesystem and runlevel [!06] and started ...
- 比较好的总结runtime
http://www.cocoachina.com/ios/20160128/15154.html
- WebStorm修改默认快捷键
打开 "File" -> "Setting" -> "keymap",即可修改.
- BIND9详解之日志篇
在默认情况下,BIND把日志消息写到/var/log/messages文件中,而这些日志消息是非常少的,主要就是启动,关闭的日志记录和一些严重错误的消息,所以要详细记录服务器的运行状况,需要自己配置服 ...
- mac brew 安装包下载失败解决
1.FQ或者用别的方式把安装包下载下来 2.查看缓存存储目录 brew --cache 3.将下载的包拷贝到缓存目录中,再此执行安装命令,如果安装还是去下载,检查下缓存目录是否多出一个下载中的文件,将 ...
- java 使用正则表达式对文件名非法字符处理
1.文件名在操作系统中不允许出现 / \ " : | * ? < > 故将其以空替代 Pattern pattern = Pattern.compile(" ...
- Div在BOdy中居中
<h1 style="position: absolute; width: 500px; height:200px; left:%; top:%; margin-left:-250px ...
- WebSQL实例记录
<table id="content"> </table> <br> <input type="button" id= ...
- PHP文章管理(2)
##############index.php###################### <?session_start(); require"./inc/func.php&qu ...