Monday, December 15, 2014

New Location

Now You Can Have Robust Data Logging for Free - Part 10

We have moved the site to the following address:

ACCautomation.ca
If you have subscribed to emails when new posts are created, please do so again on the new site.
We hope that you will continue to find benefit from the new improved site.

Thank you,
Garry

Saturday, December 6, 2014

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

We have moved the site to the following address:

ACCautomation.ca

If you have subscribed to emails when new posts are created, please do so again on the new site.
We hope that you will continue to find benefit from the new improved site.

Thank you,
Garry

Sunday, November 30, 2014

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:
ConstantValueDescription
sckClosed0Default. Closed
sckOpen1Open
sckListening2Listening
sckConnectionPending3Connection pending
sckResolvingHost4Resolving host
sckHostResolved5Host resolved
sckConnecting6Connecting
sckConnected7Connected
sckClosing8Peer is closing the connection
sckError9Error

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.
Regards,
Garry

Saturday, November 22, 2014

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 CodeActionTable Name
01 (01 hex)ReadDiscrete Output Coils
05 (05 hex)Write singleDiscrete Output Coil
15 (0F hex)Write multipleDiscrete Output Coils
02 (02 hex)ReadDiscrete Input Contacts
04 (04 hex)ReadAnalog Input Registers
03 (03 hex)ReadAnalog Output Holding Registers
06 (06 hex)Write singleAnalog Output Holding Register
16 (10 hex)Write multipleAnalog 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.
Regards,
Garry

Sunday, November 16, 2014

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:\AccRL\Data\AccRL.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:\AccRL\Data\AccRL.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.
Regards,
Garry

Saturday, November 8, 2014

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/vb6/vbtutor.html
http://www.vb6.us/guides/visual-basic-6-beginners-guide
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.
http://www.rtaautomation.com/wp-content/cache/supercache/www.rtaautomation.com/technologies/modbus-tcpip/

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.
Regards,
Garry

Thursday, November 6, 2014

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.

Sunday, November 2, 2014

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

Saturday, November 1, 2014

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
http://www.automationdirect.com/adc/Overview/Catalog/Programmable_Controllers/Do-more_Series_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

Saturday, October 18, 2014

Now You Can Have Robust Data Logging for Free - Part 1

Robust PLC Data Logger

With traditional loggers, software will read the memory of the PLC and store in a local computer. If the network stops or the PLC communication fails then the logging will stop.
Creating a robust PLC data logger allows the communication to be stopped for a period of time without losing any of the data for collection. This is accomplished by storing the data locally on the PLC until communication is restored. All of the data is then read without loss. The amount of time that the connection can be lost will be dependent on the memory size of the PLC and the frequency of the data collected.

This series will walk you through the steps to create and implement a robust PLC data logger using the following equipment and hardware.
  • Automation Direct - Do-More - H2-DM1E PLC (Ethernet Modbus TCP)
  • Do-more Designer 1.3 (Simulator instead of PLC mentioned above)
  • Windows based computer running IIS
  • Visual Basic 6

The following steps will be explained in details and sample programming.

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.

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.

Data Distribution
We will set up a web server (IIS). This will allow the access database containing the information from the PLC to be available to all of the computers on the local network. (Intranet)
We will use Active Server Pages (ASP) and HTML to create programs to access this database information. Web browsers will call our ASP and HTML program so the information can be displayed on the device. This will be universal when we look at it with computers, tablets and phones.

Advanced Data Distribution
Using Raphael and SVG programming, we will graph using line graphs. We will also see how we can use dials to create dashboards on our web server.


This may sound like allot of work to do, but it is not. What we are doing is breaking down the fundamentals to display information. Using a robust logging system from the PLC ensures the reliability and your confidence of the data collected. Once the basic principles are applied, your system can expand rapidly.

Are you ready?

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

Sunday, October 12, 2014

... and I also do PLC programming.

