BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-02-2007, 09: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, 11:03 AM   #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, 11:14 AM   #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, 03: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, 12: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

Lot 28 OMRON FN515-PS221 CPU01P ID211 ID212 OD212 OD411 NC011 NC022 MB081 MB043
$49.99
Lot 28 OMRON FN515-PS221 CPU01P ID211 ID212 OD212 OD411 NC011 NC022 MB081 MB043 pictureAllen Bradley 1764-LSP Micrologix 1500 Processor Unit Ser B Rev B FRN 5 1764LSP
$69.99
Allen Bradley 1764-LSP Micrologix 1500 Processor Unit Ser B Rev B FRN 5 1764LSP pictureLot 38 OMRON Modules PS221 M1000H CPU01AP CPU01A II001 ID211 NC011 NC022 MX212
$49.99
Lot 38 OMRON Modules PS221 M1000H CPU01AP CPU01A  II001 ID211 NC011 NC022 MX212 pictureWaring Pro Prep Chopper Grinder Commercial Food Processor WCG75
$159.99
Waring Pro Prep Chopper Grinder Commercial Food Processor WCG75 pictureOmron C200H PLC System w/ CPU02, ME431, (2) ID212, OD211, (2) OC222 cards
$275.0
Omron C200H PLC System w/ CPU02, ME431, (2) ID212, OD211, (2) OC222 cards picture






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