Suggestions Welcome

beethoven_ii

Lifetime Supporting Member
Join Date
Nov 2006
Location
Central England
Posts
409
I have a client on a recent project who now wants to make a few changes. We are currently scanning barcodes on containers and sending certain codes in one direction and all others in a different direction on a conveyor system with a divert unit. The customer has up to 1000 different store codes identified by 4 digits in the barcode (0001-0999)and wants to be able to add or remove individual codes from a list of stores to be diverted to lets say Region 1, with all others being Region 2. The plc I have is a Siemens S7-1200 CPU 1214C using TIA portal and I have a KTP700 Basic HMI screen. I'm looking for tips or suggestions on the best way of achieving this. I have 2 days to prepare this before returning to site with a solution.
 
Try using a lookup table. You can make an array of 1000 elements (In this case bits), and address by the 4 digits. Use 1 to divert and 0 to go straight. For example:

Barcode: 1234567890120666
Product Code: 0666
Array element: DivertArray[666]
Element Value: True (This product will divert).

Of course, this is only any good if you can create an array that big, and they don't want to expand the product code to something bigger than the processor can address in the future. If you have more than 2 directions, use an integer instead of a bit, so each direction has a value.
 
I've done a similar thing with AB, but not Siemens. My approach would be (in AB terminology, you'll have to translate it to Siemens):

- Create an array of 1000 BOOL's, called, say Divert_Map
- Scan barcode, and extract the last four digits. Store these last four digits as an integer of some sort in a tag called, say, Product
- Examine Divert_Map[Product]. If it's a 1, the product gets diverted. If not, it doesn't.
- Set up a HMI screen where you can call up a particular product to set it's divert status. Have the user enter a number into a field which is tied to a tag, say, "ProductEdit". Display the status of Divert_Map[ProductEdit] on the HMI. The operator can then toggle a bit (say, DivertEdit). Once the operator hits the save button, copy the state of DivertEdit to Divert_Map[ProductEdit]

Hope that makes some kind of sense.
 
Beat you by THIS much! :ROFLMAO: We also do this with an AB system, but there's no reason you can't implement the same thing with Siemens.
 
Thanks for the tips guys. If this was an AB project I'd be way more comfortable as arrays & indirect addressing are pretty straight forward. Never done anything similar in Siemens but I guess I'll have to learn some time.
 
Damn it Jeev, if it wasn't for daylight savings I'd have been first! Damn Queenslanders! :ROFLMAO:
 
Thanks for the tips guys. If this was an AB project I'd be way more comfortable as arrays & indirect addressing are pretty straight forward. Never done anything similar in Siemens but I guess I'll have to learn some time.

If this were one of the older generation PLCs (300/400), then the indirect addressing would probably have been a bit complicated (STL/SCL). In the 1200/1500, it works pretty much just like it does in AB, where you can use a tag as the array index in LAD.

You only need to use the field read/write instructions from Jeev's link if you are using one of the original firmware 1200's.
 
The Field_Read and Field_Write blocks work beautifully and I have completed my Region selection to my bool array from the HMI screen. Now just trying to figure out how to compare my barcode characters to a look up table.

I need to look at 3 characters within the barcode which will be my store numbers 000-999. If the barcode reads store number 450 for instance and element 450 of my bool array is true then I need to divert the container. Not sure how best to do this at the minute but will soldier on.

Thanks for the help so far and any further advice would be greatly appreciated.
 
I need to look at 3 characters within the barcode which will be my store numbers 000-999. If the barcode reads store number 450 for instance and element 450 of my bool array is true then I need to divert the container. Not sure how best to do this at the minute but will soldier on.

Take a look at the code below. It should be pretty straightforward to get the number out of your barcode string, assuming it is in the same place every time. The MID instruction grabs a piece of a string based on starting position and substring length, and then the STRG_VAL instruction converts it to an INT or REAL. If you're using it as the array index, you need an INT.

string to int.jpg
 
Thanks for that. It looks very much like being the solution. At the moment my Barcode reader/camera is writing the barcode results to IW256 in the plc. I'm struggling in TIA to figure out how to copy this to a string somewhere so I can do what you've shown in your example. In Step 7 SFC20 would do it but I can't find the equivalent in TIA.
 
Thanks for that. It looks very much like being the solution. At the moment my Barcode reader/camera is writing the barcode results to IW256 in the plc. I'm struggling in TIA to figure out how to copy this to a string somewhere so I can do what you've shown in your example. In Step 7 SFC20 would do it but I can't find the equivalent in TIA.

SFC20 is now called Move_BLK. You would have to make sure that you have an standard type data block (non-optimized) into which to copy the string.

However, there is a way that I think is easier, if your PLC firmware and Portal are both up to date. The data you have coming in from the barcode reader isn't really a string, its an array of characters. There is a Chars_TO_Strg command that converts from a character array into a string, for easy processing.

One question left, though, how do you get the IO data into an array of char? Easy, just declare the tag! Well, almost easy. This is the bit that requires everything to be up to date. You can't directly assign a tag as an array, but you CAN assign it as a custom PLC Data Type (or a UDT in Simatic Manager). So if you create a Data type with just one element in the structure, an array of characters equal to the length of your barcode text, you can use that tag directly in the Char_TO_Strg command above. No need to mess around with block moves. When you declare the tag, you declare it for the first bit of the tag (I256.0, in your case), and it fills in the rest of the structure.

Its all part of the new way of doing everything symbolically. It took me some getting used to, but once I got there I've been a big fan.
 
To do a PIB move I just make a FC that looks something like this.

FUNCTION BarcodeDataMove: VOID

TITLE = 'Barcode Data Move'

VAR_TEMP
x: INT;
length: INT;
END_VAR

// Block Parameters
VAR_INPUT
// Input Parameters
ReadComplete: BOOL;
DataTransferLength: WORD; //number of bytes to move
PhysicalStartIndex: INT; // partner address start index ie.. to move data from IB0 enter 0
Barcode_DB :BLOCK_DB;
Offset :INT;
END_VAR

// Instruction Section
length := WORD_TO_INT(DataTransferLength);
IF ReadComplete = TRUE THEN
// Statement Section_IF
FOR x := 0 TO length BY 1 DO
Barcode_DB.DB[(Offset + x)] := PIB[PhysicalStartIndex + x];


END_FOR;
;

ELSE
// Statement Section_ELSE


;
END_IF;


;
END_FUNCTION
 
I've finally cracked it thanks largely to your guidance and a lot of perseverance. I'll be off to site tomorrow full of confidence that it will work. Many thanks to all who offered their help.
 

Similar Topics

Hi guys. I would like to sense coated web running on a chained conveyor. The application looks something like this. Material fed through a coater...
Replies
22
Views
6,082
I know this topic has been brought up a few times, but i had some specific questions. I have installed several 1783-NATR devices and they have...
Replies
6
Views
298
I'd like people's opinions on which manufacturer of hardware they prefer. We are an aerospace manufacturing facility that does little to no SCADA...
Replies
10
Views
531
I am setting up control for Hypochlorite dosing. The easy part is the dosing calculation for flow pacing but I would also like to setup trimming...
Replies
8
Views
947
I'm working on an application and have hit a bit of a snag. I need to find an industrial touchscreen display that can: - Tolerate down to -40C...
Replies
7
Views
755
Back
Top Bottom