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

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. Lets discuss how the logic will work.

1. User selects ‘Start Logging’
2. The timer for 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. 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
Once the command is sent a timer is set to determine if communications has been lost.
5. If the timer for communications is lost, goto step 3. Repeat the last command.
6. Turn off the timer to determine if communications has been lost. Read the information from the winsock tool. If the data needs to be stored, then update the database. Set the timer for interval between communications.

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

Timer1 is used to control the amount of 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 background colour to green
    Else
       Text1.BackColor = &HFF ‘ Change background colour 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:

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 Peer is closing the connection
sckError 9 Error
Here is the information that we will need to read and write to the MHR registers in the Do-More PLC.

‘ Read the information

‘0000:    Transaction Identifier
‘0000:    Protocol Identifier
‘0006:    Message Length (6 bytes to follow)
’00:      The Unit Identifier
’03:      The Function Code (read MHR Read Holding Registers)
‘0000:    The Data Address of the first register
‘0002:    The number of registers to write
‘ Write the information
‘0000:    Transaction Identifier
‘0000:    Protocol Identifier
‘0009:    Message Length (6 bytes to follow)
’01:      The Unit Identifier
’16:      The Function Code (read Analog Output Holding Registers)
‘0000:    The Data Address of the first register
‘0001:    The number of registers to write
’02:      The number of data bytes to follow
‘0030     The number to put into the register
All of the information will be bytes of data. The maximum value in a byte is 256. If we need to send a value of 600 then the two bytes of data will be:
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.
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.

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

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

 

Computer Program Visual Basic (VB6) Continue

We have started our VB program and have set up our Adodc connections to the database. Lets continue by setting the labels up with the Adodc connections. Then we will set up the communications to the Do-More PLC and put information into our Access 2007 (*.accdb) database. (AccRL.accdb)

Select all of the labels that will be for the Production_Log table and set the properties. Under DataSource select Adodc1. Do the same thing for all the labels under the Minute_Log table.

Now go through each of the labels and select the DataField that it represents. Do this for both the Production_Log table and the Minute_Log table.
Note: You can also set the format in which the field will display

We now have our basic display set up in visual basic. The last thing that we will do is add a text box and command buttons to control the logging of the information.

A text box is added to enter the IP Address of the PLC.
A Command1 command button is added to start the logging of the information.
A Command2 command button is added to stop the logging of the information.
We now have everything on the dispay that we will need for the program.
Lets now take a look at the modbus protocol.

http://www.simplymodbus.ca/TCP.htm

All Modbus Commands:

Function Code Action Table Name
01 (01 hex) Read Discrete Output Coils
05 (05 hex) Write single Discrete Output Coil
15 (0F hex) Write multiple Discrete Output Coils
02 (02 hex) Read Discrete Input Contacts
04 (04 hex) Read Analog Input Registers
03 (03 hex) Read Analog Output Holding Registers
06 (06 hex) Write single Analog Output Holding Register
16 (10 hex) Write multiple Analog Output Holding Registers
Due to Homeland Security the automation direct Do-More PLC will allow only the MHR area of memory to be written and read. Since this controller resides on a network and can be connected to the internet, this makes perfect sense. So the only function codes that we will be using will be 03 Read and 16 Write.
A review of the numbering systems can be found on a previous blog here.

Here is what we have to send to the PLC. (In this example we will read registers.)
00 – Transaction ID
00 – Protocol ID
06 – Length of message words
0 – Unit ID (Default)
3 – Function Code (Read) 10hex – Write
10 – Data bits (In this case the number of registers to read)
We will receive what we sent out plus the data requested.
Note: The rest of the network protocol will be handled by TCP/IP. All of the error checking is also handled by the network.

In part 8 we will continue with writing the VB6 program. We will start to put everything together in the program using code.
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.

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

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

Computer Program Visual Basic (VB6)

We have looked at what VB is and discussed what we need to do in order to get the information out of the Do-More PLC and into an Access 2007 (*.accdb) database.
We will start by setting up the database. It will have the following two tables, Production_Log and Minute_Log. Please refer back to the data that we are storing in the PLC in Part 5.
Using Access create the two tables (Production_Log / Minute_Log) Name each record in the logs according to the data that we will be retrieving from the PLC.
See tables below.
The database will be named AccRL.accdb. This is an access 2007/2010 database.
We will store the database in the following directory:
C:AccRLDataAccRL.accdb
The visual basic program file will be in the C:AccRL directory.

