Simple PC – PLC Communications Part V - Expect The Unexpected

. Saturday, November 8, 2008

The handshake used for PC – PLC communication works well if everything is perfect. But what happens if something happens that violates the handshake?


In some countries power loss is an ordinary part of life. Generally PC is supplied by UPS, but PLC is not. In a power loss, PLC lefts the communication unexpectedly.


Even if you are using an industrial PC, it is not stable as a PLC. PC or the software running on PC may be frozen. In this case, PC or software may need a restart.


In the other hand, physical conditions may also violate the handshake. Imagine that boxes crashing on station:





It is possible; sensors may be dirty or defected, or any other unexpected reason may cause this.

So, how can we restore the stable cycle again?

Most PLC systems use non-volatile memory for holding data permanently. For a PLC system, it is not difficult at all.

If we are programming the PC, it is obvious that we have to store some information in a file or in database to avoid failure after power loss.

    If we say as a rules of thumb:
  1. Store all global variables (handshakes last time interval, all counters etc. and the most important; the last data you wrote in to PLC) in to a text file or database as soon as they changed.

  2. Restore all global variables on start up.

  3. Do not execute 'Write all outputs' before restoring all global variables.

For obeying rule 1, you can use 'Property' in addition to a global variable. Think the 'Property' as a global variable, however it is possible to execute defined subroutines when property is read or write.


VB6.0 example:

Public Property Get Data As Integer
Data = m_Data
End Property



Public Property Let Data(ByVal New_Data As Integer)
m_Data = New_Data
SaveProperty (m_Data,"Data") 'Save routine for recording Data
End Property

'Get' routine is executed whenever you attempt to read property 'Data' as

A = Data

or

MsgBox Data

And 'Let' routine is executed whenever you attempt to write property 'Data' as:

Data = 5


or


Data = Text1.Text

Use 'Property' as a global variable, add a record routine inside 'Let' and never mind again.


For the example above, restoring the 'm_Data' global variable instead of restoring 'Data' is works faster because restoring 'Data' will cause re-recording the 'Data' again and in some cases it may cause a violation error as 'File Already Open'

Rule 2 is clear so nothing to explain.


Rule 3 is also important. Think about the handshake graphics:



PC Status = '0000' also means that 'PC has completed operations, so that PLC can send the existing product and bring the new one'. Visual Basic assigns 0 into variables as they created.


C may assign anything in the memory unless variable is initialised.

Writing uninitialized data into PLC may result unexpected and unwanted results. So do not execute 'Write All Outputs' routine before loading all global data or properties and the last data written into PLC.

As the summary of those three rules of thumb, you are free to last time intervals in handshake as long as you want, however do not switch into another time interval or do not cause PLC to switch into another time interval.

You can consider putting a button on screen for resetting the handshake cycle against deadlocks, you can simply switch to T1 and clear 'PC Status' with this button, but never switch to T1 on start up. Let the operator decide for reset if necessary.


If it is not possible to control write and reads?
If your application writes 'PC_Status' into PLC before restoring it on initial start, it may cause unexpected movements on the assembly line. Some may get injured or you can miss one product.


Some SCADA systems also uses 'Read All Inputs' and 'Write All Outputs' routines for PC – PLC communications. However some of them may execute those routines in a separate thread so it may be possible to write a global variables (mostly named as 'Tag' in SCADA systems) value into PLC before initialising or restoring it.

So, what can you do if you are using a SCADA and not be able to manage 'Read All Inputs + Write All Outputs' process ?

One solution is using a cyclic counter in PLC. PLC has an increasing counter and PC echoes it into another data memory of PLC. If counter value is equal to the echo, PLC increases the counter and waits the same value from PC. If PC can not update in a certain time, PLC understands that PC has failed, and the data from PC is untrusted. This method also can be used to understand if PC is still working.


Fragmanted Information
Other than power interruptions, communicating with lots of data may cause unexpected results. Most PC – PLC communication protocols have packet length limits. For that reason, if PC wants to write too many information into PLC, it should use many data packets to write information in to PLC.

This may be dangerous if automation system designers don't take sufficient precautions.

Assume that PC is writing a receipt into PLC data memories, and 'receipt ready' flag is at the beginning of the data memory area.

PLC may apply the receipt as soon as it realises 'receipt ready' flag is set, however receipt may not be ready on time. This results of this design may be difficult to debug.

How can we avoid fragmented information?
  1. We can use checksum at the beginning or at the end of data memory area reserved for PC's write operations. However, there is still a probability that something may leak because there are too many possibilities to produce the same checksum value.

  2. We can use the counter solution stated above. Reserve two data memories in the data memory area which is reserved for PC's write. Let the PC fill two data memories with the echo from PLC. If both data memories are same and fresh, PLC can trust that information is consistent and trustable.

With this post, we completed the 'Simple PC – PLC Communications' series.

Our next post will be about customers. 'Customer is always right and mostly undefined'. And we will have another series with a case study. We are going to examine a data collection system to use for assembly line balancing and reporting the bottle necks on an assembly line.

4 comments:

Anonymous said...

Hello....
I enjoy your posts. Really informative.
I have PLC blog myself, but it's in Indonesian. I use OMRON.

http://telinks.wordpress.com

Thanks.

Moosty said...

Hello,

Thank you very much. Your comment is the first one in InDa notes.

Your opinions are valuable, I am so glad to have a comment.

I also use OMRON, and planning to publish an ActiveX control for FINS communication soon.

Unknown said...

replica bags supplier replica bags supplier replica bags qatar

Anonymous said...

yeezy 350 v2
golden goose sneakers
kyrie shoes
off white hoodie
kyrie shoes
golden goose outlet
kyrie irving shoes
curry 9
bape clothing
jordans

Post a Comment

Followers

Search This Blog

Comments

About Me

My photo
Automation engineer especially working on PC software development. Formerly I was coding on PLC, but now I am using mostly Visual Basic on PC.