The XML was improperly formatted.Please escape it if necessary.

CharlesIPTI

Active Member
Licensed User
Longtime User
This may assuredly be a problem with my scanner set up so forgive my Naivety .....

:sign0163:

I have garbled up the examples for AsyncScanSrv and Bluetooth enough to get it to work for my solution..
http://www.b4x.com/forum/basic4andr...als/7669-asyncstreams-tutorial.html#post43578
http://www.b4x.com/forum/basic4andr...ncstreams-two-activity-modules.html#post94451
AND of course
http://www.b4x.com/forum/basic4andr...etooth-bluetoothadmin-tutorial.html#post83697


My design per the articles referenced, was to be able to select a menu button which will allow the user to perform barcode scanning features.
Most importantly was the separation of the feature into a service module.
There will be multiple features available of this genre. Scan current location, Scan to load new batch of orders, etc etc.


In Summary I couldn't load up the BluetoothAdmin and Serial as in the examples, because I have other stuff going on in my activity_create. I do not want to force scan features on load but as afore stated per a menu or button invocation. (its currently in a menu but thats trivial) ...


I have the Mac Address Type 'NameAndMac' (two Strings) its instance "connectedDevice" the BluetoothAdmin and the serial in my process Globals of my activity.
Just like the samples---
Activity_Create as already mentioned is very busy and already very tired so the only addition in it, to this process is a menu item named ScanBatch---
By the way this menu item lists itself like seven times but its the only menu item I have defined !!!!!-- Anyone know why this is happening ??

The events section for the menus of course has the Case "ScanBatch" which calls my sub named ScanBatch
I have combined the processes from multiple subs from the examples here in to this calling sub from the menu selection:
Please advise and comment - I'm worried that this may not be correct...

B4X:
   Sub ScanBatch
   
      If Admin.IsInitialized = False Then
         Admin.Initialize("admin")
         scanSerial.Initialize("scanSerial")      
      End If
      
         If Admin.IsEnabled = False Then
      If Admin.Enable = False Then 
         ToastMessageShow("Error enabling Bluetooth adapter.", True)
      Else
         ToastMessageShow("Enabling Bluetooth adapter...", False)
         'the StateChanged event will be soon raised
      End If
   Else
      Admin_StateChanged(Admin.STATE_ON, 0)
   End If
   
   
End Sub

The Admin_StateChanged
Admin_DeviceFound and the Admin_DiscoveryFinished
are the same as the examples.

Although the latter calls my serial object by my name for it ---> scanSerial. Connect(connectedDevice.Mac)


Then I of course start my service:
B4X:
Sub scanSerial_Connected (Success As Boolean)
   ProgressDialogHide
   Log("connected: " & Success)
   If Success = False Then
      Log(LastException.Message)
      ToastMessageShow("Error connecting: " & LastException.Message, True)
   Else
        StartService(AsyncScanSrv)  
   End If
End Sub

Again the code in my service matches the examples:
Empty Service_Create, in Service_Start check for IsInitialized Close or Init as needed

and in the NewData I call a sub back in the calling activity.. Works great....


THE PROBLEM-->

#1) The error.. I have tried
MsgReceived = BytesToString(Buffer, 0, Buffer.Length, "ISO-8859-1")
MsgReceived = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")

Both result in the XML ERROR "The XML was improperly formatted.Please escape it if necessary."

#2) I'm REALLY Confused as to WHAT is REALLY GOING ON HERE --How much of this will I need to duplicate to create a couple more scan barcode type of features.... . I'm going to need to review this hodge podge for quite some time today to really get whats going on ... For example I'm trying to see what I can do to add another BarCode Scan function for lets say scan current location...

How much of this will I be able to use again versus recreate for the new
scan method. Wil it simply be a different Menu choice calling the same stuff, and I just proces the results differently. If So AWESOME !!!! WIN WIN WIN !!! I appreciate any and all insight or criticism .. :sign0085: :sign0104: :sign0089:



Is this old condition appropriate in this case: ?

Old 10-31-2007, 11:06 PM
Erel Administrator
Basic4ppc Founder
http://www.b4x.com/forum/questions-windows-mobile/1074-what-am-i-overlooking.html#post5570
This is not the value of SQLCmd.
There is a bug in the IDE that causes this message (it tries to parse the string as XML because of the > sign).
It is fixed in the next version.
You can check its value in the watches fields.
 
Last edited:

CharlesIPTI

Active Member
Licensed User
Longtime User
How to continue

What do I check for to avoid re searching for the device if its already ready to go and do a different scan. I shouldn't have to re connect if the device is paired and ready to go after initialization...

Sub ScanLocation

If connectedDevice.Mac <> Null Then
scanSerial.Connect(connectedDevice.Mac)
Admin_StateChanged(Admin.STATE_ON, 0)
Else


this seems to be missing something
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The "XML was improperly formatted" message is an IDE message. Try to log the value instead. I guess that the bytes are not valid string. Though it can be an issue in the IDE.

If I remember correctly you once said that you call Activity_Create yourself. This may be the cause for the multiple menu items.

What do you mean with "ready to go"? You can use Serial.GetPairedDevices to find the addresses of the paired devices.
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Thanks

Firstly Thank you for your time I earnestly appreciate it

I use Booleans to safeguard / protect entries into various portions of the
Activity_Create.

Is FlagOne true OK you can now build this list
Is FlagTwo true OK then you can now do this portion of code blah blah.

I though of that I even made a new flag to secure the UI creation portion
where I manually drop the views and stuff so its not creating the menu items multiple times.

"ready to go" === as In I don't have to GoFind devices again to get he scanner.. I'll gladly try "GetPairedDevices"

but once I find one do I need to check that Bluetooth is initialized and then just call Admin_StateChanged(Admin.STATE_ON, 0) to start the scan ???

Lastly has anyone heard of the menu problem i mentioned. I have only one menu coded but several appear in the UI
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Fixed --- WOW !!

The flags I was setting in the activity create needed to be set outside of the activity create for them to be recognized correctly preventing untimely entry into restricted portions of the sub until various other tasks were completed.

It always 'appeared' that the services ran out and did their work and the remainder of the sbu was not called especially the areas 'protected' by flags.
However these areas were getting their flag toggled as the sub continued on whilst the services additionally performed their tasks.

Thusly UI creation for example occurred like 7 - 15 times easily producing the java.lang.IndexOutOfBoundsException. when attempting to use the AHQuickActionMenu.

This of course additionally explains how two menu entries quickly turned into some 15 - 20 menu entries all with the same two names
 
Upvote 0
Top