Category Archives: Uncategorized

Here’s a Quick Way to Wire NPN and PNP devices

Here’s a Quick Way to Wire NPN and PNP devices

I get asked often on how to wire NPN and PNP devices to the programmable logic controller. This can be confusing at first when looking at the wiring diagrams. I have managed to destroy a few sensors in the process….. so lets get started and I will share my experiences.


NPN and PNP refer to the transistor in the output device.
NPN – Negative Positive Negative Switching. Sometimes referred to as ‘Sinking’ the load.  People have told me that when the NPN sensor blows it has a tendency to blow in an open state. (No Signal)
PNP – Positive Negative Positive Switching. Sometimes referred to as ‘Sourcing’ the load. People have told me that when the PNP sensor blows it has a tendency to blow in a closed state. (Signal On)

When the sensor blows, (malfunctions) it usually will also take out the power supply. (Fuse) It generally does not matter if you use NPN or PNP sensors provided they are all connected to the PLC using isolated commons.

You cannot mix PNP and NPN sensors on the same common point for inputs to the PLC. If you do mix the sensors, then the different common points on the PLC must be isolated from each other. This means that the commons are not connected internally to each other. Not ensuring this takes place will provide a short across the power supply and blow your sensors and supply. In general, machines tend to use all NPN or all PNP only.

Colour coding of the wires vary. Do not always rely on the colour code of the wires for connection. Refer to the wire diagrams in the documentation.

The following is a wire diagram of an open collector PNP sensor. You will notice that the load appears between the 0V (Blue)  and Switching wire (Black). When connecting to the PLC, the PLC input acts as the load. The 0V (Blue) will be attached to the common input and the Switching wire (Black) will be attached to the input number.

The following is a wire diagram of an open collector NPN sensor. You will notice that the load appears between the +V (Brown)  and Switching wire (Black). When connecting to the PLC, the PLC input acts as the load. The +V (Brown) will be attached to the common input and the Switching wire (Black) will be attached to the input number.

As you can see a direct short will be created if NPN and PNP sensors are wired into the PLC on the same common. The following shows an example of wiring of the 3 wire sensors into a PLC with isolated commons.

Watch on YouTube : Wiring NPN Sensor to PLC

Watch on YouTube : Wiring PNP Sensor to PLC

Watch on YouTube : Wiring Contact (Discrete) PLC Inputs

Wiring Interposing Relays
Watch on YouTube
: Wiring NPN and PNP Sensors into the PLC with an Interposing Relay
If you have any questions or need further information please contact me.
Thank you,
Garry



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.

How to make a Start / Stop / Jog circuit in a PLC

Looking at a stop start jog circuit in the PLC will help us in understanding the differences in hard wiring the circuit and programming.

Lets start with the basic stop stop circuit.
Here is what it looks like hard wired. (Physical switches wired to outputs devices, such as motor contactor and relays.)

When the start pushbutton (NO) is pressed the power is passed through the stop pushbutton (NC) to the control relay (CR). The CR contact closes and ‘seals in’  the start pushbutton. The start pushbutton can now be released because the CR contacts allow the power to pass through to the CR.

NO – Normally Open – This refers to the state of the input  device if nothing acts upon it. 
NC – Normally Closed – This refers to the state of the input device if nothing acts upon it.

Lets take a look at the PLC program for the above wiring diagram.

The first thing that you will notice is that the input for Stop is NO contact and not NC. This is because the actual signal wired in the input is NC and we do not want to inverse this signal. You can see that the stop input is currently on in the program.
If we hit the start pushbutton then the circuit is complete and the output CR turns on.

Letting go of the start pushbutton, the output remains on because the CR input seals in the start pushbutton.

Pressing the stop pushbutton will break the circuit and turn off CR.

Letting go of the stop pushbutton will return us back to the original state shown above.

Adding a jog input to the hard wiring diagram will look something like this:

