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:
...
...
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.
", GetClock());
dashboard.Printf("451!|distance=2|flywheel=%f|!451
", 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#:
/*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?
Here is the applicable code from my dashboard. It uses async calls so its a little more complicated.
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
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.
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.
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
Thanks, but i figured it out:
(in C#.net just to irritate you VB bigot)
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+="
"+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!);
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)