PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework OpenNETCF Serial - strings struncated by NULL char

Reply

OpenNETCF Serial - strings struncated by NULL char

 
Thread Tools Rate Thread
Old 16-01-2006, 04:41 PM   #1
anbeyon@btinternet.com
Guest
 
Posts: n/a
Default OpenNETCF Serial - strings struncated by NULL char


Dear all,

I am having some trouble using the OpenNETCF libraries. Actually It's
VB.NET related.

My data being read from the serial port is being truncated in some way.

This is what I do.

<Snippet>

Dim sBuffer As String = ""
Dim Buffer(MasterPort.InBufferCount - 1) As Byte

Buffer = MasterPort.Input
sBuffer = sBuffer + UCase(System.Text.Encoding.ASCII.GetString(Buffer,
0, Buffer.Length))

</Snippet>

I am expecting to read a 6 byte command from the port and this is what
is reported by sBuffer.Length. However if one of the chars is the
string is = 0 the string is truncated.

Chars up to the 0 char can be read using sBuffer.Substring(x,y) those
including the 0 char and afterwards cannot.

How can I get around this problem ?

Thanks

Anbeyon

  Reply With Quote
Old 17-01-2006, 01:04 AM   #2
Guest
 
Posts: n/a
Default Re: OpenNETCF Serial - strings struncated by NULL char

A 0 data byte is interpreted as a null, and string are null terminated, so
the behavior you see is expected. What are you expecting the 0 to become in
the string?

-Chris

<anbeyon@btinternet.com> wrote in message
news:1137429714.093189.297330@g44g2000cwa.googlegroups.com...
> Dear all,
>
> I am having some trouble using the OpenNETCF libraries. Actually It's
> VB.NET related.
>
> My data being read from the serial port is being truncated in some way.
>
> This is what I do.
>
> <Snippet>
>
> Dim sBuffer As String = ""
> Dim Buffer(MasterPort.InBufferCount - 1) As Byte
>
> Buffer = MasterPort.Input
> sBuffer = sBuffer + UCase(System.Text.Encoding.ASCII.GetString(Buffer,
> 0, Buffer.Length))
>
> </Snippet>
>
> I am expecting to read a 6 byte command from the port and this is what
> is reported by sBuffer.Length. However if one of the chars is the
> string is = 0 the string is truncated.
>
> Chars up to the 0 char can be read using sBuffer.Substring(x,y) those
> including the 0 char and afterwards cannot.
>
> How can I get around this problem ?
>
> Thanks
>
> Anbeyon
>



  Reply With Quote
Old 17-01-2006, 09:30 AM   #3
anbeyon@btinternet.com
Guest
 
Posts: n/a
Default Re: OpenNETCF Serial - strings struncated by NULL char


Hi Chris

Thanks for the reply. I realised that what I was seeing was what I
should expect I just wasn't sure how to deal with it.

The 0 byte needed to be interpreted as a 0.

I worked around it bu using the .Chars() method and inspected each
value using that.

Thanks

Anbeyon

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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