Now lets start the visual basic programming:
Start a new project save it as AccRL in the directory mentioned above.

Add the Microsoft Winsock Control 6.0 component to the project. This will be needed to communicate through Ethernet to our PLC on the network.

Add the Microsoft ADO Data Control 6.0 (OLEDB) component to the project. This is required to communicate to the AccRL.accdb file created above.

This is what our program form looks like now.

We can now draw labels on our form for all of the data that we wish to display. Fonts sizes etc can all change based upon how you would like it to appear.
Note: Everything shown on the form are labels for the data. This program will just display the information that is being retrieved from the PLC.

Along the bottom of the form you will notice that the Winsock control, two Adodc controls and a timer have been added.
The Winsock control will be setup during the running of the program. On the form will will add a variable to tell the IP address of the PLC. We will deal with it after the database information has been setup.
Each of the Adodc controls represent the two tables set up earlier. Adodc1 is for the Production_Log table and Adodc2 is for the Minute_Log.
Lets now set up Adodc1.
Right click the control and select properties.

Select the ‘Use Connection String’ and click on Build.
Select ‘Microsoft Office 12.0 Access Database Engine OLE DB Provider’ and then click Next.

We will now enter where the data source is located. C:AccRLDataAccRL.accdb
Click ‘Test Connection’

If the connection is good you will receive the following message. If not please check the location of the data source and provider information mentioned earlier.

The last step is to set the table in the database.

Go back to the Property Page and select the RecordSource tab. The command type will be set for ‘2 – adCmdTable’ and the Table or Stored Procedure Name will be ‘Production_Log’. You will notice that you will only be able to choose between the Production_Log and Minute_Log because they are the only two tables in the database file.
Now repeat the same steps and set up the Adodc2 for the Minute_Log table of the database.

In part 7 we will continue with writing the VB6 program.
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.

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

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

Computer Program

We will now start to write a program in visual basic. (VB) Visual Basic is a product by Microsoft. It was developed to allow programs to be easily written. It is the most widely used computer programming language. Visual Basic was developed after Basic. Basic was used before the world was introduced to Windows.
There are several versions of Visual Basic. Visual Basic was always backward compatible. This means that code written in it can be easily used in the new version. In 2005, VB.net was introduced which was not compatible with previous versions but opened up a whole new computer architect for programmers. We will use VB6 for our Robust Data Logging to the Do-More Controller.

The following links can be used for training on VB6:
http://www.vbtutor.net/vbtutor.html
http://www.vbtutor.net/vbtutor.html
Learning Visual Basic 6 Programming: Lesson 1
YouTube is also a great resource for learning how to program in VB.


Data Collection
Visual Basic 6 will be used to log the data into a database. The information will be collected using Modbus TCP communication to the Do-More PLC and/or Simulator of the Do-more Designer. This will use an Ethernet communication cable to the PLC. The program will read the indirect address pointers in the PLC. It will then read the information collected and store the information into an Access Database. The indirect address pointers will then be reset by the program.

The access database is 2007 and has an extension of ‘.accdb’. Here are two videos that show how we connect to a database, read, write, and delete records.
VB6 – How to connect ADO with MSAcess 2007 (*.accdb) Database – Tutorial 1
VB6 – How to connect ADO with MSAcess 2007 (*.accdb) Database – Tutorial 2

Here is a link on the Modbus TCP protocol with a good overall introduction and explanation. A video is also included on the page.
https://www.youtube.com/watch?v=E1nsgukeKKA

Here are the locations for the information in the programmable logic controller:

Daily Production Log Pointer