Programmable Logic Controller (PLC) programming is often thought as something everyone can do easily. We often design the system, install the hardware and then start to think about the PLC program and programmers. This approach can be improved. The landscape of PLC programming is changing and we must also change.

Computer Programming / PLC Programming
I believe that with all of the new functions of the PLC processor, you would be better served by someone that can do additional computer programming. Ladder logic has been taught in our schools for about 20 years or more. The basic bit programming in ladder is easily understood. Connecting to the manufacturers dedicated software  shows the power flow from left to right and shows the logic solved from top to bottom.

Some applications are fine if you are just replacing a few relays, however today's manufacturing floor must be integrated. The existing hardware in the plant must also be connected to the PLC system. This will allow connection of data logging, email, vision system, motion control, HMI, computer servers, etc.
Ladder logic and the standardization of PLC's on the plant floor has long been a topic for discussion and debate. The benefits were that anyone can look and understand the PLC logic to troubleshoot the system. Today the PLC can do allot more. Visually it can indicate /display its own troubleshooting and diagnostics to the engineer, electrician and/or operator in a variety of ways. You no longer need the skills on the plant floor all of the time. Using HMI (Human Machine Interface), computer screens, indication lights and email, just to name a few, information can be passed for troubleshooting and diagnostics. The investment in the program and integration of the system in your plant will pay for itself time and time again.

I believe that PLC programmers need more than just this programming language. They must have network and high level language skills to be capable of integrating the entire plant floor.

Let me know what you think? Are we teaching the new generation the right way?
Garry

Sunday, October 5, 2014

Changing Landscape of PLC Programming

Today's new processing and networking power the future looks bright for programmable logic controllers and it's programming. This has allowed the role of the PLC to expand.

System Design:

The PLC design has changed significantly. Computer processing power has now added the following to programmable controllers:

  • Micro USB slots (Data Storage)
  • Ethernet ports 
  • WiFi 
  • RS232 / RS422 / RS485 (Serial Ports) 
  • Canbus
  • Profibus
  • DeviceNet
  • Several digital I/O bus systems like ASi Bus
System design more than ever is done by asking even more question on what is required when installing a PLC system. 
Traditional Questions to Ask:
  • Number of input signals? Voltage levels? (Discrete on/off inputs.)
  • Number of output signals? Voltage levels? (Discrete on/off outputs.)  
  • Number of analog input signals? Voltage and/or Current levels?
  • Number of analog output signals? Voltage and/or Current levels?
  • Operator Interface required? HMI - Human Machine Interface - This is now a touch or function key LCD or LED screen.
  • Etc.
Additional Questions to Ask:
  • Drives / Motors  - What are you connecting to and the communication system required?
  • Computer network - Will this join your computer network? What is the connection cable and communication protocol?
  • Do you need data collection?
    • Do you need data displayed and/or controlled on a remote device such as a tablet or phone?
  • Do you need email and/or text messages sent out by the PLC?
  • Etc.

Programming:

PLC
There has been a movement to standardize PLC programming. IEC 61131-3 is the standard for PLC programming. It defines three programming methods:
  1. Ladder Diagram - Graphical structure 
  2. Function Block Diagram - Graphical structure
  3. Structured Text - Textual structure
  4. Instruction List - Textual structure
  5. Sequential Function Chart - Graphical and Textual structure
The above methods to program PLC's all will do a good job. It depends on how you were originally taught about programming and the experience that your have. Not all PLC's will be able to program in the 5 different ways. Some will only provide a couple. You will have to see the programming manual of the make and model of the PLC that you want to program.

IEC 61131-3 is good, however this does not mean that every programmable controller will program the same way. It will look familiar between programming ladder in AB vs Siemens vs Omron vs Direct Automation, but the key strokes in the software will be different. Manufactures in my opinion will not come to an agreement to have the software exactly the same for all PLC programming. Why should they take away from their market share?

