Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   recieve data from cRIO (http://www.chiefdelphi.com/forums/showthread.php?t=75085)

byteit101 21-02-2009 16:27

recieve data from cRIO
 
We have a custom dashboard (written in C# .net or VB .net) and it is supposed to receive the packets coming from the DS on port 1165 of type UDP. we have the cRIO running the following program based off the dashboard data example:
Code:

...
...
void RobotMain()//so it executes even if disabled
{
                Dashboard &dashboard = m_ds->GetDashboardPacker();
                while (true)
                {
                        dashboard.Printf("It's been %f seconds, according to the FPGA.\n", GetClock());
                        dashboard.Printf("451!|distance=2|flywheel=%f|!451\n", 1);//our custom packet of data
                        dashboardDataFormat.PackAndSend();
                        Wait(0.02);
                }
}
....
...

and we have recieved on our custom dashboard... nothing, we changed the dashboard.printf to regular printfs and still nothing
here is the .net code in C#:
Code:

/*init function*/
        UdpClient cRIO = new UdpClient();
        cRIO.Bind("10.4.51.5",1165);
/*end init*/
/*in the start button click*/
        IPEndPoint ipend = new IPEndPoint(IPAddress.Any, 1165);
        this.textBox1.Text = cRIO.Recieve(ref ipend);
//*end button*/

and the code pauses and never recieves anything from port 1165, I tried out wireshark, and tons of packets are coming in, but I get nothing, what are we doing wrong?

EHaskins 21-02-2009 21:00

Re: recieve data from cRIO
 
Here is the applicable code from my dashboard. It uses async calls so its a little more complicated.

Code:

    Sub BeginGetDataAsync() Implements IDashboardClient.BeginGetDataAsync
        _listening = True
        _client = New UdpClient(DS_TO_PC_LOCAL_PORT)
        _client.BeginReceive(AddressOf Me.GetDataAsync, Nothing)
    End Sub

    Sub GetDataAsync(ByVal result As IAsyncResult) Implements IDashboardClient.GetDataAsync
        Try
            Dim endPoint As IPEndPoint = Nothing
            Dim bytes = _client.EndReceive(result, endPoint)
            ParseBytes(bytes)
        Catch ex As Exception
            Throw
        Finally
            If Listening Then
                _client.BeginReceive(AddressOf Me.GetDataAsync, Nothing)
            End If
        End Try
    End Sub


byteit101 24-02-2009 21:40

Re: recieve data from cRIO
 
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)

keehun 25-02-2009 19:25

Re: recieve data from cRIO
 
Quote:

Originally Posted by EHaskins (Post 826153)
Here is the applicable code from my dashboard. It uses async calls so its a little more complicated.

You are awesome.. that's Visual Basic?

byteit101 25-02-2009 20:13

Re: recieve data from cRIO
 
Quote:

Originally Posted by keehun (Post 827982)
You are awesome.. that's Visual Basic?

Unfourtunatly, yes(I am a C# person). But fortunatly, I know Visual Basic

EHaskins 25-02-2009 21:52

Re: recieve data from cRIO
 
Quote:

Originally Posted by byteit101 (Post 827557)
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


byteit101 02-03-2009 20:54

Re: recieve data from cRIO
 
Thanks, but i figured it out:
(in C#.net just to irritate you VB bigot)
Code:

buffer= client.Receive...
string endresult = "";
foreach (byte databit in buffer)
{
    endresult+=((buffer==0)?"":((char)databit).ToString());//I love () to make sure thigs execute as i want (as well as ; semicolins;)
}
textBox1.Text+="\n"+endresult;

the problem is it was sending something like this:
?hs\0546d\0jos\0MYDATAHERE\0jsfjnn\0
and it cut off after the \0 (or null (buffer = 0) (Nothing for you VB bigot))
i just had to set a breakpoint, see the data, and realize what was happening (the string was being chopped up!);

virtuald 06-03-2009 23:59

Re: recieve data from cRIO
 
Something very useful for feedback is the ability to write to the LCD of your DriverStation: http://thinktank.wpi.edu/article/144

byteit101 07-03-2009 07:48

Re: recieve data from cRIO
 
Quote:

Originally Posted by virtuald (Post 832687)
Something very useful for feedback is the ability to write to the LCD of your DriverStation: http://thinktank.wpi.edu/article/144

but can you provide moving green and pink targets on the screen of it, while at the same time using a "taco-meter" (a meter looking like a taco, don't ask) to display the speed of another thing, a distance to target bar, and a timer for teleop and auto on the LCD? (we think not. plus, we have our dashboard working)

virtuald 07-03-2009 16:37

Re: recieve data from cRIO
 
All that is great, as long as you have a laptop around. :)


All times are GMT -5. The time now is 01:13.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi