示例#1
0
            public void sendData(ControlsUpdate updateControls)
            {
                //string to hold data after being serialized is created
                //it is encoded to ascci bytes and put into the byte array
                //the data is then written to the stream and
                //the sending event is invoked
                JavaScriptSerializer serialise = new JavaScriptSerializer();
                string serializedData          = serialise.Serialize(updateControls);

                byte[] data = Encoding.ASCII.GetBytes(serializedData);
                stream.Write(data, 0, data.Length);
                Sending?.Invoke(updateControls);
            }
示例#2
0
 private void setControlUpdates(ControlsUpdate controlUpdate)
 {
     //Will need to be involked if it is required
     //This recalles the function
     if (this.InvokeRequired)
     {
         this.Invoke(new SendingDataHandler(setControlUpdates), new object[] { controlUpdate });
     }
     else
     {
         //updates the throttle and pitch values
         controlUpdate.throttle      = trkThrottle.Value;
         controlUpdate.elevatorPitch = trkPitch.Value * 0.1;
     }
 }
示例#3
0
        public void controlsScrollUpdate()
        {
            //created a network stream object using client's .GetStream function
            //Instance of controls update struct created
            NetworkStream  stream         = client.GetStream();
            ControlsUpdate controlsUpdate = new ControlsUpdate();

            //Sets the structs objects values to the current values from the sliders
            controlsUpdate.throttle      = trkThrottle.Value;
            controlsUpdate.elevatorPitch = trkPitch.Value * 0.1;
            //stream uses the send data fucntion to send data
            //to be sent to the other program
            sender.stream = stream;
            sender.sendData(controlsUpdate);
            //thread sleeps for 300 milliseconds
            Thread.Sleep(0300);
        }