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 connection is made then the background colour of the IP Address will turn green and we will continue to step 4. If the connection already exists then continue to step 4. If the connection cannot be made then the background colour is red, further execution is stopped. The program will continue at step 1.
4. The following sequence of commands are 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 10 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:
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
Timer1 is used to control the amount of time between intervals of communication to the PLC.
If Winsock1.State <> 7 Then
If (Winsock1.State <> sckClosed) Then
Winsock1.RemoteHost = Text1.Text ‘ Set IP Address
StartTime = Timer ‘ Use the timer to determine if a connection cannot be made
Do While ((Timer < StartTime + 2) And (Winsock1.State <> 7))
If (Winsock1.State = 7) Then
Text1.BackColor = &HFF00& ‘ Change background colour to green
Text1.BackColor = &HFF ‘ Change background colour to red
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:
|sckClosing||8||Peer is closing the connection|
‘ 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 that 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 contact me.
If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.
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.