In over my head (ladder logic) Horner PLC, serial Barcode scan

Ted Z

Member
Join Date
Sep 2021
Location
Earth
Posts
42
Thanks ahead for any insight or assistance...


I am a machine designer of 25+ Years in a relatively new "one man band" position, I've never had controls training and only enough experience to be dangerous. I've always had controls engineers in house that do the programming and debugging.


I've been tasked with a Pass/Fail barcode scanner table that has a stop cylinder to control part pass through.


I am using a Horner HE-XE105UC, Datalogic Gryphon GFS4450-9 (RS232), Inductive prox for both Part Present, Cylinder Sensors for position of stopper cylinder and a simple R/G indicator LED.


As far as wiring, It is all functional.


I can get some of the logic to do what i want, but am having a hard time putting the logic together to do what i need.




The basics are:




Part makes PP switch (Start of cycle)


Clear values from last scan and verify state of the stop cylinder


Bar code scans, ASCII data in (28 char), Compare last 12 digits with known string

Success > green indicator lights, Stop cylinder retracts.
Fail > Red indicator lights, Stop cylinder stays extended.


if part passes, outgoing PP switch is made, clearing last scan memory, and extending stop cylinder.


End of Cycle


Please help me become the hero of the day! :)
 
It's not yet completely, unambiguously clear what you want the PLC to do. E.g.

  • Is "PP switch (Start of cycle)" the same as PART_POS1?
  • Is "outgoing PP switch" the same as PART_POS2?
  • What value will SOL_EXT have, 0 or 1, either to extend or to retract the stop cylinder?
  • for the bar code reader
    • Is it continually sending its last-read string to the serial interface, or does it have to be polled or triggered?
    • Is there a start and/or termination characters between bar code strings sent to the serial interface e.g. carriage return, linefeed, whitespace, comma, semi-colon, etc.?
      • Can start and/or termination characters be part of the 28 characters read by the RECV instruction?
    • Is it possible to receive a partial string? How can that be detected, cleared, and the next complete string read?
What would be helpful is comments in the code, describing how each rung interprets and or affects the process. e.g. for that last rung "Turn on red light and extend (retract?) cylinder when part makes outgoing (incoming?) prox."

So at present the forum has to guess from your words and your code what is supposed to happen. Not that many of members here cannot do it, but we do spend a fair bit of time chasing geese.

That said, for those last two rungs

  1. The seal-in branches (NO/NC contacts checking state of SOL_EXT) are not needed because the final output elements are sets and reset
  2. That said, I think you are trying to implement what is commonly called a Start/Stop pattern (see this link). Are those last two rungs trying to implement the following logic?
    • If PART_POS2 is 1, then SOL_EXT should be 0 (the current code does do this)
    • If PART_POS2 is 0, and PART_POS1 is 0, then SOL_EXT should be 0 (the current code does not do this)
    • If PART_POS2 is 0, and PART_POS1 is 1, then SOL_EXT should be 1 (the current code does do this)
    • Note that that is not what those last two rungs, as written, do, but I wonder if that may be what you want them to do.
    • Note also that, in the code as written, if both PART_POS2 and PART_POS1 are 1, then both red and green lights will be on.
 
Last edited:
Thank you for the reply, I will go through and try to comment my code and re-post


You are correct:

PP is the same as PART_POS1
Outgoing PP is the same as PART_POS2


I'm not sure on the SOL_EXT, It is a spring return solenoid valve (5/2) i am using.... So i assume it's either on or off (extend or retract or visa-versa)



I think you are on the right path as to what i WANT the code to do, And i'm in some confusion as to making it all do what i need..


I think the light can go off when Part_Pos2 is made as it is just an indicator that the barcode scanned correctly and the part can be transferred, Once part is in Position2, It's end of cycle until a part is introduced into Position1 again.
 
I think you are on the right path as to what i WANT the code to do, And i'm in some confusion as to making it all do what i need..

It sounds like you are new to programming; if that is the case, then the most important thing I can tell you is this:

  • The PLC cares not a whit what you want it to do, but it will always and flawlessly do exactly what you tell it to do.
