private void bTestStuff_Click(object sender, EventArgs e) { DS_Status_Message theMessage = new DS_Status_Message(); theMessage.SetStatus(mStatus); theMessage.SetTime((UInt32)DateTime.Now.Subtract(mStartTime).TotalMilliseconds); byte[] theData = theMessage.GetData(); }
private void RunThread() { Socket sending_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPAddress send_to_address = IPAddress.Parse(mConfig.mIPAddress); IPEndPoint sending_end_point = new IPEndPoint(send_to_address, mConfig.mRCPort); UdpClient listener = new UdpClient(mConfig.mDSPort); IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, mConfig.mDSPort); listener.Client.ReceiveTimeout = 30; byte theDouble = 0; while (true == mRunThread) { mCurStatusMessage.SetStatus(mStatus); mCurStatusMessage.SetTime((UInt32)DateTime.Now.Subtract(mStartTime).TotalMilliseconds); mCurStatusMessage.RollSequenceNumber(); mController.SetNumber(1); for (int i = 0; i < MAX_BUTTONS; i++) { mController.SetButton(i, ((1 << i) == (mButtons & (1 << i)))?true:false); } mController.SetAnalog(0, (short)(mLeftX / 256)); mController.SetAnalog(1, (short)(mLeftY / 256)); mController.SetAnalog(2, (short)(mRightX / 256)); mController.SetAnalog(3, (short)(mRightY / 256)); theDouble += 1; byte[] theData = mCurStatusMessage.GetData(); sending_socket.SendTo(theData, sending_end_point); // Repeat this as many times you want theData = mController.GetData(); sending_socket.SendTo(theData, sending_end_point); // Repeat this as many times you want Thread.Sleep(2); try { theData = listener.Receive(ref groupEP); // You can repeat this as many times, but you can’t send stuff using this port. PiMessage.Message theMessage = MessageFactory.Build(theData); if (null != theMessage) { switch (theMessage.GetMessageID()) { case (PiMessage.Message.MessageIDs.DS_STATUS): mDSMessage = (DS_Status_Message)theMessage; break; case (PiMessage.Message.MessageIDs.RC_STATUS): mRCMessage = (RC_Status_Message)theMessage; break; } } if (mCurStatusMessage.GetSequence() != mRCMessage.GetSequence()) { mMessage = "Skipped"; } else { mMessage = "OK"; } } catch (Exception e) { mMessage = e.Message; } mCount++; Thread.Sleep(50); } sending_socket.Close(); }