Control PLC omron to VB example | Controller Circuit

Monday, January 21, 2013

Control PLC omron to VB example

In this post , I'd like to Change the state of PLC (run,monitor,stop) from the VB.I send the command from VB to PLC and then PLC responds and the change their state ,
please make VB interface below:



write the source code below:
Dim data 'General Declaration
Private Sub kirim()
Dat$ = data
l = Len(Dat$)
A = 0
For I = 1 To l
Opo$ = Mid$(Dat$, I, 1)
A = Asc(Opo$) Xor A
Next I
FCS$ = Hex$(A)
If Len(FCS$) = 1 Then

FCS$ = "0" + FCS$
End If
DatTX$ = Dat$ + FCS$ + "*" + Chr$(13)
MSComm1.Output = DatTX$
End Sub

Private Sub cmdKeluar_Click()
End
End Sub

Private Sub cmdMonitor_Click()
data = "@00SC02" '(setting hostlink pada PLC 00)
lblPeringatan.Caption = "MESIN ANDA BERGERAK,BILA ANDA MEMILIH MODE INI,PASTIKAN SAFETY"
lblPeringatan.ForeColor = &HFF&
jawab = MsgBox("ANDA MAU MERUBAH MODE PLC? " & vbCrLf & _
"MONITOR MODE!!!! ", vbYesNo + vbQuestion + vbDefaultButton1, "RUBAH MODE PLC")
If jawab = vbYes Then
cmdProgram.Enabled = True
cmdRun.Enabled = True
cmdMonitor.Enabled = False
kirim
lblModePLC.ForeColor = &H8000000D
lblModePLC.Caption = "PLC SEDANG MODE MONITOR !!!!"
lblPeringatan.Caption = ""
lblPeringatan.ForeColor = &HFFFFFF
End If
lblPeringatan.Caption = ""
lblPeringatan.ForeColor = &HFFFFFF
End Sub

Private Sub cmdProgram_Click()
data = "@00SC00" '(setting hostlink pada PLC 00)
lblPeringatan.Caption = "MESIN ANDA AKAN SHUT DOWN ,BILA ANDA MEMILIH MODE INI"
lblPeringatan.ForeColor = &HFF&
jawab = MsgBox("ANDA MAU MERUBAH MODE PLC? " & vbCrLf & _
"PROGRAM MODE!!!! ", vbYesNo + vbQuestion + vbDefaultButton1, "RUBAH MODE PLC")
If jawab = vbYes Then
cmdProgram.Enabled = False
cmdRun.Enabled = True
cmdMonitor.Enabled = True
kirim
lblModePLC.ForeColor = &HFF&
lblModePLC.Caption = "PLC SEDANG MODE PROGRAM!!!!"
lblPeringatan.Caption = ""
lblPeringatan.ForeColor = &HFFFFFF
End If
lblPeringatan.Caption = ""
lblPeringatan.ForeColor = &HFFFFFF
End Sub


Private Sub cmdRun_Click()
data = "@00SC03" '(setting hostlink pada PLC 00)
lblPeringatan.Caption = "MESIN ANDA BERGERAK,BILA ANDA MEMILIH MODE INI,PASTIKAN SAFETY"
lblPeringatan.ForeColor = &HFF&
jawab = MsgBox("ANDA MAU MERUBAH MODE PLC? " & vbCrLf & _
"PROGRAM MODE!!!! ", vbYesNo + vbQuestion + vbDefaultButton1, "RUBAH MODE PLC")
If jawab = vbYes Then
cmdProgram.Enabled = True
cmdRun.Enabled = False
cmdMonitor.Enabled = True
kirim
lblModePLC.ForeColor = &HFF&
lblModePLC.Caption = "PLC SEDANG MODE RUN!!!!"
lblPeringatan.Caption = ""
lblPeringatan.ForeColor = &HFFFFFF
End If
lblPeringatan.Caption = ""
lblPeringatan.ForeColor = &HFFFFFF
End Sub

Private Sub SET_Click()
data = "@00WR00100001"
kirim
End Sub

Private Sub RESET_Click()
data = "@00WR00100000"
kirim
End Sub

Private Sub Form_Load()
MSComm1.CommPort = 1 '(port PC comm1,tapi tergantung PC anda)
MSComm1.Settings = "9600, e, 7, 2" '(harus sama PC dan PLC)
MSComm1.PortOpen = True
End Sub

No comments:

Post a Comment