1

In swift based application, I have to implement barcode scanning using device camera as well as using Linea Pro 5 (LP5) external barcode scanner. In the application have to to check the iPhone connection state with Linea Pro 5 (LP5) device and if iPhone is not connected with LP5 then it must open iPhone camera otherwise it will scan using LP5. The scanning I have to do with any UIButton reside on the application screen.

My problem is that when I call connect() method the "func connectionState(state: Int32)" method call and iPhone connection state with LP5 change from Connecting to Connected then after I am able to scan using LP5 but when I perform scan another barcode the LP5 is not scanning and camera get open. Also when I scan wring barcode which is not expect then after rescan the device camera opens. It means connection state changed somehow. but each time "func connectionState(state: Int32)” not call.

Can anybody tell me how to check connection state of the LP5 device before each scan operation. Or tell me proper solution of the above problem.

Santosh Kumar
  • 71
  • 1
  • 6

1 Answers1

0

Option 1: Maintain a variable in the calling class, which holds the state of the linea pro device,

var lineaProState;

assign the value to this variable in, connectionState(_ state: Int32) method

lineaProState = state;

Then before scanning the item/barcode, check the state variable:

if(lineaProState==0)
                {
                    //disconnected...
                    //call the lib.conncet() method
                    lib.connect()
                }
                else if(lineaProState==1)
                {
                    //connecting...wait for connect to finish
                }
                else if(lineaProState==2)
                {
                    //connected..Proceed with scanning
                }

Option2: Call the lib.connect() method from the library every time you try to scan the new barcode? This in turn, will invoke the connectionState(_ state: Int32) method and you can check the device status, whether it is connected.

This will do the trick.Cheers!!!

BlackPearl12
  • 306
  • 5
  • 20