Burn that into your memory, because every time you see the PLC do something you do not understand, it essentially always comes down to forgetting this fundamental axiom.
 
I see it as simple as this, not included the lamps but that should be simple, assumed a single acting solenoid that sits in reject position when de-energised, coms & compare already done.
Part hits PP1, bar code is read, if good set a bit, if bad nothing happens so rejected, if good part solenoid energises so part caries on, hits Sensor PP2 (here it is assumed this is after reject solenoid) reset the solenoid & not shown but clear the bar code data.

Good part.png
 
Building on @parky's simple approach and using the Start/Stop pattern:

xxx.png

Another approach needs neither the [NO Solenod] seal-in branch nor the [NC Out_Pos_PP] stop test above nor even perhaps the [NO In_Pos_PP], and instead resets the bar code to gibberish when Out_Pos_PP is, or has a rising edge to become, 1, which in turn resets Solenod to 0 through the AND$.

This part is easy; the interesting bit is going to be parsing the serial input. I think OP should hook up a PC with with a serial comm port and use Hyperterminal or similar to understand how that bar code reader works.
 
Building on @parky's simple approach and using the Start/Stop pattern:

View attachment 59517

Another approach needs neither the [NO Solenod] seal-in branch nor the [NC Out_Pos_PP] stop test above nor even perhaps the [NO In_Pos_PP], and instead resets the bar code to gibberish when Out_Pos_PP is, or has a rising edge to become, 1, which in turn resets Solenod to 0 through the AND$.

This part is easy; the interesting bit is going to be parsing the serial input. I think OP should hook up a PC with with a serial comm port and use Hyperterminal or similar to understand how that bar code reader works.


You are quite correct sir. My programming knowledge is basic, hahaha ;) I'm a mechanical guy thats taken on some new things



I actually have the data from the barcode reader showing on the top half of my screen (Full Part No) it comes in as Ascii data, 28 char as i expected... I'm not clear on how to compare only the last 12 digits with a known string for the pass/fail though, i'm maybe close.
 
Excellent, then from here on out it's merely bookkeeping. No different than mechanical work, I imagine. E.g if someone asked you to take this conveyor or whatever apart, you would already have a fairly detailed idea in your head the order in which you would do it, how you would lay out the pieces so it would go back together correctly, etc. Programming is not too different from that: the only thing you lack is knowing what the pieces are and how to put them together.

Do you have a programming manual for that PLC? There are usually a set of string-handling instructions, one of which may be called "RIGHT" for extracting a rightmost sub-string of characters, in this case 12, from a longer string, another of which may be "MID" for extracting a sub-string from the middle (or end) a longer string, so you would tell "MID" to start at character index 17* and extract the next 12 characters.

* or index 16, if the index represents an offset from the first character position, instead of an ordinal character position.

If not, you might be able to BMV the 28 characters to a memory location of 7 LONG (4-byte) integers or 14 word (2-byte) integers. If you can do it to LONGs, then you only have to figure out what the byte order is and then it is three LONG integer compare instructions to test those 12 characters, or six word compares.

Are those last 12 characters always the same? Or do you need to retrieve them from somwhere else?

Sidebar: how do you know the RECV is getting the correct 28 characters, or more specifically, how would the program know?
 
Yes DR is right, it will depend on what instructions the PLC has for comparing strings, many have no length parameter so for example if your barcode was 16 chars long the call to a string function may be a max of 64, it usually can take care of varying string lengths by the terminating character, you may have to strip unwanted chars from the barcode i.e. the things like reader address & crc or checksums & in your case only get the 12 chars you need.
The alternative is use standard compares ANDED on each 2 chars (one word 6 times) but that is a little long winded.
Other things you may need is some sort of timing for example you could use a time delay between the trigger of the barcode to actually comparing the code, a better way is use the communication i.e. characters received as the trigger to do the comparison this is better than timers.
DR is a perfectionist & likes to reduce the number of instructions by incorporating many instructions in one ladder, I too take this approach when writing code, however, I have found in teaching novices, this can be confusing & in FBD on some IDE's not ideal as some results cannot be seen when monitoring the code, I do suggest you split some code up here is an example of what I mean.
You will see that incorporating both maths functions in FBD in the first rung the result of the first function cannot be seen, by splitting this up you can see the results of both maths functions, this is only a simple example & probably not any use, however, when you have a more complex routine, when debugging, it is often better to split them up, once you know it is working correctly, then if you wish combine them.

