Go to Post STEM: Science, Trial, Error, Math. - hrench [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 19-11-2013, 09:34
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
TCP problems in C#

I've got a small LV TCP server 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 something this for the first four iterations (each line is what is read at 20ms):


Quote:
"a b c"
" ca b"
"b ca "
"ca b "


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


Here's the C# code:

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();
            }
        }
Does anyone know how to fix this or what I'm doing wrong? I need a quick read time to get accurate data..
__________________
Per Audacia Ad Astra
 


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 22:39.

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