PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
OpenNETCF Serial - strings struncated by NULL char
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
OpenNETCF Serial - strings struncated by NULL char
![]() |
OpenNETCF Serial - strings struncated by NULL char |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