MHR1 is the porinter for the daily production log. It will point to the location to store the next series. (Next Day of Data)
MHR1 = 30 means that we are all data has been retrieved.
MHR1 = 650 means that we have 31 days of data to be retrieved.
A visual basic program will read MHR1. If it is greater than 30 then the data will be read and then written into a database. It will then write the value of 30 back into MHR1 to reset the pointer.
Current values are located here:
MHR10 – Year (XXXX)
MHR11 – Month (XX)
MHR12 – Day (XX)
MHR13 – Weekend 12am Meters MSW (Most significant word)
MHR14 – Weekend 12am Meters LSW (Least significant word)
MHR15 – Weekend 12pm Meters MSW
MHR16 – Weekend 12pm Meters LSW
MHR17 – Weekday 12-8am Meters MSW
MHR18 – Weekday 12-8am Meters LSW
MHR19 – Weekday 8-4pm Meters MSW
MHR20 – Weekday 8-4pm Meters LSW
MHR21 – Weekday 4-12pm Meters MSW
MHR22 – Weekday 4-12pm Meters LSW
MHR23 – Weekend 12am Utilization % (xxx.x)
MHR24 – Weekend 12pm Utilization % (xxx.x)
MHR25 – Weekday 12-8am Utilization % (xxx.x)
MHR26 – Weekday 8-4pm Utilization % (xxx.x)
MHR27 – Weekday 4-12pm Utilization % (xxx.x)
Run Minute_Logger
MHR2 – Pointer – Value 670 to 2000
MHR660 – MHR669 – Current logged values
MHR660 – Year – xxxx   MHR661 – Month – xx   MHR662- Day – xx
MHR663 – Hour – xx   MHR664 – Minute – xx   MHR665- Second – xx
MHR666 – MHR667 – Current Meters – xxxxxxxx
MHR668 – Current Rate – xxxxx mpm

In part 6 we will continue with the VB6 program of getting the information out of the PLC and putting it into a database.
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.

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

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

PLC program – Continue

In part 3 we finished logging the daily information in the PLC. We will now log minute by minute information in the PLC memory for retrieval. Similar steps will be taken, but we no longer have to track shift by shift information.
This is where the amount of memory used in the controller can be great. The Do-More PLC will allow you to allot more memory to areas in the configuration menu.

We will leave this at the default setting in our project. Remember that this can be modified at any time if you wish to increase the amount of information logged.

Run Minute_Logger
MHR2 – Pointer – Value 670 to 2000
MHR660 – MHR669 – Current logged values
MHR660 – Year – xxxx   MHR661 – Month – xx   MHR662- Day – xx
MHR663 – Hour – xx   MHR664 – Minute – xx   MHR665- Second – xx
MHR666 – MHR667 – Current Meters – xxxxxxxx
MHR668 – Current Rate – xxxxx mpm
Internal used bits –
D40 – D49 / V2

We will start off by looking at the log pointer.

Minute Log Pointer
MHR2 is the porinter for the minute production log. It will point to the location to store the next series. (Next Minute of Data)
MHR2 = 670 means that we are all data has been retrieved.
MHR2 = 2000 means that we have 133 minutes of data to be retrieved.
A visual basic program will read MHR2. If it is greater than 670 then the data will be read and then written into a database. It will then write the value of 670 back into MHR2 to reset the pointer.
Current values are located here:
MHR660 – MHR667

After 133 minutes (~2 hours) without communication to the programmable logic controller, the data will be lost. You may wish to increase the memory area as mentioned above. This will change the MHR area so your reset value will have to change from 2000 to your new setting.

Log Time Parameters
MHR660 – Year
MHR661 – Month
MHR662 – Day
MHR663 – Hour
MHR664 – Minute
MHR665 – Second

This area sets up the real time clock. (RTC) The format is as follows: YYYY MM dd hh mm ss.

Meters
For testing purposes a 50ms internal timer is used. The count input should be activated on the leading edge if you remove the 50ms internal timer.

D19 contains the length per pulse of the counter. In our case D19 = 303
With each pulse of the input, D40 increments by 303. There for after 10 pulses the value in D40 will be 3030. This would represent 3.030 meters of product.
To change this into an integer to log the data we will divide D40 by 1000 and store the result in D41.
D41 will now contain the total meters for the shift. This is a 32 bit address location and we want the results to be in a 16 bit address location. (D vs MHR)
Using some math we split our total meters into the most significant 4 digits and the least significant 4 digits.
MHR666 – MHR667 – Current Meters – xxxxxxxx
D41 divided by 10000 will be placed into MHR666. Ex. 12345678 / 10000 = 1234
D41 minus ((Int(D41/10000)) *10000) will be placed into MHR667.
Ex. 12345678 – ((Int(12345678/10000))*10000) = 12345678 – 12340000 = 5678


