Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Developer
Posts: 10
Registered: ‎04-08-2009
My Device: Not Specified
Accepted Solution

Signature problem when running BluetoothDemo program on Blackberry 8320

Hi,

 

I am attempting to communicate from my computer to the Blackberry 8320 using a Bluetooth serial transmitter/receiver.  The "BluetoothDemo" program is not function properly.  When I run it, I first see a blank screen with "Bluetooth Sample" at the top.  I click the trackball and I get a menu with options "Listen for Connections" and "Full Meno".  I click Listen for Connections and a screen comes up that says "Connect external device and then type something..."  I type something on the Blackberry, and the letters appear, but no other options appear for verifying a Bluetooth connection.  I have already paired the Bluetooth device with the Blackberry, but the connection fails to show up when I run the BluetoothDemo program. When I click the trackball again, I see the full menu with "Close serial port", "Get DTR", etc.

 

I believe there is a problem with the secure API signatures.  Obviously the "BluetoothDemo" program is not executing past the very first stages.  When I debug on the Blackberry, I see the following output from the console that leads me to believe there is a problem with the signatures:

 

ocusHistory: Focus lost; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
FocusHistory: Focus gained; App Home Screen; Component net.rim.device.api.ui.MediaController
JVM: bklt @286061: timer
JVM: bklt @286061: idle 15
JVM: bklt @292270: setTimer 15
FocusHistory: Focus lost; App Home Screen; Component net.rim.device.api.ui.MediaController
CMM: BluetoothDemo(4738) no sig from 0x33
Starting BluetoothDemo
CMM: BluetoothDemo(4738) no sig from 0x33
Started BluetoothDemo(167)
Foreground BluetoothDemo(167)
FocusHistory: Focus gained; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
FocusHistory: Focus lost; App Home Screen; Component net.rim.device.apps.internal.ribbon.launcher.RibbonIconField
FocusHistory: Focus lost; App Bluetooth Demo; Component NULL
FocusHistory: Focus gained; App Bluetooth Demo; Component net.rim.device.api.ui.menu.DefaultMenuListField
FocusHistory: Focus lost; App Bluetooth Demo; Component net.rim.device.api.ui.menu.DefaultMenuListField
BT: allocSerialPort a0d729a8
BT: sdpAddRecord
BT: allocSdpAttributeData
FocusHistory: Focus lost; App Bluetooth Demo; Component NULL
BT: SppWrite-1 failed: 1
Failed to write data. Exception: java.io.IOException: BtSppWrite failed

 

I was confused about initially running the BluetoothDemo program, and originally built and generated an alx file for the program com_rimbluetoothserialportdemo, which I think is used by the BluetoothDemo program.  The com_rimbluetoothserialportdemo program actually connected to the Bluetooth tx/rx, as shown by the devices status light staying solidly on instead of blinking (When BluetoothDemo is running the status light is blinking, indicating no connection). When I switch between the workspaces in which I have these projects, the set of keys is unsigned and I have to sign it again, which appears to cause the keys in the other workspace to become unsigned.  As further evidence of the strange signing problem, occasionally when I run one or other on the Blackberry there is an error that says the app is not signed.

 

I feel like deleting the workspace and alx file for com_rimbluetoothetc might be a step in the right direction.  Am I correct in assuming that the "no sig from 0x33" is a secure API signature problem?  Could BluetoothDemo be accessing com_rimbluetoothserialport and be denied because it doesn't have signatures?  Thank you for any help you can provide.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

My initial reaction is this is not a signing problem  Leter I will work through your notes, but first can you confirm that you are using a correct JDE for the device.  For the 8320 the highest OS I believe is available is 4.5, which means you should be using JDE 4.5 or lower.  In fact, it is likely the device is running 4.2.2, unless you have upgraded it, so you should running JDE 4.2.1.

 

On to your post:

 

"I have already paired the Bluetooth device with the Blackberry, but the connection fails to show up when I run the BluetoothDemo program."

What profile does your device use?  You will only see devices that use Serial Port Profile.  If it is recognized as anything else, you will not see it here.

 

"When I switch between the workspaces in which I have these projects, the set of keys is unsigned and I have to sign it again, which appears to cause the keys in the other workspace to become unsigned.  "

Switching workspaces should have no effect - remember it is the cods that are signed, not the workspaces.  Each time you regenerate the cod it effectively becomes unsigned. 

 

"no sig from 0x33" is a secure API signature problem?

You can ignore this message - I think this is a signature that is available to RIM - potentially this identifies RIM modules from other modules.  Anyway, it has no effect on how your code works.

 

I would recommend that you remove both test applications from your device, and install only one and see if you can get some consistency in what you are seeing. 

New Developer
Posts: 10
Registered: ‎04-08-2009
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

Hi Peter, thanks for writing back.  I am running the 4.5.0.81 OS on my BB 8320, and I was running the Bluetooth Demo program for JDE 4.5.  I just tried the Demo for JDE 4.3, but I didn't have success with that.

 

