Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   sending/Reading the Eathernet port (http://www.chiefdelphi.com/forums/showthread.php?t=75939)

xtreampb 17-03-2009 19:15

sending/Reading the Eathernet port
 
I have our robot done thanks to previous help with creating the class. I hope it works. I wasn't able to test it before we sent it off but we will find out on thrusday morning. What i need to get done now is creating the functions and applications that will pack the data, send the data, unpack the data and read the data. I am sure i can pack the data and send it based on reading the information provided by us first in packing the data. I need help on the other end...unpacking. I don't know how to read the eathernet port. I am going to use VB.net because i know that language. I know I need to use the imports functions before my class declearation, but i dont know what type of imports or how to unpack the data. Help please. we compete this thursday and although not necessary, i would like to have it up and running by then.

Thanks,


~Xtreamp~

EHaskins 17-03-2009 22:27

Re: sending/Reading the Eathernet port
 
You will probably want to use the System.Net.UdpClient class to receive data from the cRio.

Here is the receive code from my code:
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
            Debug.WriteLine(ex.Message)
            Debug.Assert(False)
            Throw
        Finally
            If Listening Then
                _client.BeginReceive(AddressOf Me.GetDataAsync, Nothing)
            End If
        End Try
    End Sub

If you need more info you can ask me, or take a look at my dashboard viewer.

xtreampb 17-03-2009 22:54

Re: sending/Reading the Eathernet port
 
I downloaded the latest project that you uploaded but i wasn't able to get the crc32 or a few other folders/solutions to load. what am i missing.

EHaskins 17-03-2009 22:59

Re: sending/Reading the Eathernet port
 
1 Attachment(s)
Quote:

Originally Posted by xtreampb (Post 837578)
I downloaded the latest project that you uploaded but i wasn't able to get the crc32 or a few other folders/solutions to load. what am i missing.

crc32 is a C# project. If you don't have VS Pro or above it won't load. I've attached the complied DLL. Remove the crc32 project by right-clicking it, selecting Remove. Then in EHaskins.Frc.Dashboard, add a reference to the crc32.dll I attached.

If there is anything else missing let me know.

EDIT: I confirmed I can compile a clean checkout on another machine. If you have issues all of the non-source-included dependencies are in the .\src\libs folder.

EHaskins 17-03-2009 23:22

Re: sending/Reading the Eathernet port
 
Here is some code I just wrote. I haven't tested it, but it should display any printed or error strings which are written to the dashboard from the robot.

I've committed this to the Codeplex repo if you want the project file.

Hopefully you find it useful.

Code:

Imports EHaskins.Frc.Dashboard

Module Module1

    Sub Main()
        Dim dashboard As New DashboardClient(Of DefaultUserDataProcessor)
        dashboard.BeginUpdating()

        Dim lastIndex As Integer
        Dim printedLength As Integer
        Dim errorLength As Integer

        Do
            Dim data = dashboard.UserData
            If data IsNot Nothing AndAlso _
                Not lastIndex = data.PacketNumber Then

                'Write new printed strings
                If data.PrintedStrings.Count > printedLength Then
                    For i = printedLength To data.PrintedStrings.Count() - 1
                        Console.WriteLine(data.PrintedStrings(i))
                    Next
                    printedLength = data.PrintedStrings.Count()
                End If

                'Write new error strings
                If data.ErrorStrings.Count > errorLength Then
                    For i = errorLength To data.ErrorStrings.Count() - 1
                        Dim oldColor = Console.ForegroundColor
                        Console.ForegroundColor = ConsoleColor.Red

                        Console.WriteLine(data.ErrorStrings(i))

                        Console.ForegroundColor = oldColor
                    Next
                    errorLength = data.ErrorStrings.Count()
                End If
            End If

            Threading.Thread.Sleep(10) 'Give the CPU a break. :)
        Loop

    End Sub

End Module



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

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