07-02-2009 02:18 PM
Hello.
I am busy with my final year project and I need to be able to scan a barcode in order to determine what task the autonomous vehicle must execute.
I want to connect a barcode scanner to the NI 9403 module. I just want to know if it is possible and if so, how can I read the data from the barcode scanner (which is in Hexadecimal) through a pin. I am new to the LabView and I'm not familiar with al the functions. I am currently runnig LabView 8.5 on my computer.
If this is not possible which DAQ modules would you suggest. I have looked at the NI 9401 module but I am not sure if I have to buy a new NI module.
I want to use as few as possible external circuitry, that is why I want to connect it directly to the CompactRIO. The interface of the barcode scanner is a wedge keyboard (PS/2). I have already connected it to a pc to test the scanner and I can see that the barcode scanner works.
The reason why I say it is SPI is because the barcode scanner has a clock and data line. Thus it is synchronous. When I connect the barcode's data line and clock line to an oscilloscope I can see the make and break codes.
Is it possible to read the data coming from the barcode into an array when programming in the FPGA block diagram. I assume that the array type will be Boolean. Then I want to extract the different make codes to compare it with a database of ASCII codes. For example the barcode will say TASK0112.
The last four ASCII codes will be compared to a database and the appropriate task will be executed.
Can you please help me.
07-02-2009 03:47 PM
Achillies,
You can use the 9403's I/O to read the data as long as the clock is slow enough (7us update rate for the 9403) and TTL signalling (5V logic high). It sounds like you are pretty sure the interface is synchronous serial, but are you sure it is standard SPI, or possibly RS232? I don't know PS/2 off the top of my head, but I'm sure there's plenty of websites out there explaining that. Knowing the actual protocol will help in decoding the data you receive. If you can first read the synchronous bits coming from the device that will of course help figure that out if it's not documented.
First you will need to create an edge detector that will detect the proper edge of the clock has occurred. With the 9403 this will require sampling from the module probably as fast as possible, and detecting a transition by the new value being different from the last value. You'll have to determine if the data is stable on the rising or falling clock edge to know when to sample the data bit. These bits can then be appended to an array in whatever format you wish.
If you need lower-level help (like how to configure the module or use an IO Node) I'd suggest the CompactRIO Developer's Guide, particularly chapters 5 and 6 of the full guide.
07-02-2009 04:05 PM
Thank you.
I will go through the full guide and make sure of the clock rate and interface.
I will come back to you if I get stuck again.
Thanx for the advise.
07-06-2009 11:08 AM
Achillies,
You also might find this document helpfull as well.
Implementing SPI Communication Protocol in LabVIEW FPGA
07-26-2009 08:31 AM
Hello again.
I was able to read the data from the barcode scanner into the FPGA program, using the clock generated by the bacode scanner. But I struggle to transfer the datafrom the FPGA program to the program in the Real- time controller.
When I run the FPGA program alone it scans and displays the correct data, but when I run the Real- Time host program it scans and displays the incorrect data. When I scan the same barcode over and over it displays different data every time.
I wil try and my program. I just want to know if there is something wrong with my program. In this program I use a "switch untill release" button but in the Real-Time program I can't.
Can you please help me.
07-26-2009 08:32 AM
sorry, here is the attachment.
07-26-2009 06:22 PM - edited 07-26-2009 06:31 PM
Achilles,
Since you haven't included your RT VI it is hard to determine why you aren't seeing data. I will guess that you don't see it though because you don't have a good handshaking method setup between the FPGA and RT. It helps to think of the RT and FPGA targets as two totally separate components and it is up to you to determine the method of synchronizing and handshaking data between the two.
For your application I suggest using an IRQ. You can have the IRQ assert first thing when the FPGA code loop runs. This will cause the FPGA code to wait until the RT target acknowledges the IRQ. Then once it is acknowledged your code can run and acquire the barcode data once. Since it is in a loop, the IRQ will then assert again once the loop returns to the beginning.
The RT target then can easily acknowledge the IRQ, wait for the IRQ to re-assert, and then you know the data will be valid and ready to read from the FPGA.
I've attached a full project where I've modified your code to use this method. I had to save for previous to get it to LV8.5, so hopefully you can open it. You'll have to change your FPGA to whichever one you are using to get it to work though.
I want to also mention that your current algorithm appears to just start whenever you decide to run it, not when the barcode scanner really is sending the new data (unless you happen to be pushing the scan barcode button before scanning the actual barcode). To make the algorithm better I would add the ability to frame the data using the chip select line of the barcode scanner if one is available as well as adding a wait for the opposite edge of the clock to guarantee that you aren't double-sampling the same data.
-James
07-27-2009 02:56 AM
Thanx allot!
I'll have a look at it, and come back to you. I also want to know if you can helpme with the for loop problem that I have? The size of the for loop in the program is 10 but it must be a value of 297...but as you can imagine the compile time is very, very long... an hour and a half.
Any tips?
Thanx allot for your support!
07-27-2009 06:26 AM
I'm sorry but I neglected to tell you that I use the scan barcode button in my FPGA program to toggle a pin high, which is used to act like the push button of the barcode scanner.
How can I implement that in the example you gave me, I haven't worked with the IRQ functions so Im not sure how to use it.
Thanx for your help.
07-28-2009 04:27 PM
Hi Achillies,
An example for using interrupts can be found in the NI Example Finder (Help»Find Examples...) by searching for "Interrupts".