View Single Post
  #6   Spotlight this post!  
Unread 25-02-2009, 21:52
EHaskins EHaskins is offline
Needs to change his user title.
AKA: Eric Haskins
no team (CARD #6 (SCOE))
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Elkhorn, WI USA
Posts: 998
EHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond repute
Send a message via MSN to EHaskins
Re: recieve data from cRIO

Quote:
Originally Posted by byteit101 View Post
Thanks! now we can see something, it looks like ?M? for each packet, and changes to variations of that, ?p? ?r? ??? etc... changing the encoding changes the ? to other chars, but it looks weird (wiresharks verifies that our custom packet works, and looks normal there)
If you're just trying to get the printed strings, you'll need to do some data processing. Here is some code which should work, and I'm leaving it in VB.net just to irritate you C# bigots.

Code:
        Dim reader As New BinaryReader(New MemoryStream(data))

        reader.ReadBytes(26) 'Skip the automatically sent data (team number, battery, DS in/outs, etc.)

        SequenceNumber = reader.ReadByte()

        Dim printedString = New String(Text.Encoding.ASCII.GetChars(reader.ReadBytes(reader.EReadUInt32())))
        Me.PrintedString.Add(printedString)
        Dim errorString = New String(Text.Encoding.ASCII.GetChars(reader.ReadBytes(reader.EReadUInt32())))
        Me.ErrorStrings.Add(errorString)

        Dim dataSize = reader.EReadUInt32()
        Dim userData As Byte() = reader.ReadBytes(dataSize)
BinaryReader.EReadUInt32 is an extension method on BinaryReader since I had issues reader UInt32s from the robot. Here is the extension methods file.

Code:
Imports System.IO
Imports System.ComponentModel
Imports System.Collections.ObjectModel
Imports System.Runtime.CompilerServices

Public Module BinaryReaderExtensions
    <Extension()> _
    Public Function EReadUInt32(ByVal reader As BinaryReader) As UInt32
        Dim bytes = reader.ReadBytes(4)
        Return bytes(0) * 255 ^ 3 + bytes(1) * 255 ^ 2 + bytes(2) * 255 ^ 1 + bytes(3)
    End Function

    <Extension()> _
    Public Function EReadUInt16(ByVal reader As BinaryReader) As UInt16
        Dim bytes = reader.ReadBytes(2)
        Return bytes(0) * 255 ^ 1 + bytes(1)
    End Function
End Module
__________________
Eric Haskins KC9JVH