You can see that the diagram will work the exact same as the circuit above with the start and stop pushbuttons. The jog when pushed will break the sealing contact, and then make a bypass of the start pushbutton. This will keep the M coil on as long as the jog button is pressed. Letting go of the jog will stop the bypass of the start pushbutton which will stop M coil. When the jog returns to the original state M input will already be off so it will not keep M coil on.
The action on the jog is referred to as a Break before Make device. The jog pushbutton will break the circuit before making another connection.

Sometimes in programming a PLC it can be beneficial to think of the inputs as Make before Break. Inputs are made before the previous ones are broken. The programmable controller will scan the program from left to right, top to bottom. The outputs from the rung above are available to the rungs below. Here is a previous article on PLC scanning.
Lets take a look at PLC program with a jog that will not work.

Even though this looks like it would work… Remember that the contacts in the PLC are make before break. You can jog the unit and it will turn on but as soon as you release your finger off of the pushbutton the not jog input will seal the CR in. The output will not be able to turn off.

We must consider the delay from on to off when looking at the PLC program for this circuit.
Here is a circuit that will work:

Notice that we create a delay from on to off by turning on an intermediate bit in the program.

Another way to do start stop circuits in the PLC is to use the instructions Set (SET)  and Reset (RST).
The set will have all of the conditions to turn on a bit in memory and the reset will have all of the conditions to turn off a bit in memory. These instructions are used to make the program easier to view and troubleshoot.
Here is the same logic above using the set and reset instructions.

Notice that X10 Jog2 is in parallel with the Start. We use a trailing edge one shot in parallel with the Stop. This sets our delay so the output will turn off.

Watch on YouTube :  Learn PLC Programming – Free 4

If you have any questions or need further information please contact me.
Thank you,
Garry



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.

Adjusting Daylight Savings Time In Do-More

Adjusting for daylight saving time in Do-More PLC.

When does it start and end?
Canada Daylight Saving Time begins at 2:00 am local time on the second Sunday in March. On the first Sunday in November areas on Daylight Saving Time return to Standard Time at 2:00 am local time. When Daylight Saving Time begins turn your clocks ahead one hour. This is what happens in most parts of Canada.



There are several methods in the Do-More PLC to account for Daylight Savings Time. You can use the internet time clock, manual adjustment or use an internal bit to set daylight savings time. Since websites for internet time may not always be reliable and we do not want to wake up at 2 am in the morning to set the real time clock, we will use the internal bit method.

ST768 $SummerTime Configuration
Set this bit ON to add one hour to LocalTime to account for Daylight Savings Time.

The first line of code will check for the 3rd month (March). Then ensure that the day is between 8 and 14 so that we are viewing the second week. Next make sure the day of the week is 0 (Sunday). Finally it will check to make sure the hour is 2 (2am). The ST768 $SummerTime will then be turned on to add one hour to the real time clock in the PLC.

The second line of code will check for the 11th month (November). Then ensure that the day is less than 8 first week. Next make sure the day of the week is 0 (Sunday). Finally it will check to make sure the hour is 2 (2am). The ST768 $SummerTime will then be turned off to subtract one hour to the real time clock in the PLC.

Adding this code to your existing logging information in the PLC can be helpful when determining the correct time.

If you have any questions or need further information, please contact me.
Regards,
Garry

P.S. In the contact section, send me a email and I will send you a link for the download of this code.



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.

Now You Can Have Robust Data Logging for Free – Part 12

Now You Can Have Robust Data Logging for Free – Part 12

HTML and Scripting Languages

 We have the following accomplished:
  • PLC program
  • Visual Basic Program
  • Data collected in a Database
  • IIS web service established
  • ASP Script Written
Lets take a closer look at the ASP Script ( AccRL.asp) that was written in part 11:
The <html> is at the start of the file and the </head> is at the end of the file. These tags all have to have a start and end.  The ‘/’ indicates the end of the tag.
The <head> is used to place the information for the web page. The refresh will load the page after 300 seconds (5 minutes). This way the information will always be the latest. Title is used to label the page. This is the information at the top of the browser. The SHORTCUT ICON is used for the icon at the top of the browser near the page address.
<html>

