Now You Can Have Robust Data Logging for Free – Part 1
Now You Can Have Robust Data Logging for Free – Part 2
Now You Can Have Robust Data Logging for Free – Part 3
Now You Can Have Robust Data Logging for Free – Part 4
Now You Can Have Robust Data Logging for Free – Part 5
Now You Can Have Robust Data Logging for Free – Part 6
Now You Can Have Robust Data Logging for Free – Part 7
Now You Can Have Robust Data Logging for Free – Part 8
Computer Program Visual Basic (VB6) Continue
The display part of the program is done, and we have reviewed the Modbus TCP protocol. It is now time to start the VB6 code. Let’s discuss how the logic will work.
1. The user selects ‘Start Logging.’
2. The timer for the interval between communications is stopped.
3. The IP address is used to open the Winsock connection. If the reference is made, then the background color of the IP Address will turn green, and we will continue to step 4. If the contact already exists, then continue to step 4. If the connection cannot be made, the background color is red, and further execution is stopped. The program will continue at step 1.
4. The following sequence of commands is made: Determine what command to send.
- Read the Daily Production Log and Minute Log Pointers (MHR1 and MHR2 )
- If MHR2 (Minute Log Pointer ) > 670, then
- Request the Minute Log starting at MHR670 and keep incrementing by ten until the last location is requested.
- Write the value of 670 into MHR2 (Reset the pointer)
- If MHR1 (Daily Production Log Pointer > 30, then
- Request the Daily Production Log starting at MHR30 and keep incrementing by 20 until the last location is requested.
- Write the value of 30 into MHR1 (Reset the pointer)
- Read the current Minute Log information starting at MHR660
- Read the current Daily Production Log information starting at MHR10
The above is the general program flow for the program.
Here are our variables:
Dim MbusQuery
Public MbusResponse As String
Dim MbusByteArray(255) As Byte
Public MbusStatus As Integer
Public ProductionPointer As Integer
Public MinutePointer As Integer
Private Sub Command1_Click()
Timer1.Enabled = False’ Stop the interval between reads to the PLC
Timer 1 controls the time between intervals of communication to the PLC.
Dim StartTime
If Winsock1.State <> 7 Then
If (Winsock1.State <> sckClosed) Then
Winsock1.Close
End If
Winsock1.RemoteHost = Text1.Text’ Set IP Address
Winsock1.Connect
StartTime = Timer’ Use the timer to determine if a connection cannot be made.
Do While ((Timer < StartTime + 2) And (Winsock1.State <> 7))
DoEvents
Loop
If (Winsock1.State = 7) Then
Text1.BackColor = &HFF00& ‘Change the background color to green
Else
Text1.BackColor = &HFF ‘Change the background color to red
Exit Sub
End If
End If
Here is the code to control Winsock1. The IP address entered in Text1 is used to set the RemoteHost. We then check for the state of the Winsock1. The following are the different states that Winsock1 can be in:
Constant | Value | Description |
sckClosed | 0 | Default. Closed |
sckOpen | 1 | Open |
sckListening | 2 | Listening |
sckConnectionPending | 3 | Connection pending |
sckResolvingHost | 4 | Resolving host |
sckHostResolved | 5 | Host resolved |
sckConnecting | 6 | Connecting |
sckConnected | 7 | Connected |
sckClosing | 8 | The peer is closing the connection |
sckError | 9 | Error |
‘Read the information
600/256 = 2.34
The most significant byte is 02
600 – (256*2) = 88
The least significant byte is 88
So the information we need to send through Winsock1 would be Chr(2) and Chr(88) to represent the value of 600.
In part 9, we will continue with writing the VB6 program. We will start reading and writing the information to the PLC.
If you have any questions or need further information, please get in touch with me.
Thank you,
Garry
If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLCs are not challenging to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimals, Hexadecimal, ASCII, and Floating Points.
To get this free article, subscribe to my free email newsletter.
Use the information to inform other people how numbering systems work. Sign up now.
The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.