BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-02-2007, 10:16 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 how to write a string as single byte chars?

Please Login to Remove!

Hi folks,

I'm trying to send a string to the serial port using a DataOutputStream. However when using writeChars(string s) it sends the characters as a series of two byte chars, filling the space with a null char.

I have looked at a direct dump from the device connected to the serial port, I'm trying to send the string "! 200 200 600 1" and the device is receiving char(00)char(21)char(00)char(20)char(00)char(30)ch ar(00)char(20)char(00)char(32)... instead of simply char(21)char(20)char(30)char(20)char(32)... I think the char(00) is a result of writeChars trying to send char(0x21) where I just want it to send char(\x21) i.e.the single byte value.

Any ideas?

Cheers!
Offline  
Old 07-02-2007, 12:03 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2007
Location: La Crosse, WI
Model: 7130e
PIN: 32bba42d
Carrier: US Cellular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

if i can find my binder from classes last year, i'll help you out - i know it should be somewhat decent to figure out, but i haven't looked at anything CS related since summer started haha
Offline  
Old 07-02-2007, 12:14 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2007
Location: La Crosse, WI
Model: 7130e
PIN: 32bba42d
Carrier: US Cellular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

then again, are you scripting?
Offline  
Old 07-02-2007, 04:05 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

Hey Eclipse,

Thanks for replying, I figured it out anyway - I'm coverting the string to bytes using String.getBytes(); and then using write(byte[], 0, byte.length); to write the entire string to the DataOutputStream.

Not sure if its the best/easiest way, but it got rid of all the char(00) which is the main thing!

Thanks again!
Offline  
Old 07-03-2007, 01:54 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2007
Location: La Crosse, WI
Model: 7130e
PIN: 32bba42d
Carrier: US Cellular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

well good, i'm glad you got it to work

it's my major, i should have known it like the back of my hand... but sometimes i slip during summer.... kinda like i have to go back and study Calc1 and Calc2 now before fall
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.