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 校 ...
随机推荐
- apache 配置https(转)
主要讲述在windows下apache配置SSL以实现http转换为https SSL: SSl是为Http传输提供安全的协议,通过证书认证来确保客户端和网站服务器之间的数据是安全.也就是说在SSL下 ...
- hdu 4772
题意:给你两个矩阵,一个矩阵旋转90度,180度,270度, 然后和另外一个矩阵进行比较,如果对应值相同,则加一,最后得出最大的值 题目没什么难度....主要是纪念下....貌似这一题是当时比赛前一个 ...
- asp.net微信开发第七篇----高级群发(图文)
上一篇介绍了如何群发文本消息,本篇将介绍如何群发图文信息,上传图文信息所需的素材,界面如下: 我们先看从素材库中获取图文素材的代码,界面: 素材列表,我是使用的repeater控件, 前台代码如下: ...
- 《CSS网站布局实录》学习笔记(二)
第二章 XHTML与CSS基础 2.1 XHTML基础 XHTML是网页代码的核心内容,标准XHTML代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD ...
- Android Studio 实用快捷键
ctrl + alt + 方向键 跳转到上次或下次编辑位置 ctrl + alt +n 查找文件 shift + f6 重构之重命名 ctrl + f12 导航到类方法 ...
- Sql server Compact 小型数据库损坏修复
之前碰到过小型数据库损坏打不开的问题,一直没有理会,今天生产上客户本地小库产生这样的问题,已经修复 SqlCeEngine engine = new SqlCeEngine(" ...
- PHP set_error_handler() 函数
定义和用法 set_error_handler() 函数设置用户自定义的错误处理函数. 该函数用于创建运行时期间的用户自己的错误处理方法. 该函数会返回旧的错误处理程序,若失败,则返回 null. 语 ...
- Eclipse读取xml中文乱码问题解决
解决eclipse读取xml时中文乱码报错问题 在eclipse.ini中加入下而一行 -Dfile.encoding=UTF-8
- 《Linux内核分析》 week4作业-使用嵌入式汇编调用一个系统调用
一.fork的嵌入式汇编执行 #include <stdio.h> #include <unistd.h> int main(){ pid_t pid; asm volatil ...
- 利用谷歌 kaptcha 进行验证码生成
package main.com.smart.controller; import com.google.code.kaptcha.Producer; import main.com.smart.ut ...