Rate
This is the rate per minute. (MPM)
Samples are taken once per minute.

D40 – Current Meters
D42 – Last Minutes Meters
D43 – Meters passed since the last minute
MHR668 – Meters per minute (Rate)
If the current meters is greater than the last minute meters then subtract the last minute meters from the current meters and store it in the meters passed since the last minute.If not do the opposite. This will ensure that a negative number is not obtained. The meters passed since the last minute are then divided by 1000 so we are only looking at the integer of the number.

This finishes the PLC programming. In part 5 we will continue by getting the information out of the PLC.
If you have any questions or need further information, please contact me.
Regards,
Garry

To get a copy of the entire program. Please contact me in the contact section. I will be more than happy to send you the program. Put ‘Robust Logger’ in the subject line.




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 3

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

PLC program – Continue

We have created our shift bits, shift total seconds, shift seconds for the program.
Here is the setup for the daily log information: This is where all of the current values will be stored.

Daily Log Information
MHR10 – Year (XXXX)
MHR11 – Month (XX)
MHR12 – Day (XX)
MHR13 – Weekend 12am Meters MSW (Most significant word)
MHR14 – Weekend 12am Meters LSW (Least significant word)
MHR15 – Weekend 12pm Meters MSW
MHR16 – Weekend 12pm Meters LSW
MHR17 – Weekday 12-8am Meters MSW
MHR18 – Weekday 12-8am Meters LSW
MHR19 – Weekday 8-4pm Meters MSW
MHR20 – Weekday 8-4pm Meters LSW
MHR21 – Weekday 4-12pm Meters MSW
MHR22 – Weekday 4-12pm Meters LSW
MHR23 – Weekend 12am Utilization % (xxx.x)
MHR24 – Weekend 12pm Utilization % (xxx.x)
MHR25 – Weekday 12-8am Utilization % (xxx.x)
MHR26 – Weekday 8-4pm Utilization % (xxx.x)
MHR27 – Weekday 4-12pm Utilization % (xxx.x)

The real time clock can be populated by the following:
Note that the format is 2014 11 01 (yyyy mm dd) This will be important when setting up the database for the data.

We will determine the total meters per shift. Remember that our counter will give us one pulse every 0.303 meters.

Shift Meters – Weekend 12am
For testing purposes a 50ms internal timer is used. Also the count input should be activated on the leading edge, if the 50ms internal timer is removed.

D19 contains the length per pulse of the counter. In our case D19 = 303
With each pulse of the input, D20 increments by 303. There for after 10 pulses the value in D20 will be 3030. This would represent 3.030 meters of product.
To change this into an integer to log the data we will divide D20 by 1000 and store the result in D30.
D30 will now contain the total meters for the shift. This is a 32 bit address location and we want the results to be in a 16 bit address location. (D vs MHR)
Using some math we split our total meters into the most significant 4 digits and the least significant 4 digits.
MHR13 – Weekend 12am Meters MSW (Most significant word)
MHR14 – Weekend 12am Meters LSW (Least significant word)

D30 divided by 10000 will be placed into MHR13. Ex. 12345678 / 10000 = 1234
D30 minus ((Int(D30/10000)) *10000) will be placed into MHR14.
Ex. 12345678 – ((Int(12345678/10000))*10000) = 12345678 – 12340000 = 5678
The same calculation will be used for the other 4 shifts.
The shift percent will now be calculated. Remember that D0 contained the total seconds that have passed on the shift and D10 contains the total seconds that the machine was running. This is for weekend 12am shift.
MHR23 – Weekend 12am Utilization % (xxx.x)
To determine the shift percent to one decimal we will do the following math:
(D10 * 1000)/D0
Ex. If we want one decimal place in the output register then looking at 75% this should be equal to the value of 750 in the output channel.
(75 *1000)/100 = 75000/100 = 750
The same calculation will be used for the other 4 shifts.
Now that we have all of the data in the registers we are now ready to log this information when the day changes. That is when the weekend 12am or weekday 12-8am shift bit turns on.
 
