| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- VERSION 4.00
- Begin VB.Form Form1
- Caption = "Form1"
- ClientHeight = 6570
- ClientLeft = 1140
- ClientTop = 915
- ClientWidth = 8310
- Height = 6975
- Left = 1080
- LinkTopic = "Form1"
- ScaleHeight = 6570
- ScaleWidth = 8310
- Top = 570
- Width = 8430
- Begin VB.Timer Timer1
- Interval = 1000
- Left = 1080
- Top = 360
- End
- Begin VB.Frame inputregs
- Caption = "INPUT REGS"
- Height = 4575
- Left = 4320
- TabIndex = 8
- Top = 1440
- Width = 1695
- Begin VB.TextBox inregsaddress
- Height = 285
- Left = 480
- TabIndex = 9
- Text = "1"
- Top = 360
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 9
- Left = 480
- TabIndex = 20
- Top = 4080
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 8
- Left = 480
- TabIndex = 19
- Top = 3720
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 7
- Left = 480
- TabIndex = 18
- Top = 3360
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 6
- Left = 480
- TabIndex = 17
- Top = 3000
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 5
- Left = 480
- TabIndex = 16
- Top = 2640
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 4
- Left = 480
- TabIndex = 15
- Top = 2280
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 3
- Left = 480
- TabIndex = 14
- Top = 1920
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 2
- Left = 480
- TabIndex = 13
- Top = 1560
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 1
- Left = 480
- TabIndex = 12
- Top = 1200
- Width = 735
- End
- Begin VB.Label inputreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 0
- Left = 480
- TabIndex = 11
- Top = 840
- Width = 735
- End
- End
- Begin VB.Frame Frame4
- Caption = "HOLDING REGS"
- Height = 4575
- Left = 6360
- TabIndex = 4
- Top = 1440
- Width = 1455
- Begin VB.TextBox holdingregsaddress
- Height = 285
- Left = 360
- TabIndex = 7
- Text = "1"
- Top = 360
- Width = 855
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 9
- Left = 360
- TabIndex = 29
- Top = 4080
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 8
- Left = 360
- TabIndex = 28
- Top = 3720
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 7
- Left = 360
- TabIndex = 27
- Top = 3360
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 6
- Left = 360
- TabIndex = 26
- Top = 3000
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 5
- Left = 360
- TabIndex = 25
- Top = 2640
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 4
- Left = 360
- TabIndex = 24
- Top = 2280
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 3
- Left = 360
- TabIndex = 23
- Top = 1920
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 2
- Left = 360
- TabIndex = 22
- Top = 1560
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 1
- Left = 360
- TabIndex = 21
- Top = 1200
- Width = 735
- End
- Begin VB.Label holdingreg
- Alignment = 2 'Center
- Caption = "0000"
- Height = 255
- Index = 0
- Left = 360
- TabIndex = 10
- Top = 840
- Width = 735
- End
- End
- Begin VB.Frame Frame2
- Caption = "COILS"
- Height = 4575
- Left = 2520
- TabIndex = 3
- Top = 1440
- Width = 1455
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 9
- Left = 600
- TabIndex = 50
- Top = 4080
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 8
- Left = 600
- TabIndex = 49
- Top = 3720
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 7
- Left = 600
- TabIndex = 48
- Top = 3360
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 6
- Left = 600
- TabIndex = 47
- Top = 3000
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 5
- Left = 600
- TabIndex = 46
- Top = 2640
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 4
- Left = 600
- TabIndex = 45
- Top = 2280
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 3
- Left = 600
- TabIndex = 44
- Top = 1920
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 2
- Left = 600
- TabIndex = 43
- Top = 1560
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 1
- Left = 600
- TabIndex = 42
- Top = 1200
- Width = 255
- End
- Begin VB.CheckBox coilstatus
- Enabled = 0 'False
- Height = 255
- Index = 0
- Left = 600
- TabIndex = 41
- Top = 840
- Width = 255
- End
- Begin VB.TextBox coiladdress
- Height = 285
- Left = 360
- TabIndex = 6
- Text = "1"
- Top = 360
- Width = 735
- End
- End
- Begin VB.Frame Frame1
- Caption = "INPUTS"
- Height = 4575
- Left = 600
- TabIndex = 2
- Top = 1440
- Width = 1575
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 9
- Left = 600
- TabIndex = 40
- Top = 4080
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 8
- Left = 600
- TabIndex = 39
- Top = 3720
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 7
- Left = 600
- TabIndex = 38
- Top = 3360
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 6
- Left = 600
- TabIndex = 37
- Top = 3000
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 5
- Left = 600
- TabIndex = 36
- Top = 2640
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 4
- Left = 600
- TabIndex = 35
- Top = 2280
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 3
- Left = 600
- TabIndex = 34
- Top = 1920
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 2
- Left = 600
- TabIndex = 33
- Top = 1560
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 1
- Left = 600
- TabIndex = 32
- Top = 1200
- Width = 255
- End
- Begin VB.CheckBox inputstatus
- Enabled = 0 'False
- Height = 255
- Index = 0
- Left = 600
- TabIndex = 31
- Top = 840
- Width = 255
- End
- Begin VB.TextBox inputaddress
- Height = 285
- Left = 360
- TabIndex = 5
- Text = "1"
- Top = 360
- Width = 735
- End
- End
- Begin VB.TextBox Device
- Height = 285
- Left = 3720
- TabIndex = 1
- Text = "1"
- Top = 720
- Width = 855
- End
- Begin VB.Label statusline
- Alignment = 2 'Center
- ForeColor = &H000000FF&
- Height = 255
- Left = 840
- TabIndex = 30
- Top = 1080
- Width = 6735
- End
- Begin VB.Label Label1
- Caption = "Device"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 13.5
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 375
- Left = 3600
- TabIndex = 0
- Top = 240
- Width = 1095
- End
- End
- Attribute VB_Name = "Form1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Public m_svr As IModSca
- Dim PollHandle(4) As Integer
- Dim status(4) As Integer
- Dim SlaveDevice As Integer
- Dim StartAddress(4) As Long
- Dim Modbus_Id(4) As Long
- Dim Counter As Integer
- Dim temp As Integer
- Dim Modbus_Addr As Long
- Private Sub Text4_Change()
- End Sub
- Private Sub coiladdress_Change()
- If (IsNumeric(coiladdress.Text)) Then
- StartAddress(1) = coiladdress.Text
- Modbus_Addr = Modbus_Id(1) + StartAddress(1)
- status(1) = m_svr.ModifyPollRequest(PollHandle(1), SlaveDevice, Modbus_Addr, 10)
- StatusMsg (status(1))
- End If
-
- End Sub
- Private Sub Device_Change()
- If (IsNumeric(Device.Text)) Then
- SlaveDevice = Device.Text
- Modbus_Addr = Modbus_Id(0) + StartAddress(0)
- temp = m_svr.ModifyPollRequest(PollHandle(0), SlaveDevice, Modbus_Addr, 10)
- Modbus_Addr = Modbus_Id(1) + StartAddress(1)
- temp = m_svr.ModifyPollRequest(PollHandle(1), SlaveDevice, Modbus_Addr, 10)
- Modbus_Addr = Modbus_Id(2) + StartAddress(2)
- temp = m_svr.ModifyPollRequest(PollHandle(2), SlaveDevice, Modbus_Addr, 10)
- Modbus_Addr = Modbus_Id(3) + StartAddress(3)
- temp = m_svr.ModifyPollRequest(PollHandle(3), SlaveDevice, Modbus_Addr, 10)
- End If
- End Sub
- Private Sub Form_Load()
- Set m_svr = CreateObject("ModScan32.Document")
-
- Modbus_Id(0) = 10000 'input status prefix
- Modbus_Id(1) = 0 'coil status prefix
- Modbus_Id(2) = 30000 'input register prefix
- Modbus_Id(3) = 40000 'holding register prefix
- SlaveDevice = 1
- For Counter = 0 To 3
- StartAddress(Counter) = 1
- Modbus_Addr = Modbus_Id(Counter) + StartAddress(Counter)
- PollHandle(Counter) = m_svr.CreatePollRequest(SlaveDevice, Modbus_Addr, 10)
- Next Counter
- statusline = "** UNINITIALIZED **"
- End Sub
- Private Sub Form_Terminate()
- For Counter = 0 To 4
- m_svr.DeletePollRequest (PollHandle(Counter))
- Next Counter
-
- End Sub
- Public Sub StatusMsg(Index As Integer)
- If Index = 0 Then statusline = ""
- If Index > 0 And Index < 256 Then statusline = "Slave Device Exception Response"
- If Index = 256 Then statusline = "Invalid Handle"
- If Index = 257 Then statusline = "Modbus Message Overrun"
- If Index = 258 Then statusline = "Invalid Address"
- If Index = 259 Then statusline = "Invalid Device Address"
- If Index = 260 Then statusline = "Invalid Length Specification"
- If Index = 261 Then statusline = "Invalid modbus command"
- If Index = 262 Then statusline = "Driver Out-Of-Memory"
- If Index = 263 Then statusline = "** Time-Out **"
- If Index = 264 Then statusline = "Invalid Protocol Specification"
- If Index = 265 Then statusline = "** Bad Checksum **"
- If Index = 266 Then statusline = "Server NOT Connected"
- If Index = 267 Then statusline = "Invalid Response from Driver"
- If Index = 268 Then statusline = "Modbus Write Failure"
- If Index = 269 Then statusline = "Remote Server not Connected"
- If Index = 270 Then statusline = "** UNINITIALIZED **"
- If Index = 271 Then statusline = "ModScan Demo Time Expired"
- End Sub
- Private Sub holdingregsaddress_Change()
- If (IsNumeric(holdingregsaddress.Text)) Then
- StartAddress(3) = holdingregsaddress.Text
- Modbus_Addr = Modbus_Id(3) + StartAddress(3)
- status(3) = m_svr.ModifyPollRequest(PollHandle(3), SlaveDevice, Modbus_Addr, 10)
- StatusMsg (status(3))
- End If
-
- End Sub
- Private Sub inputaddress_Change()
- If (IsNumeric(inputaddress.Text)) Then
- StartAddress(0) = inputaddress.Text
- Modbus_Addr = Modbus_Id(0) + StartAddress(0)
- status(0) = m_svr.ModifyPollRequest(PollHandle(0), SlaveDevice, Modbus_Addr, 10)
- StatusMsg (status(0))
- End If
-
- End Sub
- Private Sub inregsaddress_Change()
- If (IsNumeric(inregsaddress.Text)) Then
- StartAddress(2) = inregsaddress.Text
- Modbus_Addr = Modbus_Id(2) + StartAddress(2)
- status(2) = m_svr.ModifyPollRequest(PollHandle(2), SlaveDevice, Modbus_Addr, 10)
- StatusMsg (status(2))
- End If
-
- End Sub
- Private Sub Timer1_Timer()
- For Counter = 0 To 9
- status(0) = m_svr.ReadValue(PollHandle(0), Counter, temp)
- StatusMsg (status(0))
- If temp = 0 Then
- inputstatus(Counter).Value = 0
- Else
- inputstatus(Counter).Value = 1
- End If
- Next Counter
- For Counter = 0 To 9
- status(1) = m_svr.ReadValue(PollHandle(1), Counter, temp)
- StatusMsg (status(1))
- If temp = 0 Then
- coilstatus(Counter).Value = 0
- Else
- coilstatus(Counter).Value = 1
- End If
- Next Counter
- For Counter = 0 To 9
- status(2) = m_svr.ReadValue(PollHandle(2), Counter, temp)
- StatusMsg (status(2))
- inputreg(Counter).Caption = temp
- Next Counter
-
-
- For Counter = 0 To 9
- status(3) = m_svr.ReadValue(PollHandle(3), Counter, temp)
- StatusMsg (status(3))
- holdingreg(Counter).Caption = temp
- Next Counter
- End Sub
|