Hello,
I wonder, if it is possible to use the built-in Hardware Barcode Scanner of my SWELL V710 (http://www.cnswell.com/en/product/produ ... asp?id=417) with Automagic. The Scanner is integrated in Android, meaning, whenever I scan a Barcode it types the Barcode like keystroke-input coming from an external Keyboard. Thus, all I need is handle keystroke-input and assign it to a variable. In order to detect wheter a keystroke-input Comes from the Barcode Scanner or an external Keyboard (e. g. my Bluetooth Keyboard), Automagic should watch any Input for a Special Character. Let's say, I configure the Barcode-Reader, sending a '|' Prefix before "typing" the Barcode. Automagic detects the '|' Character and catches all keystrokes until a CR (Carriage Return) is "typed". I do not have any experience, how to configure Automagic for catching several keystrokes (lets say, the Barcodes contains up to 20 characters). My Idea is to Set an InputDialog, coming up, when the '|' Prefix is detected, the Barcode Reader just type in the Barcode. I've tested this: The Barcode-Data is written into the InputDialog. Thats fine so far, but I have no idea, how to "click OK" on the DialogBox automatically, at least CR does not close the Dialog Box. I think, the Timeout-Feature of DialogBox is like an Escape, not an OK, thus the typed Input isn't handled but refused.
Enclosed some Screenshoots of Barcode-Scanner-Settings, for better understanding, here you see see Barcode-Scanner:
Regards from Germany,
Lucas
Use Built-in Hardware Barcode Scanner with Automatig
Moderator: Martin
Use Built-in Hardware Barcode Scanner with Automatig
- Attachments
-
- Screenshoot_Barcode_Settings4.png (61.78 KiB) Viewed 16831 times
-
- Screenshoot_Barcode_Settings1.png (70.06 KiB) Viewed 16831 times
Re: Use Built-in Hardware Barcode Scanner with Automatig
Barcode scanner or other scanner behaves just like a keyboard; either it is bluetooth or usb version.
The first thing is you might want to try to use Trigger Hardware Key Event. That can detect the special character you put as prefix and later recognize all the rest. Unfortunately, keyboard based input is so fast, that the trigger probably will miss some of them. So you can't use Hardware key event.
In you case, you have no problem using Input dialog. So I would suggest to use Control UI with loop while() to check for the input. Automagic Accessibility must be enabled first. The script in the Control UI
The script start with init var {ela} as 0, and ftext as "1" (can be anything, as long as not empty)
The loop start at the while, and check if ela is less than 10000 (10 seconds). While still not 10 seconds, sleep for 500 ms and add the ela. Retrieve the text from the input dialog. Check if it is the same as ftext, at first of course it will be false, so nothing happen. Skip to checking if text is "" (empty), still same, nothing happen since text is still empty. This continue to loop
Until your scanner start to put something to the box, the behaviour of the loop change. The text is not empty string now, so ftext = text. The next loop, the text is still changing, the ftext is not the same as text, so still skipped. Until the text not changing anymore; the scanner has stop giving new input text, then ftext == text, and clicking that button1 (OK Button). The input dialog is closed and flow continue to the next step.
If the timeout is reached first before anything input, then the flow still continue, and you can use expression to check it and loop back to the input dialog. You can increase the timeout 10 seconds. You can also change the sleep(500), this will change the sensitivity to the change. Don't change it to low, 500 ms seems a good start. You can try 1000 ms too.
Try it using keyboard first. You can check by typing some char and stop for a while, it should toast the string you type.
The first thing is you might want to try to use Trigger Hardware Key Event. That can detect the special character you put as prefix and later recognize all the rest. Unfortunately, keyboard based input is so fast, that the trigger probably will miss some of them. So you can't use Hardware key event.
In you case, you have no problem using Input dialog. So I would suggest to use Control UI with loop while() to check for the input. Automagic Accessibility must be enabled first. The script in the Control UI
Code: Select all
ela = 0;
ftext = "1";
while(ela <= 10000)
{
sleep(500); ela = ela + 500;
text = getTextById("ch.gridvision.ppam.androidautomagic:id/edit_text");
if(ftext == text)
{
clickById("android:id/button1");
break;
}
if(text != "")
ftext = text;
}
The loop start at the while, and check if ela is less than 10000 (10 seconds). While still not 10 seconds, sleep for 500 ms and add the ela. Retrieve the text from the input dialog. Check if it is the same as ftext, at first of course it will be false, so nothing happen. Skip to checking if text is "" (empty), still same, nothing happen since text is still empty. This continue to loop
Until your scanner start to put something to the box, the behaviour of the loop change. The text is not empty string now, so ftext = text. The next loop, the text is still changing, the ftext is not the same as text, so still skipped. Until the text not changing anymore; the scanner has stop giving new input text, then ftext == text, and clicking that button1 (OK Button). The input dialog is closed and flow continue to the next step.
If the timeout is reached first before anything input, then the flow still continue, and you can use expression to check it and loop back to the input dialog. You can increase the timeout 10 seconds. You can also change the sleep(500), this will change the sensitivity to the change. Don't change it to low, 500 ms seems a good start. You can try 1000 ms too.
Try it using keyboard first. You can check by typing some char and stop for a while, it should toast the string you type.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Use Built-in Hardware Barcode Scanner with Automatig
Wow, Thank you so much for your worthful ideas and fast answer ! I came in mind, that I've to push a button to enable the scanner, first. If there would be a way to catch this key Event, we could say, Pressing the scanner-button down lets pop-up the Dialog Box, releasing the scanner-button does the Click-Button. The Problem is, that I don't know how to trigger the flow in that case. In Tasker, I'm able top setup Plugin-Event AutoInput Key / Manual Key Code (automatically detected: 131). For example: When Pressing the Scan-Button, the scanner is activated and Tasker let's popup a "HELLO WORLD" simultaneously. Of course, I can use this Plugin in Automagic, too, but unfortunately the Plugin-Event isn't fired (of course I've disabled Tasker). Is there a way to do it without AutoInput Key and choose from the Event "Hardware Key-Input"? There is a huge list of keys, but of course not this KeyCode 131? When manually entered, it won't work.
Re: Use Built-in Hardware Barcode Scanner with Automatig
Hardware Key event is relatively new, just introduced in this 1.36.0. So maybe Martin haven't put the proper keycode as he had done in other part. You can find the key code to key name mapping (or vice versa) using the sendKey() function in the Control Ul. Just tap Function, search sendKey), choose either the key code or key name and search for 131. At mine it shows up as 131 F1. If yours is the same, use F1 as your trigger key in hardware key event.
The other method of finding unknown key is using debug dialog. At hardware key event, simply check all key. Add condition debug dialog and enable the flow. Press your key and it should pop up the key code/name. More advanced option, you can use my variable logger flow (look at my index), combined with this hardware key event to log all pressed key during certain period.
If you have used Automagic, basically there is no need to use Autoinput again.
The other method of finding unknown key is using debug dialog. At hardware key event, simply check all key. Add condition debug dialog and enable the flow. Press your key and it should pop up the key code/name. More advanced option, you can use my variable logger flow (look at my index), combined with this hardware key event to log all pressed key during certain period.
If you have used Automagic, basically there is no need to use Autoinput again.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Use Built-in Hardware Barcode Scanner with Automatig
Excellent! I'm now able to catch the Barcode in a Input Dialog and take further Action based on {value}. I'm excited that I'm almost reached the target, I've never had reached with Tasker so fast. The only thing is, that the flow won't work when the device is locked. I found, that it will (at least Sound-Actions for testing), but obviously only the Input Dialog cannot be handled while the device is locked.
Attached the Demo Flow. With Device unlocked, everything works fine, if locked only the first Sound is played (telling me the Flow does work when locked). But on unlocking the device I see the (empty) Dialog Box. I guess there is no way to solve that. It would be the cherry on the cake, if reading Barcodes can be done while dark screen (standby device).
Attached the Demo Flow. With Device unlocked, everything works fine, if locked only the first Sound is played (telling me the Flow does work when locked). But on unlocking the device I see the (empty) Dialog Box. I guess there is no way to solve that. It would be the cherry on the cake, if reading Barcodes can be done while dark screen (standby device).
- Attachments
-
- flow_Flow1_20190114_124112.xml
- (6.73 KiB) Downloaded 802 times
Re: Use Built-in Hardware Barcode Scanner with Automatig
The hardware key event is working when the screen is off? AFAIK, accessibility only work when screen on, it is known limitation from android. If the key can be detected when screen off, you can actually try to detect every key using hardware key event trigger. But of course the flow will be executed so many times, you have to buffer the detected key into glovar, so it stays across multiple consecutive execution. No guarantee it will work, but can be tried first.
Open the hardware key event and check all the possible key. Then in the following number, simply add a script.
Of course you have to create the global_barcode_buffer first, put it empty string (nothing, blank). After scanning with phone locked, check the glovar if it contains the scanned barcode.
Once you have used Automagic passing some point of no return, you will never go back to tasker anymore.
Open the hardware key event and check all the possible key. Then in the following number, simply add a script.
Code: Select all
global_barcode_buffer = concat(global_barcode_buffer, key_code_name);
Once you have used Automagic passing some point of no return, you will never go back to tasker anymore.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Use Built-in Hardware Barcode Scanner with Automatig
The good News are: Hardware key Input is recognized during standby (screen of). Thanks a lot for the script ideas, keystrokes are collected flawless. The bad News are: The scanner does not fire the key Event trigger although the Barcode is typed to Focus. There is a Setting in the scanner called Input Type: Whether I select "Focus Input" or "Keyboard Input" there seems to be no Difference. Only the third Option "None" does result, scanner isn't sending anything. I've set to Keyboard Input and rebootet the Phone, but it's still the same.
I'm amazed About your experience and would like to thank you so much all your help!
I'm amazed About your experience and would like to thank you so much all your help!
Re: Use Built-in Hardware Barcode Scanner with Automatig
You are welcome.
So you need to keep the screen on then when scanning. I think it is OK, since you are actively using the phone. If you afraid the battery drain, just add another action to set the brightness to almost minimum, to reduce the battery usage duing the standby scanning.
So you need to keep the screen on then when scanning. I think it is OK, since you are actively using the phone. If you afraid the battery drain, just add another action to set the brightness to almost minimum, to reduce the battery usage duing the standby scanning.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.