- Home /
Barcode reader using Laser Gun
Hi all, I've to interface my project with a laser gun hardware to read an existing barcode.
I've seen that it's very simple to create a barcode scanner using camera in mobile apps, but i need to use my program on PC, using this USB hardware.
Before I proceed on purchase that laser gun I'd like to ask if anyone tried to do this before, and can tell me how difficult can be. I looked in the asset store, but I didn't find anything I can use.
So, how can Unity3d interface with this kind of hardware?
Looking forward to answers, Thanks for attention!
Have you had any luck? I'm looking into this myself at the moment. Haven't bought the actual scanner yet tho.
$$anonymous$$y first guess is we'll have to open a serial port and poke into it.
Answer by Benoit Dufresne · Jan 16, 2014 at 07:29 PM
If your gun is like mine, it is treated like a keyboard (e.g. writes decoded data in notepad). Then reading data is trivial using Input.inputString:
public UILabel barCode;
public float timeDelay = 0.1f;
private string currentCode;
private float lastReceivedInput = 0f;
// Use this for initialization
void Start () {
currentCode = "";
}
// Update is called once per frame
void Update () {
if (Time.time > lastReceivedInput + timeDelay){
currentCode = "";
}
if (Input.inputString != ""){
currentCode += Input.inputString;
lastReceivedInput = Time.time;
}
if (currentCode!="" && (currentCode[currentCode.Length-1] == '\n' || currentCode[currentCode.Length-1] == '\r')){
barCode.text = currentCode;
}
}
Edit: some more in-depth wisdom after testing parameters...
Has to be in "Keyboard wedge" mode to be read from Input.inputString
Transmission speed is an issue. From my big booklet o' settings were 2 barcodes for transmission speed settings (under Interface - KBW). Options were 0 and 25 and 25 fixed the problem. I'm not 100% certain what caused it (I suspect dropped bytes [eg only half character getting there in time]) but characters would appear randomly capitalized or not, and numbers would either be numbers or their corresponding symbols on the keyboard. These are NOT reading errors as readings are 100% accurate outside Unity. With the 25 speed setting, readings are accurate inside Unity as well.
Answer by Pangamini · Jan 14, 2014 at 08:31 PM
This is not an unity related question in any way, ask on forums related to .Net / C# / forums related to this hardware (does it come with some API?) , because that's how you are going to access it.
It IS related to Unity if you take the simplest route, which is Input.inputString
Answer by gulink · Jun 03, 2014 at 03:42 AM
if you want to create a barcode scanner, why don't you go to some barcode reader creation website. you will find easy way to create a barcode reader in Visual Studio with a few steps.
Answer by fenden · Apr 02, 2015 at 12:35 PM
I think you may refer to some .net bar code reader websites, or another one is Zxing bar code, which I've heard recently.
Answer by royallauker · Oct 09, 2018 at 04:37 AM
Is this what you're looking for? Use a barcode scanner sdk to read an existing barcode like reading QR code c# etc.
Your answer
Follow this Question
Related Questions
how to do a laser pointer 1 Answer
How to get a LineRenderer to shoot from Gun Point to Mouse Position 1 Answer
How do I make a line render always be pointing at the center of the canvas/gui 1 Answer
what is the best way of making a laser gun that shoots long ray of la 3 Answers
Creating laser gun effect. 1 Answer