0

How to start/stop barcode scanning

cahoots 11 år siden opdateret af icahill (Administrator) 11 år siden 3
I have added barcode reading functionality to my app, but the camera seems to be continuously scanning, even when the camera panel is hidden. In order to prevent multiple scans, I was trying to implement a button to show the camera panel and start scanning, and upon a successful scan, show another panel (which I thought would stop the scanning, but apparently not).

Edited code:
<wire>
<main>
<panel name="background" alias="BACK" height="100%" width="100%" background="#0000ee">
<toolbar name="toolbar" height="10%" width="100%" align="left" valign="top">
<panel name="button" width="30%" height="80%" align="left" margin="10" valign="center" background="#888888" cornerradius="5" onclickup="camera-return">
<text name="back" width="90%" height="90%" color="#000000" font="" size="9" align="center" valign="center" text="Scan"></text>
</panel>
</toolbar>
<panel name="camerapanel" alias="CAMERA-PANEL" height="90%" width="100%" valign="bottom" hidden="yes">
<camera alias="CAMERA" name="panel" type="barcodescan" onscan="qrcode_action"
background="#FFFFFF" height="100%" width="100%" align="center" valign="bottom">
<panel name="box" height="150" width="50%" align="center" ypos="30%" borderwidth="2" bordercolor="ff0000" />
</camera>
<text name="title1" text="Scanning..." font="helvetica" size="24" width="100%" height="10%" alignment="center" valign="bottom" align="left" color="#FFFFFF" background="#000000" alpha="0.5"/>
</panel>

<panel name="splash" alias="SPLASH" height="90%" width="100%" valign="bottom" hidden="no" background="#ffffff">
<text name="back" width="90%" height="90%" color="#000000" font="" size="9" align="center" valign="center" text="This is a splash panel"></text>
</panel>
</panel>
</main>
<actions>
<action name="qrcode_action">
<!-- set some values -->
<play action="splash-return"/>
<!-- prevent another scan while dealing with the qr code info -->
</action>

<action name="camera-return">
<replace type="flipleft" target="CAMERA-PANEL" replacement="SPLASH" time="1"/>
</action>
<action name="splash-return">
<replace type="flipleft" target="SPLASH" replacement="CAMERA-PANEL" time="1"/>
</action>

</actions>
</wire>
Currently there is no action that we stop the scan event as long as the camera exists. Your best bet here is to delete the camera tag when it is out of view from the user and create it again when you need to call upon it. 

To do this you will want to move your camera tag into a class and use create and delete actions to place it and remove it from your CAMERA-PANEL object.

Let me know if you have any more questions. 


I believe I have restructured my wire as you suggested, however Fuse crashes - usually after one barcode read and processing loop. If I leave out calling of the "splash-return" action, everything works as expected.

My shortened code below, with creating and deleting of classes:

<classes> <class name="cameraclass"> <camera alias="CAMERA" name="panel" type="barcodescan" onscan="download" background="#FFFFFF" height="100%" width="100%" align="center" valign="bottom"> <panel name="box" height="150" width="50%" align="center" ypos="30%" borderwidth="2" bordercolor="ff0000" /> </camera> </class> </classes> <main> <panel name="background" alias="BACK" height="100%" width="100%" background="#ffffff"> <toolbar name="toolbar" height="10%" width="100%" align="left" valign="top"> <panel name="button" width="30%" height="80%" align="left" margin="10" valign="center" background="#888888" cornerradius="5" onclickup="camera-return"> <text name="back" width="90%" height="90%" color="#000000" font="" size="9" align="center" valign="center" text="Scan"></text> </panel> </toolbar> <panel name="camerapanel" alias="CAMERA-PANEL" height="90%" width="100%" valign="bottom" hidden="yes"> <text name="title1" text="Scanning..." font="helvetica" size="24" width="100%" height="10%" alignment="center" valign="bottom" align="left" color="#FFFFFF" background="#000000" alpha="0.5"/> </panel> <panel name="splash" alias="SPLASH" height="90%" width="100%" valign="bottom" hidden="no" background="#666666"> </panel> </panel> </main> <actions> <action name="processdata"> <sync> <assign property="var:code" value="[object:CAMERA.scanvalue]" /> <play action="splash-return"/> <download downloadcomplete="dosomethingelse" filename="/documents/myfile.xml" url="[var:code]"/> </sync> </action> <action name="camera-return"> <sync> <create target="CAMERA-PANEL"/> <replace type="flipleft" target="SPLASH" replacement="CAMERA-PANEL" time="1"/> </sync> </action> <action name="splash-return"> <sync> <replace type="flipright" target="CAMERA-PANEL" replacement="SPLASH" time="1"/> <delete target="CAMERA"/> </sync> </action> </actions>
There is a chance that the replace action and the delete of your camera within the splash return are overlapping. You may try moving the replace above the sync and adding a 1 sec delay to the sync block which will now contain only the delete action. 

If this doesn't work, feel free to add me as a collaborator to the project and I will take a look at the code. (icahill@rarewire.com)

Kundesupport af UserEcho