<head>
<meta HTTP-EQUIV=”Refresh” CONTENT=”300″>
<title>ACC Automation – Robust Logger</title>
<LINK REL=”SHORTCUT ICON” HREF=”http://192.168.1.3/ACC_Do.ico”/></head>

ActiveX Data Objects (ADO) is used to access databases from your web pages. ADOVBS.inc is a file that has all of the ADO constants defined.  Be sure to add this file in your root web application directory.
<!– #include virtual=”/adovbs.inc” –>

The <% and %> symbols indicate the start and finish of VBScript in the page. We dimension our variables for StartTime and EndTime. These will be used to determine how long our script took to execute.
<%
Dim StartTime, EndTime
StartTime = Timer

We dimension the variables that are used for the connection to the database file.
Dim OBJdbConnection
Dim rs1
Dim objCmd

We set up the connection to the database and determine what information we need to retrieve.
Set OBJdbConnection = Server.CreateObject(“ADODB.Connection”)

OBJdbConnection.Open “Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=C:\AccRL\data\AccRL.accdb;Persist Security Info=False;”
set rs1 = Server.CreateObject(“ADODB.recordset”)
with rs1
 .CursorType = adOpenForwardOnly
 .LockType = adLockReadOnly
 .CursorLocation = adUseServer
 .ActiveConnection = OBJdbConnection
 .Source = “SELECT * FROM Minute_Log;”
end with

Using getrows will allow us to execute the Select command and retrieve all of the information in one pass from the database.  This is the quickest method to get the information out quickly.
rs1.Open

arraytime = rs1.getrows()
rs1.close

We now write the information from the database to the page.
Response.Write arraytime(0,0) & “<br>”
Response.Write arraytime(1,0) & “<br>”
Response.Write Year(arraytime(1,0))& “/” & Right(“0” & Month(arraytime(1,0)), 2) & “/” & Right(“0” & Day(arraytime(1,0)), 2) & “<br>”
Response.Write arraytime(2,0)& “<br>”
Response.Write arraytime(3,0)& “<br>”
Response.Write arraytime(4,0)& “<br>”

The EndTime is now set and the total time it took for the process is displayed.
EndTime = Timer

Response.write “<p>Processing took “&(EndTime-StartTime)&” seconds<p>&nbsp;”
%>
</body>
</html>

Now that you have information into the database and IIS running, you can display the data in various ways.
Charts:
Graphs:
 Gauges:
This ends our robust logger design. For the complete PLC program, VB source code and web page file please send me an email and ask for the ACC Robust Logger Program. I will be happy to email you the information.
If you have any questions or need further information, please contact me.
Regards,
Garry

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
Now You Can Have Robust Data Logging for Free – Part 9
Now You Can Have Robust Data Logging for Free – Part 10
Now You Can Have Robust Data Logging for Free – Part 11
Now You Can Have Robust Data Logging for Free – Part 12




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.

Now You Can Have Robust Data Logging for Free – Part 11

Now You Can Have Robust Data Logging for Free – Part 11

HTML and Scripting Languages

 We have the following accomplished:
  • PLC program
  • Visual Basic Program
  • Data collected in a Database
  • IIS web service established
The machine that has the IIS web service must have the Microsoft Access Database Engine 2010 installed. This can be obtained by the following link:
You can select the 32 bit or 64 bit version that matches your computer.

Microsoft Access Database Engine 2010 Redistributable
Note:  If you have office installed on your machine already then you probably will already have this file.

ActiveX Data Objects (ADO) is used to access databases from your web pages. ADOVBS.inc is a file that has all of the ADO constants defined.  Be sure to add this file in your root web application directory. How to add this code to a web page is shown in the sample code below .
You can download ADOVBS.inc from this site in text format. (Just rename to ADOVBS.inc from ADOVBS.txt)
ADO Introduction:
http://www.w3schools.com/asp/ado_intro.asp

Lets set up ASP on IIS to display any error messages to our browser.
Call up Control Panel and then goto Administrative Tools. Call up Internet Information Services (IIS) Manger.

