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

Re: OpenNETCF Serial - strings struncated by NULL char by ctacke/>

ctacke/>
Mon Jan 16 19:04:06 CST 2006

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
>



Re: OpenNETCF Serial - strings struncated by NULL char by anbeyon

anbeyon
Tue Jan 17 03:30:48 CST 2006


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