BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-19-2007, 04:13 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default BluetoothSerialPortInfo not returning btssp...

Please Login to Remove!

Hello there,

Firstly I'll admin until a week ago I was a complete Java numpty! Having said that, it was the case for most of the languages I now develop in every day once upon a time...

I seem to 'inherit' projects of all shapes, colours and sizes and get responsible for making them work so, it seems, I have a knack!

Now at the moment I have a bberry app which is now working ok, but I'd like to print a label to a bluetooth printer. I'm working in JDE 4.2.0, using a bberry 8700 and a Zebra QL320Plus is the printer.

I have a small method which at the moment just prints a simple text label, later I'll add more 'intelligence' but I just want to get the damn thing to print *something* for now!

Here's the method :

private void print_receipt() throws IOException {
try {
if (BluetoothSerialPort.isSupported())System.out.prin tln("bluetooth: device supports bluetooth");
else{
System.out.println("bluetooth: device does NOT support bluetooth");
return;
}
// open a connection
BluetoothSerialPortInfo[] info = BluetoothSerialPort.getSerialPortInfo();
System.out.println("Bluetooth Serial Port Info : "+info.toString());
if( info == null || info.length == 0 ) {
Dialog.alert( "No bluetooth serial ports available for connection." );
} else {
StreamConnection _conn = (StreamConnection)Connector.open( info.toString(), Connector.READ_WRITE );
//System.out.println("printing receipt to :"+info.toString());
// send some data
DataOutputStream _dout = _conn.openDataOutputStream();
String receipt_data = "! U1 JOURNAL\n\r";
receipt_data = receipt_data + "! U1 SETLP 5 2 46\n\r";
receipt_data = receipt_data + "this is a receipt.\n\r";
System.out.println("receipt data : "+receipt_data);

_dout.writeChars(receipt_data);
// close the connection
if (_conn != null) {
try {
_conn.close();
} catch(IOException ioe) {
System.out.println("Problem closing connection : " + ioe.getMessage() + ioe.getClass());
}
}
if (_dout != null) {
try {
_dout.close();
} catch(IOException ioe) {
System.out.println("Problem closing output stream : " + ioe.getMessage() + ioe.getClass());
}
}
_conn = null;
_dout = null;
}
} catch(IOException ioe) {
System.out.println("bluetooth: error opening bluetooth connection - " + ioe.getMessage() + ioe.getClass());
}
}

Now, I'm sure there's a better way to debug an app, but I find the System.out.println quite convenient, besides not haveing the benefit of any kind of java training I simply had to bastardise whatever was there...

In the debug window I get :

bluetooth: device supports bluetooth
Bluetooth Serial Port Info : [Lnet.rim.device.api.bluetooth.BluetoothSerialPortI nfo;@c7b82641

IllegalArgumentException
no ':' in URL

As you can see the results returned from BluetoothSerialPortInfo were NOT as expected...

I've tried adding a bunch of additional system prints for info.getServerID etc to see if I can create the required string for the stream connection manually, but then I get "cannot find symbol getServerID" when compiling...

Any help at all would be very much appreciated, thanks in advance!

Cheers!
Offline  
Old 04-19-2007, 04:41 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Update :
I now have an appropriate response from the getSerialPortInfo, I just added [0] where ever info appeared as my development device is only paired with this one other device (the printer), I'll make it better later...

Now I'm getting a RuntimeException :

blocking operation not permitted on event dispatch thread

I'm not (and won't be) running this app on devices connected to a BES so need to create a new thread to run this code and then return to the main thread, right?

There's some great advice on this forum so I'll try them out and let you know how I get on...
Offline  
Old 04-19-2007, 06:53 PM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I have now got rid of this exception and everything appears to be sent to the serial port, still nothing on the printer though so I think there's something wrong with the text I'm sending. I'm going to keep going on this thread until I have a solution, I can't imagine I'm the only person in need of an application that writes data to a label/receipt type printer...
Offline  
Old 04-20-2007, 01:09 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem Solved!

Ok, I have it sorted. In case it helps anybody else I thought I'd complete this thread with the solution.

My print_receipt() method of the class I'm printing the receipt in now looks like this :

Code:
private void print_receipt() throws IOException {
            if(BluetoothSerialPort.isSupported()){
               System.out.println("bluetooth: device supports bluetooth");
            } else {
               System.out.println("bluetooth: device does NOT support bluetooth");
               return;
            }
            String receipt_data = "STUFF YOU WANT TO PRINT";
            BlueWriteThread bt = new BlueWriteThread();     
            bt.setReceipt(receipt_data);
            bt.start();
}
I also have an additional class to handle the thread for the Bluetooth connection :
Code:
private class BlueWriteThread extends Thread {
 private String receipt;
 
 public void setReceipt(String r){
   receipt = r;
 }    
 public void run() {
 
   try {
    // to open   
    BluetoothSerialPortInfo[] info = BluetoothSerialPort.getSerialPortInfo();
    if(info == null || info.length == 0 ) {
       System.out.println("No bluetooth serial ports available for connection."); 
    }
    
     _bluetoothConnection = (StreamConnection)Connector.open(info[0].toString(), Connector.READ_WRITE );
     _dout = _bluetoothConnection.openDataOutputStream();
   } catch(IOException e) {
      System.out.println("Unable to open serial port");  
   } catch(UnsupportedOperationException e ) {
      System.out.println("This handheld or simulator does not support bluetooth.");   
   } 
   
   
   try {
      //send data            
      _dout.writeChars(receipt);
      System.out.println("written to port : "+receipt);
      _dout.flush();      
      System.out.println("PORT: flushed");
      
      //close connection 
      _dout.close();
      _bluetoothConnection.close();
      
    } catch(IOException ioe) {
        System.out.println("Problems reading from or writing to serial port.");
    }
  }
}
This wee module lets me print whatever I like to my Zebra QL320+. I'm actually having a little bit of difficulty formatting the print, at the moment the printer simply prints verbatim and doesn't interpret the commands I'm actually sending using this method.

If I have to adjust this code in anyway to 'cope' I'll let you know.

Hope its useful to someone!

Cheers!
[/code]
Offline  
Old 08-09-2007, 04:18 PM   #5 (permalink)
New Member
 
Join Date: Mar 2007
Model: 8700
Carrier: telcel
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

Im trying to connect a Zebra ZM220 to a BB 8700g via bluethoot, a password is required, what password do you use for connecting your printer whit your BB?

thanks in advance
Offline  
Old 08-27-2007, 11:21 AM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi rmontero,

sorry for the delay in getting back to you, I was involved in a number of other projects and have only got back to this to check now...

By password do you mean in order to pair the devices? If so you have to use Zebra's "Label Vista" program (available for free download) to access the printer's settings and change the "bluetooth mode" and you can enter a pass-key there...

If that's not what you meant let me know and I'l try to assist further - I spent DAYS trying to get these to to talk and get something useful out of the printer and I'd hate for anyone else to have to spend the same time doing it...

Hope this helps!
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.