Go to Post If there's one thing I've learned, it's that the robot is never truly finished. - Joseph Smith [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 31-10-2013, 11:12
Invictus3593's Avatar
Invictus3593 Invictus3593 is offline
time you like wasting is not wasted
FRC #3593 (Team Invictus)
Team Role: Leadership
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Tulsa, OK
Posts: 318
Invictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really nice
Connecting to the robot - C#

Hello,

I've been trying to use NetworkStream in C# to connect to the robot, but I can't find a good resource to help me recieve packets from the robot. I've got the labview code that will run using TCP but I'm needing some help on the client side.

Anyone Know C# well enough to help, or at least point me to the right resource?

Thanks!
__________________
Per Audacia Ad Astra
  #2   Spotlight this post!  
Unread 31-10-2013, 16:33
connor.worley's Avatar
connor.worley connor.worley is offline
Registered User
FRC #0973 (Greybots)
Team Role: Mentor
 
Join Date: Mar 2011
Rookie Year: 2010
Location: Berkeley/San Diego
Posts: 601
connor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond repute
Re: Connecting to the robot - C#

You should just call NetworkStream.Read, but it sounds like you've already made it that far. What exactly isn't working?
__________________
Team 973 (2016-???)
Team 5499 (2015-2016)
Team 254 (2014-2015)

Team 1538 (2011-2014)
2014 Driver (25W 17L 1T)
日本語でOK
  #3   Spotlight this post!  
Unread 01-11-2013, 09:26
Invictus3593's Avatar
Invictus3593 Invictus3593 is offline
time you like wasting is not wasted
FRC #3593 (Team Invictus)
Team Role: Leadership
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Tulsa, OK
Posts: 318
Invictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really nice
Re: Connecting to the robot - C#

It never actually connects to the robot to get any data:/
__________________
Per Audacia Ad Astra
  #4   Spotlight this post!  
Unread 05-11-2013, 17:34
connor.worley's Avatar
connor.worley connor.worley is offline
Registered User
FRC #0973 (Greybots)
Team Role: Mentor
 
Join Date: Mar 2011
Rookie Year: 2010
Location: Berkeley/San Diego
Posts: 601
connor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond repute
Re: Connecting to the robot - C#

Have you looked into the TcpClient class?
__________________
Team 973 (2016-???)
Team 5499 (2015-2016)
Team 254 (2014-2015)

Team 1538 (2011-2014)
2014 Driver (25W 17L 1T)
日本語でOK
  #5   Spotlight this post!  
Unread 05-11-2013, 21:00
Invictus3593's Avatar
Invictus3593 Invictus3593 is offline
time you like wasting is not wasted
FRC #3593 (Team Invictus)
Team Role: Leadership
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Tulsa, OK
Posts: 318
Invictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really nice
Re: Connecting to the robot - C#

I have not, do you have any good resources you can give me on that?
__________________
Per Audacia Ad Astra
  #6   Spotlight this post!  
Unread 05-11-2013, 23:07
connor.worley's Avatar
connor.worley connor.worley is offline
Registered User
FRC #0973 (Greybots)
Team Role: Mentor
 
Join Date: Mar 2011
Rookie Year: 2010
Location: Berkeley/San Diego
Posts: 601
connor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond repute
Re: Connecting to the robot - C#

MSDN is the place to go for C#. There are some examples further down.
__________________
Team 973 (2016-???)
Team 5499 (2015-2016)
Team 254 (2014-2015)

Team 1538 (2011-2014)
2014 Driver (25W 17L 1T)
日本語でOK
  #7   Spotlight this post!  
Unread 05-11-2013, 23:26
Invictus3593's Avatar
Invictus3593 Invictus3593 is offline
time you like wasting is not wasted
FRC #3593 (Team Invictus)
Team Role: Leadership
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Tulsa, OK
Posts: 318
Invictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really nice
Re: Connecting to the robot - C#

I can't believe I didn't think of MSDN before, I guess my version of VS doesn't have in implemented because I got Express 2012:/

Thanks!
__________________
Per Audacia Ad Astra
  #8   Spotlight this post!  
Unread 09-11-2013, 09:21
Invictus3593's Avatar
Invictus3593 Invictus3593 is offline
time you like wasting is not wasted
FRC #3593 (Team Invictus)
Team Role: Leadership
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Tulsa, OK
Posts: 318
Invictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really nice
Post Re: Connecting to the robot - C#

I've got a small labview program writing a string to the stream and then on the client side (written in C#), when I read the stream every 20ms, it comes back jumbled after the first read.

For instance, if I wrote a string "a b c" to the stream, it would read like this for the first four iterations (each line is what is read at 20ms):

Quote:
"a b c"
" ca b"
"b ca "
"ca b "
As you can imagine, this is very annoying if I'm splitting up the string on the client side and using the three numbers for calculations.

Do I need to change the speed at which I'm reading the string or what's causing the inconsistency?
__________________
Per Audacia Ad Astra
  #9   Spotlight this post!  
Unread 10-11-2013, 12:19
Fifthparallel Fifthparallel is offline
Registered User
AKA: Sam Chen
FRC #1410
 
Join Date: Dec 2012
Rookie Year: 2011
Location: Denver, CO
Posts: 65
Fifthparallel is an unknown quantity at this point
Re: Connecting to the robot - C#

Can you post a screenshot of your LV server you have running and copy/paste some of the C# you're using?
__________________
sudo chmod u+x helloworld.sh
gotta start somewhere.
  #10   Spotlight this post!  
Unread 12-11-2013, 22:17
Invictus3593's Avatar
Invictus3593 Invictus3593 is offline
time you like wasting is not wasted
FRC #3593 (Team Invictus)
Team Role: Leadership
 
Join Date: Jan 2013
Rookie Year: 2010
Location: Tulsa, OK
Posts: 318
Invictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really niceInvictus3593 is just really nice
Re: Connecting to the robot - C#

Yep!

Here's the server code, really simple LV server, went off a youtube tutorial



Here's the C# code to read the stream, note that this reads every 20ms.
Code:
 private void timUpdate_Tick(object sender, EventArgs e)
        {
            //update revolutions X and Y and the Gyro Angle every 20ms from the server string value
            //and make sure the connection is solid, otherwise update connection
            Byte[] info = new Byte[Client.ReceiveBufferSize];
            try
            {
                int rData = stream.Read(info, 0, System.Convert.ToInt32(Client.ReceiveBufferSize));
                RobotData = System.Convert.ToString(rData);
            }
            catch (System.IO.IOException)
            {
                lblConnectInd.BackColor = System.Drawing.Color.Red;
                Log("The robot ended the stream.");
                stream.Close();
                Client.Close();
            }

            //split string into X, Y and angle
            strRevX = RobotData.Substring(0, 2);
            strRevY = RobotData.Substring(5, 2);
            strAngle = RobotData.Substring(8, 2);

            //update values recieved in GUI
            lblX.Text = strRevX;
            lblY.Text = strRevY;
            lblAngle.Text = strAngle;

            //convert separated strings into doubles
            Double.TryParse(strRevX, out dblRevolutionsX);
            Double.TryParse(strRevX, out dblRevolutionsY);
            Double.TryParse(strAngle, out dblAngle);


            //make sure we're still connected
            if (Client.Connected == true)
            {
                lblConnectInd.BackColor = System.Drawing.Color.Green;
            }
            else
            {
                lblConnectInd.BackColor = System.Drawing.Color.Red;
                timUpdate.Stop();
            }
        }
Other than the jumbled string, it works great!
__________________
Per Audacia Ad Astra
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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