Daily Production Log Pointer
MHR1 is the porinter for the daily production log. It will point to the location to store the next series. (Next Day of Data)
MHR1 = 30 means that we are all data has been retrieved.
MHR1 = 650 means that we have 31 days of data to be retrieved.
A visual basic program will read MHR1. If it is greater than 30 then the data will be read and then written into a database. It will then write the value of 30 back into MHR1 to reset the pointer.
Current values are located here:
MHR10 – MHR27 – As shown above.
Information will be logged for 31 days without communication from the computer program to reset the log pointer.
This is all the requirements for logging the daily information in the PLC. We will now log minute by minute information in the next part.

We will finish the PLC programming in part 4 and then continue onto getting the information out of the PLC.
If you have any questions or need further information, please contact me.
Happy Programming,
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.

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

Now You Can Have Robust Data Logging for Free – Part 1
Now You Can Have Robust Data Logging for Free – Part 2 

PLC program 

The programmable logic controller PLC will log the data in the PLC memory using indirect addressing for the data log. Information will be collected based upon shifts.
We will use the following shift schedule. Midnight, Afternoon and Days for the weekday and have two weekend shifts. Each shift will show amount of product made, utilization of the machine and rate of product made.
Also we will log a minute by minute account of the machine. This will log the amount of product made and the rate at which it is made. We can then graph the machine performance to determine if it is running correctly.

Hardware:
Do-More Designer
https://www.automationdirect.com/adc/Shopping/Catalog/Programmable_Controllers/Do-more_Series_(BRX,_H2,_T1H)_PLCs_(Micro_Modular_-a-_Stackable)
We will demonstrate everything in the PLC simulator, but the hardware would be the following:

  1. Qty 1 – H2-DM1E – Do-more PLC H2 series CPU module, three built-in communications ports: (1) RS-232 port; (1) USB port; (1) Ethernet port
  2. Qty 1 – D2-03B-1 (110/220 VAC) 3-slot base (includes power supply)
  3. Qty 1 – D2-08ND3 – 8 pt. 12-24 VDC current sinking/sourcing, 1 common (2 common terminals), removable terminal

Software:
The software will be broken down into several elements. Understanding each element and how it relates to the program is important.

Shift Bits- These are the shifts that employees will work.
C0 – Internal Bit – Weekend – 12 – 12am
C1 – Internal Bit – Weekend – 12 – 12pm
C2 – Internal Bit – Weekday – 12- 8am
C3 – Internal Bit – Weekday – 8 – 4pm
C4 – Internal Bit – Weekday – 4- 12pm

Total Shift Seconds – This is the number of seconds that have elapsed on each shift. If the PLC was not in run mode then this would not function. This will be used to determine the percentage of the shift that the machine was running.
D0 – Total Shift Seconds – Weekend 12-12am
D1 – Total Shift Seconds – Weekend 12-12pm
D2 – Total Shift Seconds – Weekday 12-8am
D3 – Total Shift Seconds – Weekday 8-4pm
D4 – Total Shift Seconds – Weekday 4-12pm
Note: 8 hour shift = 8 x 60 x 60 = 28800 seconds
         12 hour shift = 12 x 60 x 60 = 43200 seconds
Shift Seconds Reset – Use the leading edge of the shift bit to reset the shift seconds and the total shift seconds.

Next we have to determine if the machine is running or not. If it is running then count the number of seconds for the shift.
The input X0 is a signal off of a proximity sensor for a length counter. Every pulse of the input will represent 0.303 meters of product.

Machine Running Bit:
Determine if the machine has stopped. If the count input stops counting for 2 seconds then the output stop bit turns on.
Timers are used for both the on and off condition of the input. The input can stop when the input is on or it can stop when the input is off.
Stop Bit – C10 – Will be on if the machine has stopped counting

Shift Seconds – This is the total number of seconds that the machine has run for each shift.
D10 – Shift Seconds – Weekend 12-12am
D11 – Shift Seconds – Weekend 12-12pm
D12 – Shift Seconds – Weekday 12-8am
D13 – Shift Seconds – Weekday 8-4pm
D14 – Shift Seconds – Weekday 4-12pm

We will stop here and continue the PLC program in part 3.
If you have any questions or need further information, please contact me.
Happy programming,
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.