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
Visitor
Posts: 1
Registered: ‎10-11-2010
My Device: Not Specified

USB Serial Port Communication

I'm new to developing applications for Blackberry, so bear with me if this question is too naive.  I have searched and searched, but can't figure out what I'm doing wrong.

 

My goal is to develop a simple app to collect GPS coordinates and periodically send them off over USB to a PC.  Here is the relevant code I am using:

 

StreamConnection serial = (StreamConnection)Connector.open("comm:USB;baudrate=19200;channel=USB1");
DataOutputStream os = serial.openDataOutputStream();
String outline = "Hello World!\n\r";
os.writeChars(outline);

 

I opened up the Desktop Manager and connected to each of the COM ports called RIM Virtual Serial Port v2 with putty.  Neither of these displays anything when I run my program.

 

 

I feel like the code is so straight forward that it can't be too wrong, but I am far less confident on the process for actually opening a serial connection from the PC.  Do I need to have the Desktop Manager running? Do I need to do anything to attach the virtual COM ports to a physical COM port? Any other things I'm doing wrong?

 

Thanks for the help and patience.

-Justin

Developer
Posts: 17,017
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: USB Serial Port Communication

welcome to the support forums.

i would suggest you take a look at the usb demo shipping with the jde/ejde.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
New Contributor
Posts: 3
Registered: ‎10-14-2010
My Device: Not Specified

Re: USB Serial Port Communication

I looked and have tried different things, and none of them are working.  In fact its bizarre, the write seems to block, which I am not used to on serial port writes.

 

The following is a code excert of what I am doing.  The "Sent: " message is never see and if I connect to the serial port on PC with putty, on either one I have, I get nothing.

 

connection = (StreamConnection) Connector.open("comm:USB;channel=JDE_USBClient");
outputStream = connection.openOutputStream();
inputStream = connection.openDataInputStream();
Runnable runnable = new Runnable() {
	public void run() {
		printlnTestResult(true, "Send thread started");
		int count = 0;
		String message = "Hello Jon!!!";
		while (isRunning()) {
			if ((count % 10) == 0) {
				printlnTestResult(true, "About to send: " + message);
				try {
					outputStream.write('a');
//										outputStream.writeChars(message);
				} catch (IOException e) {
					printTestResultError(e);
				}
				printlnTestResult(true, "Sent: " + message);
			}
			count++;
			Util.sleep(500);
		}
	}
};
(new Thread(runnable)).start();

 

 

 

New Contributor
Posts: 2
Registered: ‎10-03-2011
My Device: Curve 8520 (also developing fro 9300)
My Carrier: Vodacom

Re: USB Serial Port Communication

Hi

I think we are in the same ship.

I want to simply connect my BB to normal Hyper Terminal for now. Later one of my colleagues will make a device that will work like a PC with Hyper Terminal.

I have 2 virtual Rim Serial ports that is always visible in my Device manager, whether I have a phone plugged in or not.

I can connect to either of these using hyper terminal but never receive the data sent. I sent data over Bluetooth and saw that the sending and receiving of data is the same in the USB sample, but the connection is slightly different.

I tried the following connection commands:

(StreamConnection)Connector.open( "comm:COM1;baudrate=9600;bitsperchar=8;parity=none;stopbits=1"); //Like in the manual, but this give an exception

(StreamConnection)Connector.open("comm:USB;channel=JDE_USBClient");  //like in the USB demo, but nothing happens. Connection is successfull, but can't send or receive data using the functions that works for Bluetooth.

(StreamConnection)Connector.open("comm:USB;channel=JDE_USBClient;baudrate=9600;bitsperchar=8;parity=none; stopbits=1");

which is basically a combination of the 2 trying to make it work on a certain speed etc. But still no success.

 

I noticed that my Bluetooth connect has 2 parameters:

this._bluetoothConnection = (StreamConnection)Connector.open( deviceName, Connector.READ_WRITE );

So I tried adding it to all 3 versions of the commands, and it still gave me the same responses.

 

Any help would be appreciated.