From IIS Manager, double click on ASP under IIS. Expand Debugging Properties and change the Send Errors To Browser to True.

Lets also ensure that your browser is set to display the error messages in internet explorer (IE). Call up Internet options from the main settings.

Click the setting for ‘Show friendly HTTP error messages’. This will ensure that the error messages show up in your browser.

The last part  of our project is to display the database information to the network. We do this by using a webpage. The HTML and VBScript can be writing in any editor. (Like Notepad)

There are also a great number of online editors that you can visual see what your page will look like while developing your code.
To learn more about VBScript following the link below:
Lets take a look at the AccRL.asp file:


<html>
<head>
<meta HTTP-EQUIV=”Refresh” CONTENT=”300″>
<title>ACC Automation – Robust Logger</title>
<LINK REL=”SHORTCUT ICON” HREF=”http://192.168.1.3/ACC_Do.ico”/></head>
<!– #include virtual=”/adovbs.inc” –>
<%
Dim StartTime, EndTime
StartTime = Timer

Dim OBJdbConnection
Dim rs1
Dim objCmd

Set OBJdbConnection = Server.CreateObject(“ADODB.Connection”)
OBJdbConnection.Open “Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=C:\AccRL\data\AccRL.accdb;Persist Security Info=False;”
set rs1 = Server.CreateObject(“ADODB.recordset”)
with rs1
 .CursorType = adOpenForwardOnly
 .LockType = adLockReadOnly
 .CursorLocation = adUseServer
 .ActiveConnection = OBJdbConnection
 .Source = “SELECT * FROM Minute_Log;”
end with

rs1.Open
arraytime = rs1.getrows()
rs1.close

Response.Write arraytime(0,0) & “<br>”
Response.Write arraytime(1,0) & “<br>”
Response.Write Year(arraytime(1,0))& “/” & Right(“0” & Month(arraytime(1,0)), 2) & “/” & Right(“0” & Day(arraytime(1,0)), 2) & “<br>”
Response.Write arraytime(2,0)& “<br>”
Response.Write arraytime(3,0)& “<br>”
Response.Write arraytime(4,0)& “<br>”

EndTime = Timer
Response.write “<p>Processing took “&(EndTime-StartTime)&” seconds<p>&nbsp;”
%>
</body>
</html>

Place this AccRL.asp file into the root directory of our web server. Call up the page though our browser (http:\\localhost\AccRL.asp) and the following output will be seen.
In part 12 we will break down the ASP code and modify. For the complete PLC program, VB source code and web page file please send me an email and ask for the ACC Robust Logger Program. I will be happy to email you the information.
If you have any questions or need further information, please contact me.
Regards,
Garry

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
Now You Can Have Robust Data Logging for Free – Part 9
Now You Can Have Robust Data Logging for Free – Part 10
Now You Can Have Robust Data Logging for Free – Part 11




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.

Now You Can Have Robust Data Logging for Free – Part 9

Now You Can Have Robust Data Logging for Free – Part 9

Computer Program Visual Basic (VB6) Continue

 

The final code will be completed for the program. If you want a link to download the complete code then go to the contact page and put Robust Logger Program in the description.

The actual code that will be seen will be in Italic. This way you can pick out the code from the commentary.

Private Sub Form_Load()
MbusStatus = 0
ProductionPointerNow = 10
MinutePointerNow = 660
End Sub
 
