9 Replies Latest reply on Aug 2, 2012 1:28 PM by Paily Njarlangattil

    Rhodes Bluetooth Connectivity in Non-Motorolla Win Mobile Devices

      Hello

      I developed a Rhodes application that will run on a JANAM XM66 Windows Mobile 6 Device. The application connects to an Oniel 4te printer via bluetooth based on the Rhodes Bluetooth API. Since The device is not a motorolla device and the application was written under the  SDK. version 2.2.6, i cannot use the APD approach .

       

      Unfortunately i ran into a problem.

       

      The original iteration of the program worked by creating a Bluetooth session every time i needed to print then immediately disconnect after printing. This was fine for a time, but because the device had to scan for all Bluetooth devices in the area every time i needed to connect, this was deemed impractical if i needed to print a lot of times or if there is a lot of Bluetooth devices within range. Unfortunately the "Connection without UI" approach to connect to a specific Bluetooth device is not available for Windows Mobile devices (only IOS and android devices) , so i am stuck with the slow way of creating a Bluetooth session.

       

      So another approach was to make a longer lasting connection. I would connect to the device and only disconnected at the end of the day, I was able to change the Bluetooth time out values in the printer and make sure the handheld doesn't power off to ensure that there isn't a disconnection, but there is still 2 scenarios where the application freezes.

       

      1) If the Bluetooth printer radio is turned off manually

      2) The Bluetooth session disconnects due to the devices leaving Bluetooth range.

       

      When either of these scenarios occur, i cant seem to find a way to get the status of the session, so when i blindly try to print, the application freezes on me.

       

      I tried using the session call back routine in the Rhodes Bluetooth API, but that is not fired when the session disconnect.

       

      I tried to query by using the get_status routine, but regardless of when it is connected or disconnected, it returns 0 (no data read).

       

      I tried placing a exception handler , i.e

      begin       

           rho::BluetoothSession.write_string       

      rescue

      recovery code

      end

      but it still freezes instead of going to he rescue clause.

       

      I was able to duplicate this same occurrence using the standard Bluetooth Chat program bundled in with the Rhodes Sample API (https://github.com/rhomobile/rhodes-system-api-samples/tree/master/app/BluetoothChat) , even with other Bluetooth devices (such as my phone) using the following steps

       

      1) Connect to Bluetooth device as client.

      2) send data

      3) cause the session to terminate (by either turning off the other Bluetooth device's radio or having one of the devices to exit Bluetooth range).

      4) attempt to send data again and watch the application freeze.

       

      I sent a report to rhomobile.zendesk.com but in the end, they said that it seems to be a bug and they will follow up with their team, then forwarded me towards this site and their sales department for purchasing direct application support.

       

      The question i have is has anyone else encountered this problem, and if so, were you able to fix it, and how?

        • Re: Rhodes Bluetooth Connectivity in Non-Motorolla Win Mobile Devices
          Glenn Sayer

          I have customers that put bar codes on the printers to do the BT syncing.  They walk up to the printer they want to connect to, scan the BT mac address that is encoded into the bar code and then device connect and don't require the user to do a scan and select.

            • Re: Rhodes Bluetooth Connectivity in Non-Motorolla Win Mobile Devices

              but how do you initiate a bluetooth session with the mac address?

               

              The only way i can see from the Rhomobile Bluetooth API is using the create_client_connection_to_device routine,  which i mentioned earlier, is only available for IOS and android devices.

                • Re: Rhodes Bluetooth Connectivity in Non-Motorolla Win Mobile Devices
                  Peter Arcuri

                  Hi Paily, I have created a heldesk ticket to assist with.... we would need sample code in an attempt to replicate the issue. Is there any way you can furnish a snipet of your app?

                    • Re: Rhodes Bluetooth Connectivity in Non-Motorolla Win Mobile Devices

                      I added a zip with a sample project that i created to reproduce the issue. You will notice that the application code is almost identical to the Bluetooth chat sample application provided by rhodes. i created this application to excplain the problem without having to load any special data.

                       

                       

                      Note:

                      i added a new proceedure called log_data(log_file, log_message, header_message) which generates and appends to a custom log file every time it is called.

                      for this sample application, the log file is SDC_DUMP.XML, which can be found in the \SDC Mobile\rho\apps directory after the proceedure is called at least once.

                       

                      You will notice that i call the log_file several times

                       

                      1)  on the on_send routine, before calling the Rho::BluetoothSession.write_string routine, i log the Rho::BluetoothSession..get_status value.

                      2) on the on_send routine, Right after call to the Rho::BluetoothSession.write_string routine, i log down the message sent if the data is sent

                      3) on the on_send routine, on the rescue clause for the  Rho::BluetoothSession.write_string routine, i log down that there was an error in sending the message string

                       

                      4) on the create_session_callback routine, i log that i created a session call back for the bluetooth session

                      Rho::BluetoothSession.set_callback($connected_device_name, url_for(:action => :session_callback))

                      5) On the session_callback routine there i log if there is any call_back triggers (such as the other device sending me data or disconnecting).

                       

                      other than this, its pretty much the same as the bluetooth chat program.

                      Note for testing the mobile device i used was a Janam XM66 device (windows mobile 6), and the application was compiled against rhodes sdk 2.2.6.

                      The other bluetooth device was a datamax-oniel mf4te bluetooth printer

                       

                      here are the steps i follow

                      1) run the application

                      2) click on the bluetooth link on the main screen to get to the bluetooth application

                      3)Click on the connect as client button (only option i have since i am using windows mobile 6 device, not android or ios)

                      this will start scanning for all available devices, and i select my bluetooth device (in this case my  datamax-oniel  mf4te printer) from the list.

                      4) once i am connected i enter a message to send to the device then press the Send command.

                      For the oniel printer i send the string {TP} to print a test page. my printer prints test page.

                      5) I manually disconnect the other device. I dont mean click on the disconnect button on the page, i mean iether a) move mobile device outside bluetooth range of the other device or b) turn off the bluetooth radio on the other device.

                      6) Try to send the same string message again. You will notice that the message {TP} does not appear.

                      6) Try sending the same string message again or pressing the disconnect buttons. You will notice the application has frozen.

                       

                      When checking the sdc_dump.xml file

                      i get the following

                      <datetime>

                          2012-06-21T13:08:12-07:00

                      </datetime>

                      <headerinfo>

                          setting call_back

                      </headerinfo>

                      <datetime>

                          2012-06-21T13:08:23-07:00

                      </datetime>

                      <headerinfo>

                          on_send get status

                      </headerinfo>

                      0

                      <datetime>

                          2012-06-21T13:08:23-07:00

                      </datetime>

                      <headerinfo>

                          on send sent write string

                      </headerinfo>

                      {TP}

                      <datetime>

                          2012-06-21T13:08:50-07:00

                      </datetime>

                      <headerinfo>

                          on_send get status

                      </headerinfo>

                      0

                       

                      From this you can see the following

                      a) the session_callback routine never fired when the device disconnected

                      b) When the message was sent properly, get_status was 0 (no data read)

                      c) after the device was disconnected, get_status was still 0, when i was expecting a -1 (error)

                      d) when trying to send data, it never fell into the rescue clause and the device froze.

                       

                      to prove to myself this is not a problem with my printer, i repeated the test where instead of the printer i used my android samsung galaxy phone with the GetBlue app (simple bluetooth commun ication app), and got the same behavior.