Maths.png
 
Thank you so much for the information guys... I had the opportunity to have a Controls Engineer stop by this morning to assist me.


I think we worked through the ladder, I still have to get through the compare data from the scanner. Which i think you've given me enough to get through



I will update soon
 
Do you have a programming manual for the Horner PLC with a comprehensive description of all instructions? I have not been able to find one in my brief searches online.

As we said, if there are not a group of string-handling instructions, then it will be down to comparing bytes or words. I.e. bookkeeping.

TL;DR

My biggest concern would be to ensure the RECV is getting the desired 28 characters. e.g.

Say the bar code reader was not polled and simply sends out each result it reads e.g.
:abcdefghijklmnop012345678909:abcdefghijklmnop012345678909:abcdefghijklmnop012345678909@...
where each result comprises 28 contiguous characters of the same color, and each bar code is delimited by a leading colon character. As long as the PLC RECV instruction always starts reading its 28 characters at one of those colon characters, then the last 12 of the 28 characters in one read will compose the string to be compared. But say the bar code reader encounters an invalid bar code, and sends something like :bad_code down the serial line; then the stream would look like this
:bad_code:abcdefghijklmnop012345678909:abcdefghijklmnop012345678909:abcdefghijklmnop012...
and the RECV will still read 28 characters at a time, but last 12 of each read will not be the correct ones to be compared.

Ideally there would be a line terminator such as a carriage return or linefeed character, or even that colon, and the RECV would terminate any string received when it received the line termination; then the code could check to ensure at least 12 characters were received and if not then wait for the next terminated read, until there are 12 characters read then extract and check them.

But I am only guessing, we would have to know how that RECV instruction and the bar code reader work.
 
My engineering support helped a lot,I am closer... But still fighting simple things i don't understand. I attached a PDF of my current logic. Bear with me, I still have commenting to do but it should be on a better path



On my Rung 10, The NC contact "%M00014" is giving me an Error: Element Not Compiled, Check Syntax


I'm not for sure that this rung does the compare i need either. BTW, We realized that all i need to check for is the last two characters of the barcode are "BC"... And i feel i can get that if i can get past this error and get to uploading to the PLC
 
Never used that PLC, but try re-creating the timer on a separate rung, i.e. reproduce the logic on the previous rung (just the trigger logic plus the %M00014), some IDE's do not like parallel branches when timers or other instructions are involved.
Again, as I said in a previous post sometimes it is better to expand your logic a little bit.
 
Call me pedantic, but there is no difference between this:
xxx.png
and this:
yyy.png
and this:
zzz.png
Also, since the full [PPMem %M00010] story is this:
aaa.png
then it could all be simplified to only this:
bbb.png
which is clearer and easier to read.

(yes there may be a minor difference in the exact per-scan behavior because of the ordering, but I suspect that is irrelevant)
 
Last edited:
I agree with parky, but I also wonder what's going on under the hood in that 'CMPSTR' function that could take five seconds to complete. It seems to me the results should be available immediately upon execution of the function without needing a timer.
 

Similar Topics

Good Afternoon , I'm sure there are many Ishida Muti-Head Weigh Systems . We have a Ishida CCW-M-214W Multi-Head system . We are...
Replies
1
Views
418
Hi all, have a project which requires reading a weigh head weight over ASCII. Never really touched ascii so struggling a bit. The weigh head is in...
Replies
11
Views
1,182
Good Morning , We have a Ishida Multi-Head Scale . I had experiece with them for chips , crackers , etc. , but now we are using them for...
Replies
7
Views
424
Hello expert I have migrate legacy project that use Applicom OPC DA with 3rd client and S7-400. I see in client code add item string call...
Replies
0
Views
344
Got another one a whole team of us and the OEM cannot figure out. Powerflex525, 20HP VFD, commanded over Ethernet won't turn a motor it's turned...
Replies
32
Views
7,642
Back
Top Bottom