When our form loads, the MbusStatus will be set to 0. This will control all of the communications to the Do-More PLC. The ProductionPointerNow and the MinutePointerNow will be used to determine where we are in getting data.
Here are our declarations for the program.
Dim MbusQuery
Public MbusResponse As String
Dim MbusByteArray(255) As Byte
Public MbusStatus As Integer
Public ProductionPointer As Integer
Public ProductionPointerNow As Integer
Public MinutePointer As Integer
Public MinutePointerNow As Integer
Start Logging Button:
We will stop or ensure the timer between reads has been disabled.
We will then check the status of the winsock. If it is not opened and ready to send then change the background colour to indicate to the operator what is going on.
Note:  Winsock RemotePort = 502
Private Sub Command1_Click()
Timer1.Enabled = False ‘ Stop the interval between reads 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 background colour to green
Else
Text1.BackColor = &HFF ‘ Change background colour to red
Exit Sub
End If
End If
Check the status of the Winsock. If we are good to go then determine the MbusStatus (0 to 9) and either send a read or write string out to the PLC.
If (Winsock1.State = 7) Then
Select Case MbusStatus
Case 0, 2
‘Read all the Daily Production Values
MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(6) + Chr(0) + Chr(3) + Chr((Val(ProductionPointerNow) \ 256)) + Chr(((Val(ProductionPointerNow) Mod 256) – 1)) + Chr(0) + Chr(20)
Case 3
‘Reset Daily Production Pointer to 30 (Write)
MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(9) + Chr(1) + Chr(16) + Chr(0) + Chr(0) + Chr(0) + Chr(1) + Chr(2) + Chr(0) + Chr(30)
Winsock1.SendData MbusQuery
Case 4, 6
‘Read the Minute Log Pointer
MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(6) + Chr(0) + Chr(3) + Chr(0) + Chr(1) + Chr(0) + Chr(1)
Case 5
‘Read all the Minute Log Values
MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(6) + Chr(0) + Chr(3) + Chr((Val(MinutePointerNow) \ 256)) + Chr(((Val(MinutePointerNow) Mod 256) – 1)) + Chr(0) + Chr(20)
Case 7
‘Reset Minute Log Pointer to 670 (Write)
MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(9) + Chr(1) + Chr(16) + Chr(0) + Chr(1) + Chr(0) + Chr(1) + Chr(2) + Chr(2) + Chr(158)
Winsock1.SendData MbusQuery
Case 8
‘Read the current Daily Production Values
MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(6) + Chr(0) + Chr(3) + Chr(0) + Chr(9) + Chr(0) + Chr(20)
Case 9
‘Read the current Minute Log Values
MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(6) + Chr(0) + Chr(3) + Chr(2) + Chr(147) + Chr(0) + Chr(10) End Select
Winsock1.SendData MbusQuery ‘Send out the Modbus Information
Timer2.Enabled = True ‘Set the timeout timer for communications
Else
MsgBox (“Device not connected via TCP/IP”)
Exit Sub
End If
End Sub
 Retrieving the information from Winsock
 We first get all of the bytes of data from winsock. Then we determine the MbusStatus and then handle the data appropriately.
