What do you press to cancel a barcode scan?

Mahares

Expert
Licensed User
Longtime User
I scan a barcode, the camera is running, but because of a possible bad or damaged barcode, the scanning failed, I would like to cancel the scan and return to the program to scan another object without exiting the application. How do you set a timer or an event to cancel the scan, say after 30 seconds elapsed?
Thank you for your help.
 

Mahares

Expert
Licensed User
Longtime User
I kept working on it while awaiting a better answer. To answer my own question, I used the following sub:
Sub myABBarcode_Canceled()
'To cancel simply press the back key on the device.
Msgbox("You Canceled scanning! Press OK to go back to select an item from the list.","")
Mylv.visible= True 'Mylv is a listview
End Sub

The above works, but it does not invoke a timer as I would like to see happen. I am still seeking a better solution if someone can devise one.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Create a timer, set it to x amount of sec, then have it call your cancel sub

Sent from my DROIDX
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
My problem is how to set MyTimer to x amount of sec since the timer has 3 properties: enable, initialize and interval.
Sub Process_Globals
Dim MyTimer As Timer
....

Sub Activity_Create(FirstTime As Boolean)
..........
MyTimer.Initialize("MyTimer",1000)
......

myABBarcode_Canceled
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Thank you for your response. I did study the sample in the beginners guide and the Timer link you have included thoroughly well before I posted, but there was not enough information to help me, particularly incorporating it with barcode scanning.
 
Upvote 0

boastrike

Member
Licensed User
Longtime User
mytimer.enabled = True will start a timer for the amount of time you set when you initialized it in the activity_create. 1000 = 1 second.

Raises the event

Sub Mytimer_tick

Mytimer.enabled = False. turn the timer off
...Do what you want here...

End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I tried something similar to what you suggested, but it did not work. Here is my code:
Dim MyTimer As Timer ‘declared in process global
Dim Counter as Int ‘declared in global

MyTimer.Initialize("MyTimer",1000) ‘In Activity create

Counter=30 ’30 seconds
Mytimer.enabled = True

Sub MyTimer_Tick
Counter=Counter-1
If Counter=0 Then
MyTimer.Enabled = False
myABBarcode_Canceled
End If
End Sub


However, the TIMER starts counting down only when I press the back space to cancel the scanning. But I do not want to cancel by pressing the back space. I want the timer to trigger the cancellation. I think the barcode scanning process is interfering with the timer starting while the camera is on.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
What do you then propose instead? Are you saying there is no solution to this issue? I thought perhaps Doevents can be inserted somewhere in the code to make it possible, but I am not certain.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
1. If a timer cannot help time out a barcode scan in progress, then does that mean that the next version of ABZxing library developed by Monsieur Alain Bailleul will be more robust if a scan timeout is included. Or is there another forum user that can still help me and others in this case.
2, I noticed that barcode scanning is not always consistent. Sometimes you hold the camera (phone) for a minute or two over the barcode and nothing happens. I had in some instances the barcode returned by the scan being totally different from the one scanned. Nobody wants that. Does that stem from poor scanning ways (although I have scanned barcodes for years) or from a poor quality barcode, etc. I am eager to hear other views from the forum on their barcode scanning experience in B4A and any recommendations.
Respectfully
 
Upvote 0

manios

Active Member
Licensed User
Longtime User
Scanning of barcodes with an android device cannot be compared to scanning with a ccd or laser device!
As the scanning is performed through the camera, the results are very much depending on the resolution of the camera, the autofocus capabilities, the color and background of the sample and mainly the ambient light. We have done some testing with different android devices and the results where not good enough for commercial use.
With a larger sized barcode on white background and good ambient light however, the scanning is very well suitable for an non commercial application.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User

Post your project file (File>Export As Zip) so we can help.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I will try to create a small version of the project and reproduce the problem because it has become too cumbersome to follow with SQLite database and several tables.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Here is attached the code with the timer and barcode scanning as requested. As you can see, the timer starts, but as soon as the scanner starts the timer resets itself and it does not have any effect and does not cancel the scanning after the pre-set seconds expire as I would like to. NJDude seems to recognize my problem, but I was hoping he has a solution for it. I tried different placement of some of the code as it is shown on my app with comments, but nothing seems to work.
Thanks
 

Attachments

  • ABBarcodeTestTwo.zip
    6.5 KB · Views: 259
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I haven't really tested this code but it seems to work, the attached project does what you want (I put a 10 seconds delay instead of 30 for quick testing purposes).

That code can be improved, but I leave that to you.
 

Attachments

  • BarcodeTest.zip
    7.2 KB · Views: 244
Upvote 0

Mahares

Expert
Licensed User
Longtime User
NJDude, you and Klaus are amazing. The changes you made are working well. The only thing I observed was that when the scanner times out and you click the button to exit the application, it resumes scanning instead of exiting the app. I tried to replace Activity.finish with ExitApplication, but it did not work.
Thank you very much
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User

Doesn't this library require an external app to launch (Barcode Reader)? If that's the case then Activity.Finish/ExitApplication won't work in your code because that is only closing YOUR app and not Barcode Reader. I'm not too familiar with this library but maybe there is a call to exit BR?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
That is correct. It requires an external app (bar code scanner) to run which I downloaded from the market. I am not sure if it has a call to close the barcode scanner app. All I know is that it has a found event and a cancel event reached by pressing the back space.
When I press the button to exit the application it resumes scanning. But if I press the back space to cancel the unwanted scanning before it reaches the time out, it exits the application.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User

Not sure how relevant this is any longer but for what it might be worth:
1. I am using "b4azxing" library
2. I set "flag" to 1 just before the call to start the scanner
3. If I now press the back button the scan is cancelled and control is returned to my app
4. Control is also returned to my app if I for eg loaded a url in a webview (subsequent to a successful scan) and I press the back button
5. App can still be terminated with a dialogresponse


B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    Dim Answ As Int
    Dim txt As String
   
    Select KeyCode
      Case KeyCodes.KEYCODE_BACK
        If flag = 1 Then
          Answ = DialogResponse.NEGATIVE
          If Answ = DialogResponse.NEGATIVE Then
            wv.RemoveView
            flag = 0
            Return True
          End If 
        End If
        If flag = 0 Then
          txt = "Do you really want to quit this program"
          Answ = Msgbox2(txt, "A T T E N T I O N", "Yes", "", "No", Null)
          If Answ = DialogResponse.NEGATIVE Then
            Return True
          Else
            Return False   
          End If
        End If 
    End Select

   
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…