# 欧姆龙Fins通讯 **Repository Path**: C_Li/OmronHelper ## Basic Information - **Project Name**: 欧姆龙Fins通讯 - **Description**: 把基础的FINS读写命令封装成了一个dll - **Primary Language**: C# - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 15 - **Forks**: 14 - **Created**: 2019-11-06 - **Last Updated**: 2024-11-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OmronLib.dll说明 DataTools.cs 数据处理工具类 Omron.cs 欧姆龙通讯类 ## DataTools.cs * ByteToHexString() 将byte数组转化成16进制字符串形式 * StrToStrArray() 将字符串两个两个分割成数组 ## Omron.cs * AreaType 枚举,PLC内存地址类型 * CIO_Bit = 0x30 * WR_Bit = 0x31 * HR_Bit = 0x32 * AR_Bit = 0x33 * DM_Bit = 0x02 * CIO_Word = 0xB0 * WR_Word = 0xB1 * HR_Word = 0xB2 * AR_Word = 0xB3 * DM_Word = 0x82 ### 属性 * IPAddr PLC IP地址 * Port PLC 端口 * IsConnected 返回PLC连接状态 ### 方法 * PLCConnect() 连接PLC * DisConnect() 断开连接 * bool Read(AreaType type, int startword, int startbit, int count, out string[] result) *通用方法* 读PLC(字或者位) * type 地址类型 * startword 开始字地址 * startbit 开始位地址 * count 读取长度 * result 读取结果 * bool WriteBits(AreaType type, int startword, int startbit, int count, bool[] paras) *通用方法* 写PLC位 * type 地址类型 * startword 开始字地址 * startbit 开始位地址 * count 写入长度 * paras 写入内容 * bool WriteWords(AreaType type, int startword, int count, int[] paras) *通用方法* 写PLC字 * type 地址类型 * startword 开始字地址 * count 写入长度 * paras 写入内容 * bool ReadDBits(int startword, int startbit, int count, out string[] result) 读DM位 * startword 开始字地址 * startbit 开始位地址 * count 读取长度 * result 读取结果 * bool ReadDWords(int startword, int count, out string[] result) 读DM字 * startword 开始字地址 * count 读取长度 * result 读取结果 * bool WriteDBits(int startword, int startbit, int count, bool[] paras) 写DM位 * startword 开始字地址 * startbit 开始位地址 * count 写入长度 * paras 写入内容 * bool WriteDWords(int startword, int count, int[] paras) 写DM字 * startword 开始字地址 * count 写入长度 * paras 写入内容 # Omron FINS 协议简介 FINS (Factory Interface Network Service的略称)是欧姆龙PLC的通信命令体系的名称。FINS消息通信中使用的命令。有CPU单元地址和各单元地址。 运用 FINS指令可实现各种网络间的无缝通信,通过编程发送FINS指令,上位机或PLC就能够读写另一个PLC数据区的内容,甚至控制其运行状态。 ## FINS 协议格式简介 以读取命令为例(读取W10的一个字) 46 49 4e 53 00 00 00 1a 00 00 00 02 00 00 00 00 80 00 02 00 00 00 00 00 00 DA 01 01 B1 00 0A 00 00 01 | FINS/Tcp Header | FINS Frame | | | FINS Header | FINS Command | 整个命令可以分成2个部分:FINS/Tcp Header 和 FINS Frame,FINS Frame又可以分成两个部分:FINS Header 和 FINS Command(如果是写操作,后面还有一个FINS Data) 46 49 4e 53 // F I N S ********************* 00 00 00 1a // 命令长度 FINS/TCP Header 00 00 00 02 // 命令码 00 00 00 00 // 错误码 ********************* 80 00 02 00 // ICF RSV GCT DNA *************** 00 00 00 00 // DA1 DA2 SNA SA1 FINS Header 00 DA // SA2 SID *************** 01 01 // FINS主命令 FINS从命令 (01 01 读) *************** B1 00 0A 00 // 寄存器控制位 开始字地址(高,低) 开始位地址 FINS Command 00 01 // 读取数量(高,低) *************** ## Omron PLC 内存对照代码表 ![图1](/Imgs/01.png) ![图2](/Imgs/02.png) ![图3](/Imgs/03.png) ### 内存代码示例 ![图4](/Imgs/04.png) ## 官方手册 详细说明在 Section3 和 Section5 [手册在这里](https://www.fa.omron.com.cn/data_pdf/mnu/w342-e1-17_cs1_cj1_cp1_com_cmd.pdf?id=1638)