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 校 ...
随机推荐
- mysql 修复表和优化表
REPAIR TABLE `table_name` 修复表 OPTIMIZE TABLE `table_name` 优化表
- [转] GMT、UTC与24时区 等时间概念
许多人都知道两地时间表简称为GMT或UTC,而世界时区表则通称为World Time,那么GMT与UTC的实质原意又是为何?世界时区又是怎么区分的?面盘上密密麻麻的英文单字代表着什么意义与作用呢?这些 ...
- git 更换远程仓库地址
1. 更改软件仓库指向.在github改了用户名和仓库名称后,仓库地址也相应的发生的变化,这时候就需要更新本地仓库以指向新的远程仓库地址: $git remote set-url origin git ...
- /etc/motd and /etc/issue
/etc/motd and /etc/issue Bash offers an option to include messages in the /etc/motd and the /etc/iss ...
- Ubuntu 14.04 配置vsftpd实现FTP服务器 - 通过FTP连接AWS
测试主机:亚马逊AWS EC2 系统:Ubuntu 14.04 想用AWS来做服务器玩,结果发现其不能像简单使用阿里云服务器那样用ftp连接,反正也不熟悉ftp服务器搭建,那就乘这个机会学习一下如何利 ...
- 用C#实现的条形码和二维码编码解码器
本文主要介绍可以在C#中使用的1D/2D编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码:二维码也开始应用到很多场合,如火车票有二维码识别.网易的首页有二维码图标,用户只需 ...
- PHP Calendar 函数
PHP 5 Calendar 函数 函数 描述 cal_days_in_month() 针对指定的年份和历法,返回一个月中的天数. cal_from_jd() 把儒略日计数转换为指定历法的日期. ca ...
- mssql 查询全部用户创建表 条数及占用空间大小(KB)
select b.name as tablename , --表名a.rowcnt as datacount, --条数rtrim(8*a.dpages) as size --占用空间单位KBf ...
- Js参数RSA加密传输,jsencrypt.js的使用
注意几点: 1.参数传递的+号处理,在传输时会把+变成空格,不处理后端就报错了. 1.前段代码 <!DOCTYPE html> <html> <head> < ...
- uva 482 - Permutation Arrays
<int, double> --> <int, string> 从而避免了输出格式: #include <vector> #include <strin ...