Private Sub Winsock1_DataArrival(ByVal datalength As Long)
Timer2.Enabled = False ‘Stop communications timeout timer
‘Get all the inforamtion from the data arriving
Dim B As Byte
Dim j As Byte
returnInfo = “”
For i = 1 To datalength
Winsock1.GetData B
MbusByteArray(i) = B
returnInfo = returnInfo & B
Next
j = 0
On Error Resume Next
Select Case MbusStatus
Case 0
‘Read the Daily Production Pointer
ProductionPointer = Val(Str((MbusByteArray(10) * 256) + MbusByteArray(11)))
If ProductionPointer <> 30 Then
ProductionPointerNow = ProductionPointerNow + 20
MbusStatus = 1
Else
MbusStatus = 4
End If
Case 1
With Adodc1
.CommandType = adCmdTable
.RecordSource = “Production_Log”
.Refresh
.Recordset.AddNew
End With
‘Read all the Daily Production Values
Label18.Caption = Format$((Str((MbusByteArray(10) * 256) + MbusByteArray(11)) & “/” & Str((MbusByteArray(12) * 256) + MbusByteArray(13)) & “/” & Str((MbusByteArray(14) * 256) + MbusByteArray(15))), “yyyy/mm/dd”)
Label19.Caption = Val(Str((MbusByteArray(16) * 256) + MbusByteArray(17)) & Str((MbusByteArray(18) * 256) + MbusByteArray(19)))
Label20.Caption = Val(Str((MbusByteArray(20) * 256) + MbusByteArray(21)) & Str((MbusByteArray(22) * 256) + MbusByteArray(23)))
Label21.Caption = Val(Str((MbusByteArray(24) * 256) + MbusByteArray(25)) & Str((MbusByteArray(26) * 256) + MbusByteArray(27)))
Label22.Caption = Val(Str((MbusByteArray(28) * 256) + MbusByteArray(29)) & Str((MbusByteArray(30) * 256) + MbusByteArray(31)))
Label23.Caption = Val(Str((MbusByteArray(32) * 256) + MbusByteArray(33)) & Str((MbusByteArray(34) * 256) + MbusByteArray(35)))
Label24.Caption = Val(Str((MbusByteArray(36) * 256) + MbusByteArray(37))) / 10
Label25.Caption = Val(Str((MbusByteArray(38) * 256) + MbusByteArray(39))) / 10
Label26.Caption = Val(Str((MbusByteArray(40) * 256) + MbusByteArray(41))) / 10
Label27.Caption = Val(Str((MbusByteArray(42) * 256) + MbusByteArray(43))) / 10
Label28.Caption = Val(Str((MbusByteArray(44) * 256) + MbusByteArray(45))) / 10
With Adodc1
.Recordset.Update
.Recordset.MoveLast
.Refresh
End With ProductionPointerNow = ProductionPointerNow + 20
If ProductionPointer = ProductionPointerNow Then
MbusStatus = 2
End If
Case 2
‘Read the Daily Production Pointer
ProductionPointer = Val(Str((MbusByteArray(10) * 256) + MbusByteArray(11)))
If ProductionPointer = ProductionPointerNow Then
MbusStatus = 3
Else
ProductionPointerNow = ProductionPointerNow + 20
MbusStatus = 1
End If
Case 3
‘Reset Daily Production Pointer to 30 (Write)
If (MbusByteArray(8) = 16) And (MbusByteArray(12) = 1) Then
MbusStatus = 4
ProductionPointerNow = 10
Else
Text1.BackColor = &HFF
End If
With Adodc1
.CommandType = adCmdTable
.RecordSource = “Production_Log”
.Refresh
.Recordset.AddNew
End With
Case 4
‘Read the Minute Log Pointer
MinutePointer = Val(Str((MbusByteArray(10) * 256) + MbusByteArray(11)))
If MinutePointer <> 670 Then
MinutePointerNow = MinutePointerNow + 10
MbusStatus = 5
Else
MbusStatus = 8
End If
Case 5
With Adodc2
.CommandType = adCmdTable
.RecordSource = “Minute_Log”
.Refresh
.Recordset.AddNew
End With
‘Read all the Minute Values
Label29.Caption = Format$((Str((MbusByteArray(10) * 256) + MbusByteArray(11)) & “/” & Str((MbusByteArray(12) * 256) + MbusByteArray(13)) & “/” & Str((MbusByteArray(14) * 256) + MbusByteArray(15))), “yyyy/mm/dd”)
Label30.Caption = Format$((Str((MbusByteArray(16) * 256) + MbusByteArray(17)) & “:” & Str((MbusByteArray(18) * 256) + MbusByteArray(19)) & “:” & Str((MbusByteArray(20) * 256) + MbusByteArray(21))), “hh:nn:ss”)
Label31.Caption = Val(Str((MbusByteArray(22) * 256) + MbusByteArray(23)) & Str((MbusByteArray(24) * 256) + MbusByteArray(25)))
Label32.Caption = Val(Str((MbusByteArray(26) * 256) + MbusByteArray(27)))
With Adodc2
.Recordset.Update
.Recordset.MoveLast
.Refresh
End With MinutePointerNow = MinutePointerNow + 10
If MinutePointer <= MinutePointerNow Then
MbusStatus = 6
End If
Case 6
‘Read the Minute Log Pointer
MinutePointer = Val(Str((MbusByteArray(10) * 256) + MbusByteArray(11)))
If MinutePointer = MinutePointerNow Then
MbusStatus = 7
Else
MinutePointerNow = MinutePointerNow + 10
MbusStatus = 5
End If
Case 7
‘Reset Minute Log Pointer to 670 (Write)
If (MbusByteArray(8) = 16) And (MbusByteArray(12) = 1) Then
MbusStatus = 8
MinutePointerNow = 660
Else
Text1.BackColor = &HFF
End If
With Adodc2
.CommandType = adCmdTable
.RecordSource = “Minute_Log”
.Refresh
.Recordset.AddNew
.Refresh
End With
Case 8
‘Read the current Daily Production Values
Label18.Caption = Format$((Str((MbusByteArray(10) * 256) + MbusByteArray(11)) & “/” & Str((MbusByteArray(12) * 256) + MbusByteArray(13)) & “/” & Str((MbusByteArray(14) * 256) + MbusByteArray(15))), “yyyy/mm/dd”)
Label19.Caption = Val(Str((MbusByteArray(16) * 256) + MbusByteArray(17)) & Str((MbusByteArray(18) * 256) + MbusByteArray(19)))
Label20.Caption = Val(Str((MbusByteArray(20) * 256) + MbusByteArray(21)) & Str((MbusByteArray(22) * 256) + MbusByteArray(23)))
Label21.Caption = Val(Str((MbusByteArray(24) * 256) + MbusByteArray(25)) & Str((MbusByteArray(26) * 256) + MbusByteArray(27)))
Label22.Caption = Val(Str((MbusByteArray(28) * 256) + MbusByteArray(29)) & Str((MbusByteArray(30) * 256) + MbusByteArray(31)))
Label23.Caption = Val(Str((MbusByteArray(32) * 256) + MbusByteArray(33)) & Str((MbusByteArray(34) * 256) + MbusByteArray(35)))
Label24.Caption = Val(Str((MbusByteArray(36) * 256) + MbusByteArray(37))) / 10
Label25.Caption = Val(Str((MbusByteArray(38) * 256) + MbusByteArray(39))) / 10
Label26.Caption = Val(Str((MbusByteArray(40) * 256) + MbusByteArray(41))) / 10
Label27.Caption = Val(Str((MbusByteArray(42) * 256) + MbusByteArray(43))) / 10
Label28.Caption = Val(Str((MbusByteArray(44) * 256) + MbusByteArray(45))) / 10
With Adodc1
.Recordset.Update
.Recordset.MoveLast
End With MbusStatus = 9
Case 9
‘Read the current Minute Log Values
Label29.Caption = Format$((Str((MbusByteArray(10) * 256) + MbusByteArray(11)) & “/” & Str((MbusByteArray(12) * 256) + MbusByteArray(13)) & “/” & Str((MbusByteArray(14) * 256) + MbusByteArray(15))), “yyyy/mm/dd”)
Label30.Caption = Format$((Str((MbusByteArray(16) * 256) + MbusByteArray(17)) & “:” & Str((MbusByteArray(18) * 256) + MbusByteArray(19)) & “:” & Str((MbusByteArray(20) * 256) + MbusByteArray(21))), “hh:nn:ss”)
Label31.Caption = Val(Str((MbusByteArray(22) * 256) + MbusByteArray(23)) & Str((MbusByteArray(24) * 256) + MbusByteArray(25)))
Label32.Caption = Val(Str((MbusByteArray(26) * 256) + MbusByteArray(27)))
With Adodc2
.Recordset.Update
.Recordset.MoveLast
End With
MbusStatus = 0
End Select
Timer1.Enabled = True ‘Set the interval between the next communication
End Sub
The last thing that we do is save and compile the VB program. I will be happy to send the complete program to you . Please go to the contact page and put Robust Logger Program in the description.
In part 10 we will display the information on a web server. We will use IIS and ASP to actively connect and display the information in the database.
If you have any questions or need further information, please contact me.
Regards,
Garry

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
Now You Can Have Robust Data Logging for Free – Part 9




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.