EEC 欧姆龙PLC输入模块算法
- Option Explicit
- Public MyArray(20000) As
Integer - Public MyArraySensor(20000) As
Integer - Sub 生成输入模块信息()
- Dim SourceTab As
String - Dim TargetTab As
String - Dim ProjTab As
String - Dim StartRow As
Integer - Dim EndRow As
Integer - Dim PRow As
Integer - Dim ModuleRow, SensorRow As
Integer - Dim Proj As MyType
- Dim Target As MyType
- Dim InputModule, ModulePath, SensorPath As
String - Dim FrameName As
String - Dim MyTempA, MyTempK, MaxRowD As
Integer - Dim SensorInt, SensorRem As
Integer - Dim SensorRowRelative As
Integer - Dim SensorMacroPosition As
String - Dim SensorChannelNum As
Integer - Dim SensorIdentifier As
String - Dim SensorPage As
Integer - Dim SensorY As
Integer
'传感器Y坐标Dim TargetMaxRowA As
Integer - SourceTab = "输入模块参数"
- ProjTab = "项目IO表"
- TargetTab = "生成输入模块图纸"
- 'TargetTab = "表单"
FrameName = "Fn1_Maider_A3"
- ModulePath = "OMRON\"
SensorPath = "OtherMacros\"
- '*********模块数据填充
'模块型号检测
For Proj.CRowNum = 4
To - If Worksheets(ProjTab).Range("C" & Proj.CRowNum) = 1
Then - InputModule = Worksheets(ProjTab).Range("B" & Proj.CRowNum)
- End If
- Next
- 'MsgBox InputModule
'求取模糊最大行数
With Worksheets(ProjTab)
- For Proj.DRowNum = 4
To - If .Range("D" & Proj.DRowNum) = ""
Then - MyTempK = MyTempK +
- Else
- MyTempK =
- End If
- If MyTempK >= 500
Then - MaxRowD = Proj.DRowNum -
- Exit For
- End If
- Next
- End With
- ' MsgBox MaxRowD
'页Left模块数据填充
For Proj.DRowNum = 4
- If Worksheets(ProjTab).Range("D" & Proj.DRowNum) <> ""
Then - Call Traverse(SourceTab, "A2:A20000", Left(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 5), SensorRowRelative)
- ModuleRow = Application.WorksheetFunction.Quotient((Proj.DRowNum -
- 'PLC模块数据填充
With Worksheets(TargetTab)
- .Range("A" & ModuleRow) = "####[x/y]"
- .Range("A" & ModuleRow + 1) = ModulePath & InputModule
- .Range("C" & ModuleRow + 1) = Worksheets(SourceTab).Range("B" & SensorRowRelative)
- .Range("E" & ModuleRow + 1) = Worksheets(SourceTab).Range("C" & SensorRowRelative)
- .Range("I" & ModuleRow + 1) = Worksheets(SourceTab).Range("D" & SensorRowRelative)
- .Range("J" & ModuleRow + 1) = "多线 <1>"
- .Range("K" & ModuleRow + 1) = "A"
- Select Case Worksheets(SourceTab).Range("E" & SensorRowRelative)
- Case
"Left" - .Range(
- If Worksheets(SourceTab).Range("E" & SensorRowRelative + 1) = "Right"
Then - .Range("Q" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "_" & Worksheets(SourceTab).Range("A" & SensorRowRelative + 1)
- Else
- .Range("Q" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative)
- End If
- .Range("R" & ModuleRow + 1) = FrameName
- Case
"Right" - .Range(
- Case Else
- MsgBox "Macro Position 数据错误,请检查!!!"
- End Select
- 'PLC模块填充数据
.Range("S" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative)
- .Range("T" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "00"
- .Range("U" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "01"
- .Range("V" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "02"
- .Range("W" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "03"
- .Range("X" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "04"
- .Range("Y" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "05"
- .Range("Z" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "06"
- .Range("AA" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "07"
- .Range("AB" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "08"
- .Range("AC" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "09"
- .Range("AD" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "10"
- .Range("AE" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "11"
- .Range("AF" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "12"
- .Range("AG" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "13"
- .Range("AH" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "14"
- .Range("AI" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "15"
- End With
- End If
- Next
- '页Right模块数据填充
For Proj.DRowNum = 20
- If Worksheets(ProjTab).Range("D" & Proj.DRowNum) <> ""
Then - Call Traverse(SourceTab, "A2:A20000", Left(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 5), SensorRowRelative)
- ModuleRow = Application.WorksheetFunction.Quotient((Proj.DRowNum -
- 'PLC模块数据填充
With Worksheets(TargetTab)
- .Range("A" & ModuleRow) = "####[x/y]"
- .Range("A" & ModuleRow + 1) = ModulePath & InputModule
- .Range("C" & ModuleRow + 1) = Worksheets(SourceTab).Range("B" & SensorRowRelative)
- .Range("E" & ModuleRow + 1) = Worksheets(SourceTab).Range("C" & SensorRowRelative)
- .Range("I" & ModuleRow + 1) = Worksheets(SourceTab).Range("D" & SensorRowRelative)
- .Range("J" & ModuleRow + 1) = "多线 <1>"
- .Range("K" & ModuleRow + 1) = "A"
- Select Case Worksheets(SourceTab).Range("E" & SensorRowRelative)
- Case
"Left" - .Range(
- If Worksheets(SourceTab).Range("E" & SensorRowRelative + 1) = "Right"
Then - .Range("Q" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "_" & Worksheets(SourceTab).Range("A" & SensorRowRelative + 1)
- Else
- .Range("Q" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative)
- End If
- .Range("R" & ModuleRow + 1) = FrameName
- Case
"Right" - .Range(
- Case Else
- MsgBox "Macro Position 数据错误,请检查!!!"
- End Select
- 'PLC模块填充数据
.Range("S" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative)
- .Range("T" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "00"
- .Range("U" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "01"
- .Range("V" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "02"
- .Range("W" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "03"
- .Range("X" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "04"
- .Range("Y" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "05"
- .Range("Z" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "06"
- .Range("AA" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "07"
- .Range("AB" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "08"
- .Range("AC" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "09"
- .Range("AD" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "10"
- .Range("AE" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "11"
- .Range("AF" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "12"
- .Range("AG" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "13"
- .Range("AH" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "14"
- .Range("AI" & ModuleRow + 1) = Worksheets(SourceTab).Range("A" & SensorRowRelative) & "15"
- End With
- End If
- Next
- '*********传感器数据填充
- ' 项目表中传感器行号 除以32 整数部分 IF(项目表中传感器 <> "",QUOTIENT((项目表中传感器行号-4),32)*68+6,"")
' 项目表中传感器行号 除以32 余数部分
Dim TempRem, NearInt As
Integer - For Proj.DRowNum = 4
- If Worksheets(ProjTab).Range("D" & Proj.DRowNum) <> ""
Then - If (Proj.DRowNum - 4) Mod 32 = 0
Then - SensorRow = Application.WorksheetFunction.Quotient((Proj.DRowNum -
- Else
- SensorRem = (Proj.DRowNum -
- NearInt = Proj.DRowNum - SensorRem
- SensorInt = Application.WorksheetFunction.Quotient((NearInt -
- SensorRow = SensorInt + SensorRem *
- End If
- ' MsgBox Proj.DRowNum & "," & SensorRow
- End If
- '传感器数据填充区,前两行特例
If Worksheets(ProjTab).Range("D" & Proj.DRowNum) <> ""
Then - With Worksheets(TargetTab)
- If (Proj.DRowNum - 4) Mod 32 = 0
Or (SensorRow - 7) Mod 68 = 1
Then - '(Proj.DRowNum - 4) Mod 32 = 0 第一个传感器
' (SensorRow - 7) Mod 68 第二个传感器
.Range("A" & SensorRow) = "####[X]"
- .Range("A" & SensorRow + 1) = SensorPath & Worksheets(ProjTab).Range("H" & Proj.DRowNum)
- '区分第一个还是第二个
If Worksheets(ProjTab).Range("F" & Proj.DRowNum) <> ""
Then - If Int(Right(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 2)) = 0
Then
'第一个传感器================.Range("K" & SensorRow + 1) = "A"
- ElseIf Int(Right(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 2)) = 1
Then
'第二个传感器================.Range("K" & SensorRow + 1) = "B"
- End If
- .Range(
- .Range(
- End If
- Else
- 个传感器
If Worksheets(ProjTab).Range("F" & Proj.DRowNum) <> ""
Then
'项目表中IO有注释部分.Range("A" & SensorRow) = "####[O=X/Y]"
- .Range("A" & SensorRow + 1) = SensorPath & Worksheets(ProjTab).Range("H" & Proj.DRowNum)
- End If
- If Worksheets(ProjTab).Range("F" & Proj.DRowNum) <> ""
Then - '判断传感器的奇偶性,奇数宏变量为B,偶数为A
If Int(Right(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 2)) Mod 2 = 0
Then
'偶数.Range("K" & SensorRow + 1) = "A"
- ElseIf Int(Right(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 2)) Mod 2 = 1
Then
'奇数.Range("K" & SensorRow + 1) = "B"
- End If
- End If
- 'X坐标
'检测传感器对应在Eplan图纸中的位置,left 或者 right
Call Traverse(SourceTab, "A2:A20000", Left(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 5), SensorRowRelative)
- SensorMacroPosition = Worksheets(SourceTab).Range("E" & SensorRowRelative)
- If Worksheets(ProjTab).Range("F" & Proj.DRowNum) <> ""
Then
'项目表中IO有注释部分If SensorMacroPosition = "Left"
Then - .Range(
- End If
- If SensorMacroPosition = "Right"
Then - .Range(
- End If
- End If
- 'Y坐标
'Y坐标数值初始化
Select Case Right(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 2)
- Case
"02" - SensorY =
- Case
"03" - SensorY =
- Case
"04" - SensorY =
- Case
"05" - SensorY =
- Case
"06" - SensorY =
- Case
"07" - SensorY =
- Case
"08" - SensorY =
- Case
"09" - SensorY =
- Case
"10" - SensorY =
- Case
"11" - SensorY =
- Case
"12" - SensorY =
- Case
"13" - SensorY =
- Case
"14" - SensorY =
- Case
"15" - SensorY =
- Case Else
- SensorY =
- End Select
- If Worksheets(ProjTab).Range("F" & Proj.DRowNum) <> ""
Then
'项目表中IO有注释部分.Range("N" & SensorRow + 1) = SensorY
- End If
- End If
- '传感器相同格式部分================
'SensorNumber**********
'标识符定义
Select Case Worksheets(ProjTab).Range("H" & Proj.DRowNum)
- Case
"6_磁性开关-常开" - SensorIdentifier = "-B"
- Case
"" - SensorIdentifier = ""
- Case Else
- MsgBox "传感器类型错误,请检查!!!" & ",项目IO表行号为:" & Proj.DRowNum
- End Select
- '检测传感器对应在Eplan图纸中页码
Call Traverse(SourceTab, "A2:A20000", Left(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 5), SensorRowRelative)
- SensorPage = Int(Worksheets(SourceTab).Range("D" & SensorRowRelative))
- SensorMacroPosition = Worksheets(SourceTab).Range("E" & SensorRowRelative)
- If SensorMacroPosition = "Left"
And Worksheets(ProjTab).Range("F" & Proj.DRowNum) <> ""
Then - .Range("O" & SensorRow + 1) = SensorIdentifier & SensorPage & Right(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 2)
- ElseIf SensorMacroPosition = "Right"
And Worksheets(ProjTab).Range("F" & Proj.DRowNum) <> ""
Then - .Range("O" & SensorRow + 1) = SensorIdentifier & SensorPage & (Int(Right(Worksheets(ProjTab).Range("D" & Proj.DRowNum), 2)) + 16)
- ElseIf SensorMacroPosition <> "Left"
And SensorMacroPosition <> "Right"
Then - MsgBox "Macro Position 数据错误,请检查!!!"
- End If
- .Range("P" & SensorRow + 1) = Worksheets(ProjTab).Range("E" & Proj.DRowNum) & Worksheets(ProjTab).Range("F" & Proj.DRowNum)
- If Worksheets(ProjTab).Range("F" & Proj.DRowNum) <> ""
Then
'项目表中IO有注释部分.Range("J" & SensorRow + 1) = "多线 <1>"
- End If
- End With
- End If
- Next
- '注释命令部分
- With Worksheets(TargetTab)
- For Target.ARowNum = 2
To - If .Range("A" & Target.ARowNum) = ""
Then - MyTempA = MyTempA +
- Else
- MyTempA =
- End If
- If MyTempA >= 500
Then - TargetMaxRowA = Target.ARowNum -
- Exit For
- End If
- Next
- For Target.ARowNum = 2
- If Worksheets(TargetTab).Range("A" & Target.ARowNum) = ""
Then - Worksheets(TargetTab).Range("L" & Target.ARowNum) = "!"
- End If
- Next
- End With
- MsgBox "数据生成完成!"
- End Sub
EEC 欧姆龙PLC输入模块算法的更多相关文章
- PLC编程算法
PLC编程算法(一) 01 开关量也称逻辑量,指仅有两个取值,0或1.ON或OFF.它是最常用的控制,对它进行控制是PLC的优势,也是PLC最基本的应用. 开关量控制的目的是,根据开关量的当前输入组合 ...
- 欧姆龙PLC HostLink协议整理
欧姆龙PLC HostLink协议整理 1.常用的存储器功能区 CIO: 输入继电器 272 点(17 CH) 0.00-16.15 输出继电器 272 点(17 CH) 100.00-116.1 ...
- 欧姆龙plc通讯协议格式
欧姆龙CPM1A型plc与上位计算机通信的顺序是上位机先发出命令信息给PLC,PLC返回响应信息给上位 机.每次通信发送/接受的一组数据称为一"帧".帧由少于131个字符的数据构成 ...
- c#基于TCP/IP、CIP协议的欧姆龙PLC通信
一.关于CIP协议 CIP通信是Common Industrial Protocl(CIP)的简称,它是一个点到点的面向对象协议,能够实现工业器件(传感器,执行器)之间的连接,和高等级的控制器之间的连 ...
- 欧姆龙PLC以太网FINSTCP通信例程与操作步骤
http://wenku.baidu.com/link?url=aa8kvtCg1eYp-wkIZY_hDpE5IuENT21Uvk1zVNtFiIyPTk-kjfarzSVyGt2DPs4ikXLT ...
- 欧姆龙PLC CP1E型号的90,91,190
I/O存储区的CIO区,输入位CIO0-CIO99 对于NA型,模拟输入0和1将分别占用CIO90和CIO91 输出位CIO100-CIO199,对于NA型,模拟输出0将占用CIO190
- SharpNodeSettings项目,可配置的数据采集,统一的工业数据网关,OPC UA服务器开发,PLC数据发布到自身内存,redis,opc ua,以及数据可视化开发
本项目隶属于 HslCommunication 项目的SDK套件,如果不清楚HslCommunication组件的话,可以先了解那个项目,源代码地址:https://github.com/dathli ...
- 「PLC」PLC基本编程
PLC中无非就是三大量:开关量(数字量).模拟量.脉冲量.只在搞清楚三者之间的关系,你就能熟练的掌握PLC了. PLC编程算法(一) 1. 开关量也称逻辑量,指仅有两个取值,0或1.ON或OFF.它是 ...
- HslCommunication组件库使用说明 (转载)
一个由个人开发的组件库,携带了一些众多的功能,包含了数据网络通信,文件上传下载,日志组件,PLC访问类,还有一些其他的基础类库. nuget地址:https://www.nuget.org/packa ...
随机推荐
- Entity Framework:Code-First Tutorial开篇
这个系列文章是关于Entity Framework Code-First的英文系列文章,内容不错,每篇一个主题知识点介绍,特转载过来 原文地址:http://www.entityframeworktu ...
- 部署到IIS上上传不了文件
应用程序池改一下
- CSS中position的absolute和relative用法
static: HTML元素的默认定位方式 absolute: 将对象从文档流中拖出,使用left,right,top,bottom等属性进行绝对定位.而其层叠通过z-index属性定义.绝对定位的元 ...
- redis命令集
查看使用运行服务:ping 关闭服务的连接:quit 切换数据库:select index 连接: redis-cli -h -a myPassword 查看密码: config get requir ...
- 51nod1043(数位dp)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1043 题意:中文题诶- 思路:数位dp 我们用dp[i][j ...
- Mice and Holes 单调队列优化dp
Mice and Holes 单调队列优化dp n个老鼠,m个洞,告诉你他们的一维坐标和m个洞的容量限制,问最小总距离.1 ≤ n, m ≤ 5000. 首先列出朴素的dp方程:\(f[i][j] ...
- 洛谷P1054 等价表达式
P1054 等价表达式 题目描述 明明进了中学之后,学到了代数表达式.有一天,他碰到一个很麻烦的选择题.这个题目的题干中首先给出了一个代数表达式,然后列出了若干选项,每个选项也是一个代数表达式,题目的 ...
- 洛谷 P1551 亲戚(并查集模板)
嗯... 题目链接:https://www.luogu.org/problemnew/show/P1551 思路: 很显然地我们会发现,这是一道并查集的模板题,并且是考察了并查集中的”并“和”查“的操 ...
- emmet缩写大全
Syntax Child: > nav>ul>li <nav> <ul> <li></li> </ul> </n ...
- windows srver 显示桌面图标。
rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0