DirectLOGIC PLCs - the most practical PLCs in the industry......from AutomationDirect go back to Do-more home AutomationDirect online store

Spend Less; Do More

Do-more™ PLC: How to setup and use a BarCode Scanner

Video Transcript:

Getting a bar code scanner up and running on some PLC's can be a real hassle. The Do-more makes it so easy. Let's take a look:

Step 1: Plug the scanner into the serial port on the front of the CPU.

Step 2: Configure the hardware: Click on System configuration. Under Serial Port Mode, choose General Purpose and device Settings. Our device is running at 9600 baud, 8 bits, 1 stop bit, odd parity and no controls. We're good to go.

Step 3: Ladder Code. You only need one instruction to read the bar code scanner: that would be STREAMIN.
We want to select the Device that we are connected to - which is our internal serial port.

And we want to determine when the message is complete. In our case we are going to be using a 10 character bar code with no delimiters. Note that you can delimit on a carriage return, line feed, or any character you want and look at this: You can even have the instruction trim the delimiters from the string that ends up in your result. We don't need that so we will turn that off.

And we are also not going to have a timeout. We're just going to let this thing run continuously. Since this is a string, we are going to have it end up in a string structure. If you had numeric data coming in you would select this option.

So that's all you need. You just select the serial port you are plugged into, when the message is complete, and where you want the result to end up.

Now you can tell from this little triangle here, that this message is edge triggered. Let's go ahead and put a control but in here, I'll use C10 that we can use to enable the instruction with.

Let's create a Data view so we can monitor some things.

The first thing we want to see is the string result, which was a String Short 1 back here in our stream in instruction. Let's add a control bit, C10, so we can turn this thing on.

And let's add one more thing. I'm going to add the internal serial port - dot - "In-queue". That tells me how many characters are buffered up in the In Queue.

I'm going to reach over here and run a couple barcodes into the bar code scanner. Ok, I just ran four in. And you can see, we collected 40 characters in our queue. That was four, ten character bar codes. To pull those bar codes out of the queue, we just enable C10. Let's turn on our edit mode. Make some room so we can view that string, and toggle C10.

When we do that, we pull the first barcode out of the queue. The queue gets reduced by 10 characters, and we are good to go.

Let's toggle C10 off, and back on, and my second bar code comes in and I dropped down another 10 characters. One more time, my third bar code, I'm down to 10 characters. And one more time. I see my fourth bar code and my buffer is empty.

That's all there is to hooking up the bar code scanner to the Do-more.

Let's do one more thing – let's put this in a code block that you can run to continuously retrieve bar code messages, without having to toggle that C10 bit.

Let's go ahead and turn C10 off to get it out of our way.

We'll create a new Program, and we'll call this BarCode. And we're going to use a simple stage program to implement this. We're going to come over here and say our first stage is going to be Stage 0. In that stage we want to do a STREAMIN. We're going to choose our internal serial port. We have a 10 character Barcode. No delimiters, no timeout. Don't need any of that. We'll go ahead and put him in String Structure… we'll put him back in String Short 1.

And this time we are going to exit on success - we're going to jump to stage S0 - the same stage. If we have an error, we will jump to stage 1.

Stage 1 - this is our error stage. Remember, if we have an error up here in STREAMIN we're going to jump to stage 1. And all I want to do here is increment a counter so I can see if I have any errors. Once that is done, I am going to jump straight back to stage zero.

That's it. So when we come into this stage, it automatically enables STREAMIN for us, pulls 10 characters out of the buffer. When that is complete, we jump back to stage zero and do it again. If we have an error, we jump down here to stage 1 where we increment a counter and then jump back to stage 0 where we will start the process all over again.

Let's accept that new routine. Go back to main, and we want to run that routine. And for this example we are just going to run it on the first scan. Remember – this is a program code block. Once you initiate it, it continues to run until something shuts it down. So we only need to do that once. We'll accept that change, save it, write it out to the PLC, and we are ready to go.

So now in our program, we have our original STREAMIN which we are not going to use – we'll just leave C10 turned off. And we have our new program which got initiated on the first scan, and continues to run for the duration of our program. We can see right here, it ran this scan.

I'm going to clear out our string, just so we can see changes. C10 is off, that's good. Our serial In Queue is zero. Because this program is running on its own in the background, all I have to do is hit our barcode scanner with some bar codes, and if you watch carefully here ... each time I do that the bar code changes.

My In Queue appears to be zero because each time the message comes in, it gets pulled right back out. Perfect. So that's exactly what we were looking for. Every time a bar code comes in, it immediately gets put into the string structure SS1 and we can now use it anywhere we want in the program.

What if you wanted to do this on an EXTERNAL serial port? That's easy.

Just define the external serial port over here: System Configuration, Module Configuration, choose that serial port. And let's say we want to plug the bar code scanner into port A.

As you can see, I've already given it a name. We select general purpose. Device settings and here are all the same settings we used before on our bar code scanner.

Now that we have configured that external serial port for the barcode scanner, all we have to do is move the cable from our internal serial port to our external serial port. Change our program to point to that external serial port. Say OK, accept it, save it, write it out, and we are ready to go.

Now if I run some bar codes through, it works just like before - EXCEPT this time it is coming from the external serial port. Very, very easy.

That ought to be enough to get you up and running with the barcode scanner on the Automation Direct DoMore PLC.

Be sure to check out the other videos in this series for more ways to get up and running quickly with this controller. And as always, please send us any comments you may have, we appreciate the feedback.

Spend Less, Do More, from AutomationDirect.


Check-out all the Do-more™ Videos

  The Do-more Way
  Do-more Designer Software
  Do-more Ethernet I/O
  Do-more Motion Control Videos
  Do-more with ViewMarq Message Display

User Application Stories
Encompassing all AutomationDirect PLCs

Helpful PLC guides



Copyright © All rights reserved.All prices are U.S. list prices.