After I pair the Bluetooth device, when I look at its properties, the Services field has the value "SPP" for serial port profile, so I think it is connecting properly.  Some of the other bluetooth threads I've found say this value is "COM1".  Is SPP wrong?

 

Here is the code snippet where it hangs.  The bold sections are never reached; "_portinfo" is always NULL, and yet I never see the "Bluetooth not supported" message.  I don't know what happens to the code here.  I've tried debugging at this point but I can't figure it out.

 

package com.rim.samples.device.bluetoothdemo;

import net.rim.device.api.bluetooth.BluetoothSerialPort;
import net.rim.device.api.bluetooth.BluetoothSerialPortInfo;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

final class AppScreen extends MainScreen
{

private BluetoothSerialPortInfo[] _portInfo;

public AppScreen()
{
setTitle("Bluetooth Sample");

//Determine if this BlackBerry model or simulator supports Bluetooth.
if (BluetoothSerialPort.isSupported())
{
// Get the BluetoothSerialPortInfo.Retrieves serial port information for
// the currently paired devices.
_portInfo = BluetoothSerialPort.getSerialPortInfo();

int numServices = _portInfo.length;

//Create a MenuItem for each Bluetooth device we can connect to.
for (int count = numServices - 1; count >= 0; --count)
{
String serviceName = _portInfo[count].getServiceName();

// A single device can provide multiple serial port connections (or services).
// Add a menu item only to the service that corresponds to the "Hi there" connection,
// or the "COM X" connection (if we are pairing with a PC).
if(serviceName.indexOf("Hi") != -1 || serviceName.indexOf("COM") != -1)
{
DeviceMenuItem deviceMenuItem = new DeviceMenuItem("Connect to: " + _portInfo[count].getDeviceName(), _portInfo[count]);
addMenuItem(deviceMenuItem);
}
}

addMenuItem(_listenItem);
}
else
{
add(new LabelField("Bluetooth is not supported on this BlackBerry or simulator."));
}

}

 

When I test the other program "Bluetooth Serial Port Demo", I get similarly confused trying to debug it.  I believe a connection is made with the Bluetooth device (LED status on Bluetooth device goes solid indicating conection, blue LED on Blackberry indicating bluetooth connection blinks), but I cannot transmit or receive data.  I've been running the 4.5 version of Bluetooth Serial Port Demo, and the 4.3 version is not Building for some reason.

 

Peterstrange, thanks for your help so far!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

Some questions:

 

" I just tried the Demo for JDE 4.3, but I didn't have success with that."  These demos have actually not changed that much over the years, so I don't understand why the 4.3 one will not work for you.  Can you tell me what the problem is?  But this is more for interest rather than to help with this problem.

 

"the Services field has the value "SPP" for serial port profile" - looks fine to me, not sure why we would have COM on the device, it doesn't have COM ports.

 

"The bold sections are never reached;" - I'm confused by this.  Any device that runs 4.5 will support Bluetooth and I am sure you have Bluetooth enabled, so your code should go through:

_portInfo = BluetoothSerialPort.getSerialPortInfo();

 

I don't think I've even seen _portIinfo being null after that statement, though it can be a 0 length array.

 

Can you add a

System.out.println("Found " + numServices + " Devices.");

after the

int numServices = _portInfo.length;

and debug on the device, to see if the array exists and is not 0 length..

 

This demo program (BluetoothDemo) gives you the option as to which device it connects to. 

 

The other demo (BluetoothSerialPortDemo) does not.  When it starts it looks at the BluetoothSerialPort.getSerialPortInfo() devices, and just chooses the first of these to connect with.  Given this program is actually seeing a device, further suggests that _portInfo is not null.  So it will attempt to communicate with the device, which is what you see.  However you need to verify that the data it sending is understood by the device.  What does you device expect any connecting device to do?  What does it expect to be sent first?

New Developer
Posts: 10
Registered: ‎04-08-2009
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

 
I inserted the print statement as you suggested, and it returns "1" (for some reason, the code that comes with the Eclipse plugin uses "numServices" while the code I downloaded from the Blackberry site uses "numDevices" and now I'm using the latter).  Despite this, _portinfo still seems to be "null".  The program then reads _portinfo.length value and if it is greater than one it initiates the connection; however, since it is one, the connection is not made.

//Create a MenuItem for each Bluetooth device we can connect to. DeviceMenuItem deviceItems[] = new DeviceMenuItem[numDevices]; for (int count = numDevices - 1; count > 0; --count) { deviceItems[count] = new DeviceMenuItem("Connect to: " + _portInfo[count].getDeviceName(), _portInfo[count]); addMenuItem(deviceItems[count]); }

 

The Bluetooth device is connected to my computer through a virtual serial port; the word length, stop bits, flow control and baud rate are set appropriately.  There is an LED on the Bluetooth device that blinks when data is transmitted or received; when I type in hyperterminal the data LED blinks, indicating transmission, but I have yet to see it blink indicating received data from the Blackberry.
I'm a Java novice; is there a chance resources or libraries could be missing from the Blackberry?  When I open the BluetoothDemo.jdw project from the Blackberry site, it opens a com_rim_bluetoothserialportdemo and com_rim_demores.  Currently I am only downloading the alx file BluetoothDemo.alx to the Blackberry; do I need to download the other projects as well?
 Also, I have not made any further progress on why bluetoothserialportdemo locks up after connecting to the Bluetooth device.
Thanks again for your help Peter!  Any further insights would be greatly appreciated.
New Developer
Posts: 10
Registered: ‎04-08-2009
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

Ah, maybe I need to download the com_rim_demores resources onto the Blackberry?  I just created an alx file and downloaded, but the serial port demos still don't work...
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

"I inserted the print statement as you suggested, and it returns "1" (for some reason"

Then you do have one.  This statement would die with a null pointer exception if there wasn't any. 

 

"Despite this, _portinfo still seems to be "null"."

What makes you say this?

In the code above, you filter according to the device name, so if you don't see a matching device, you may assume there are none. 

The filter looks like:

if(serviceName.indexOf("Hi") != -1 || serviceName.indexOf("COM") != -1)

so if the device name does not contain "Hi" or "COM" you will ignore it.  Or have you removed this check?

 

"The program then reads _portinfo.length value and if it is greater than one it initiates the connection"

Which program is this?  I don't think I've seen a check like that in either of the supplied samples.

 

"is there a chance resources or libraries could be missing from the Blackberry?"

These run standalone in the later levels of the JDE.

 

I think the easiest program for you to work with is BluetoothSerialPortDemo, as this will just connect to the first Bluetooth device it finds.  Have a look at what it actulaly does and match that to what you expect to see.

 

If you are having troubles debugging on a live device, you might find this video useful:

http://www.blackberry.com/DevMediaLibrary/view.do?name=DebugLiveDevice

 

I've just spent 30 minutes attempting to get my computer, which has built-in bluetooth, to talk to my Blackberry running BluetoothSerialPortDemo without success.  Yet it talked immediately with a Bluetooth puck I have here.  Vry frustrating, but I've timed out so can't do any more today.  Hope you get further.

New Developer
Posts: 10
Registered: ‎04-08-2009
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

 
I have indeed removed that check on the service name.  Today I did some debugging with the Bluetooth Serial Port Demo program and the Bluetooth device is definitely connecting with the Blackberry, the data transfer just does not work.  I found the segment of code where the program hangs:

try { int type, offset, count; String value; _dout.writeInt(JUST_OPEN); _dout.flush(); for (;;) { type = _din.readInt(); if (type == INSERT) { offset = _din.readInt(); value = _din.readUTF(); insert(value, offset); } else if (type == REMOVE) { offset = _din.readInt(); count = _din.readInt(); remove(offset, count); } else if (type == JUST_OPEN) { // send contents to desktop value = _infoField.getText(); if (value == null || value.equals("")) { _dout.writeInt(NO_CONTENTS); _dout.flush(); } else { _dout.writeInt(CONTENTS); _dout.writeUTF(_infoField.getText()); _dout.flush(); } } else if (type == CONTENTS) { String contents = _din.readUTF(); synchronized(Application.getEventLock()) { _infoField.setText("TEsT"+_din.readUTF()); }

 

 It seems that the Blackberry is waiting for an initial write from the Bluetooth-connected device, and either it is not receiving that write or it is not processing it.  I just had the thought that I should make sure the Bluetooth device is connected using a null modem cable instead of a straight serial cable... maybe the Blackberry is actually not receiving any data.
 I was working with a group member who is our java whiz, and he couldn't figure out what was going on in the above segment either.  Thanks again for your help, you're the man Peter. 
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

Not sure your reading of the code is correct.

 

_dout.writeInt(JUST_OPEN);
_dout.flush();

 

These two statements will write output - that seems to be the first thing that the code actually does.  Then it goes into a read loop, but assumes a specifically formatted data.

 

In my test, I removed these and replaced it with something that I thought would work, and I vary it depending on the device.  As noted yesterday O picked up data from a GPS Puck - these things just send data, they never expect anything back.  So my code looks like this:

 

byte [] buffer = new byte [1024]; for (;;) { int len = _din.read(buffer); String justRead = "Read: " + Integer.toString(len) + " bytes: " + new String(buffer, 0, len) + '\n'; System.out.println(justRead); }

 

New Developer
Posts: 10
Registered: ‎04-08-2009
My Device: Not Specified

Re: Signature problem when running BluetoothDemo program on Blackberry 8320

This works!  I commented out the big if statement block, and now the BB is receiving the data I type into hyperterminal and printing it in the debugger window.  Peter, you saved my project!  Thank you!