HMI - Human Machine Interface
Just about every manufacturer's HMI screen will be programmed with different software. Due to the proprietary nature of communications, I would always use the manufacturers HMI with their PLC. The communications is usually direct to the memory areas, and faster response time.

Computer
I believe it is always best to have some computer background information. All of our lives are based upon desktop, laptop, tablets and smart phones. Each of these will have an operating system like Windows, iOS, Android etc.
Higher level languages such as Visual Basic (VB6) will give you the ability to run self contained programs that can install on a computer and communicate to the network. I have used this to retrieve information out of the PLC's on the production floor and save this information into a database.
The computer languages are not always the easiest to learn, but with the tutorials and information on the web this becomes easier. Once you learn one language well, then this will create a building block of knowledge for you to understand even more.
Microsoft Visual Studio is a free download and fully functional computer environment. This will include the latest visual basic product. 

Computer Network
The ability to share information in the company is important. You cannot find a manufacturing plant without a computer network. This is usually confined to the 'front office' and is for email, engineering and accounting. We need to get the information from the plant floor to everyone on the Intranet and/or Internet. This can be done through setting up a web server and using basically HTML and ASP to deliver real time data to the network from the PLC.
http://www.w3schools.com/
W3school has help me to deliver real time data via email and web pages to the computer network.
HTML stands for hyper text markup language and is used for all web pages.
ASP stands for active server pages and is used to communicate from a database to web pages.
HTML, ASP, Javascript, VBscript, etc are all languages that are used to define information that gets shared on a computer network through a web server via a web client.



We have an abundance of information and ways to learn programming. The language and way will change depending on what you want to do. PLC programming is not just the logic behind discrete input and outputs on a machine, it is the entire system. It is the sharing and use of information for the organization.
I believe that we are going and growing in the right direction with information sharing...

How do you see this change?
Let me know.
Garry

Sunday, September 28, 2014

Is Manufacturing Dead In Canada? Not so!

Everywhere you look there are signs of doom for Canadian Manufacturing. Unemployment rate, companies moving or going out of business seems to be a common theme. However we have is an increase in manufacturing output.

How is manufacturing jobs disappearing and output increasing?


Investment in the business


Take a look around. Businesses that are investing in themselves will have the staying power. Those that do not are going to be left behind, wither and die.
How is your company doing?

People
We often hear that people are the greatest asset for the business. What is the game plan? When asked to see or inquire about how they are advancing there employees; you get blank faces. A constant learning environment must be established.
The learning environment includes:

  • How individuals interact with and treat one another. 
  • How information is conveyed 
    • Internet 
    • Intranet
    • Meetings
    • Teams
    • Postings
  • Knowledge of individual contributions
    • Strengths and Weaknesses
  • Recognize how individuals learn (Example: Millennials do not get information from an authority figure.)
    • Customize leaning for individuals

Process
Look at your process from a new born perspective. Inquire and explore why things have to happen in a certain way. Break every step down.
Kipling wrote:
I keep six honest serving men. They taught me all I knew. Their names are What and Why and When And How and Where and Who.
Query your people with questions and listen.

  • If they had more time, what would they work on?
  • What is there biggest challenge?
  • What is bugging them?
  • Are you happy?

Machine
Keep up on the latest machine innovations for your industry as well as others. Know the limitations of each machine. Table new concepts to your learning environment.
If you are to fix the machine then ask

  • Is this the first time this has happened? Will it happen again?
  • How long did it take to troubleshoot the problem? 
  • Is there something we can improve upon?
  • How can this knowledge be shared with operators, maintenance, management?

Automation
There is a reason that this is last on the list. Automation can stand by itself, but it really requires an understanding of each of the items mentioned above before it is successful.
You must understand your people, process and machine before automation can prove to be an asset.


Automation, people, process and machine innovation can happen. It is up to you.

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

Reference:
Statistics Canada for Manufacturing
http://www5.statcan.gc.ca/cansim/a33?lang=eng&spMode=mainTables&themeID=4005&RT=TABLE