引用
引用第6樓夏日雪夢于2009-11-16 15:30發表的 Re:Re:新手PLC仿真學習系統 (感謝 litung xiaoqizi 幫助、指導) :
只要M301~M349其中有一點動作,M300就ON,這個感覺容易做到;
直接M300從去找異常點的程式在那,這個有些不太明白,M300如何與故障點的程序連接,能否再詳細點說明了。
把異常集中在一點,是方便你對PLC程式除錯。
vb程式可以對你設定的異常點區域作搜尋比對,只要其中一個點=on,就是有異常。
底下部份程式給你參考看看。設一個time去掃程式。
Private Sub tmrAlarm_Timer()
Dim I As Integer
Dim J As Integer
Dim sDATA(100) As String
Dim mData(100) As Integer
'讀取M值狀態
sDATA(0) = ReadM(300)
gf = PLC.ReadDeviceRandom2(sDATA(0), CLng(10), mData(0))
sDATA(1) = ReadM(310)
gf = PLC.ReadDeviceRandom2(sDATA(1), CLng(10), mData(10))
sDATA(2) = ReadM(320)
gf = PLC.ReadDeviceRandom2(sDATA(2), CLng(10), mData(20))
sDATA(3) = ReadM(330)
gf = PLC.ReadDeviceRandom2(sDATA(3), CLng(10), mData(30))
sDATA(4) = ReadM(340)
gf = PLC.ReadDeviceRandom2(sDATA(4), CLng(10), mData(40))
sDATA(5) = ReadM(350)
gf = PLC.ReadDeviceRandom2(sDATA(5), CLng(10), mData(50))
sDATA(6) = ReadM(360)
gf = PLC.ReadDeviceRandom2(sDATA(6), CLng(10), mData(60))
sDATA(6) = ReadM(370)
gf = PLC.ReadDeviceRandom2(sDATA(7), CLng(10), mData(70))
sDATA(8) = ReadM(380)
gf = PLC.ReadDeviceRandom2(sDATA(8), CLng(10), mData(80))
For N = 0 To 9
M(300 + N) = mData(N)
M(310 + N) = mData(N + 10)
M(320 + N) = mData(N + 20)
M(330 + N) = mData(N + 30)
M(340 + N) = mData(N + 40)
M(350 + N) = mData(N + 50)
M(360 + N) = mData(N + 60)
M(370 + N) = mData(N + 70)
M(380 + N) = mData(N + 80)
Next N
lblAlarm = ""
If M(301) Then lblAlarm = lblAlarm & "M301:送料口異常"
If M(302) Then lblAlarm = lblAlarm & "M302:無料警告"
If M(303) Then lblAlarm = lblAlarm & "M303:載臺異常"
If M(304) Then lblAlarm = lblAlarm & "M304:推料異常"
If M(305) Then lblAlarm = lblAlarm & "M305:夾料異常"
If M(306) Then lblAlarm = lblAlarm & "M306:出料口異常"
If M(307) Then lblAlarm = lblAlarm & "M307:定位異常"
If M(308) Then lblAlarm = lblAlarm & "M308:底座異常"
If M(309) Then lblAlarm = lblAlarm & "M309:車刀座異常"
If M(320) Then lblAlarm = lblAlarm & "M320:無料警告"
If M(321) Then lblAlarm = lblAlarm & "M321:載臺前進異常"
If M(322) Then lblAlarm = lblAlarm & "M322:載臺後進異常"
If M(323) Then lblAlarm = lblAlarm & "M323:推料定位異常"
If M(324) Then lblAlarm = lblAlarm & "M324:推料前進異常"
If M(325) Then lblAlarm = lblAlarm & "M325:推料後退異常"
If M(326) Then lblAlarm = lblAlarm & "M326:夾料前進異常"
If M(327) Then lblAlarm = lblAlarm & "M327:夾料後退異常"
If M(328) Then lblAlarm = lblAlarm & "M328:定位前進異常"
If M(329) Then lblAlarm = lblAlarm & "M329:定位後退異常"
If M(330) Then lblAlarm = lblAlarm & "M330:底座前進異常"
If M(331) Then lblAlarm = lblAlarm & "M331:底座後退異常"
If M(332) Then lblAlarm = lblAlarm & "M332:車刀座前進異常"
If M(333) Then lblAlarm = lblAlarm & "M333:車刀座後退異常"
End Sub