Exemplo n.º 1
0
        /// <summary>
        /// This event handler is called when data has been received on any of our pipes.
        /// </summary>
        void OnDataReceived(object sender, PipeDataEventArgs arguments)
        {
            if (arguments.PipeNumber != pipeSetup.UartTxPipe)
            {
                AddToLog("Received data on unknown pipe.");
                return;
            }

            StringBuilder stringBuffer = new StringBuilder();

            foreach (byte element in arguments.PipeData)
            {
                stringBuffer.AppendFormat(" 0x{0:X2}", element);
            }

            if (DebugMessagesEnabled)
            {
                AddToLog(string.Format("Data received on pipe number {0}:{1}", arguments.PipeNumber,
                                       stringBuffer.ToString()));
            }

            byte[] utf8Array = arguments.PipeData;
            //string str = System.Text.Encoding.Default.GetString(utf8Array);
            string str = ToHexString(utf8Array);

            AddToLog(str);
            //Show byte here!


            //string convertedText = Encoding.UTF8.GetString(utf8Array);
            //AddToLog(string.Format("RX: {0}", convertedText));
        }
Exemplo n.º 2
0
 public void collectWiimoteData(object sender, PipeDataEventArgs e)
 {
     ConsoleLogger.logMessage("In collectWiimoteData");
     try
     {
         logWiimoteData(e.DataList);
         addMatrixRow(e.DataList);
     }
     catch (CSVFileFormatException ex)
     {
         MessageBox.Show(ex.Message, "CSV File Error", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
Exemplo n.º 3
0
 void OnDataReceived(object sender, PipeDataEventArgs e)
 {
     if (e.PipeNumber == pipeElecData)
     {
         try
         {
             recCnt++;
             //da0.getData(e.PipeData);
             //Console.Write(BitConverter.ToString(e.PipeData) + "\r\n");
             this.Invoke(new Action <byte[]>(da0.getData), new object[] { e.PipeData });
             if (recCnt > 3)
             {
                 recCnt = 0;
                 //Console.Clear();
             }
         }
         catch (Exception ee)
         {
             log.Add(new StringValue(ee.ToString()));
         }
         //Application.DoEvents();
     }
 }
Exemplo n.º 4
0
        void OnDataReceived(object sender, PipeDataEventArgs e)
        {
            StringBuilder stringBuffer = new StringBuilder();
            //short[] dataX = new short[] { e.PipeData[0], e.PipeData[6], e.PipeData[12] };
            //short[] dataY = new short[] { e.PipeData[2], e.PipeData[8], e.PipeData[14] };
            //short[] dataZ = new short[] { e.PipeData[4], e.PipeData[10], e.PipeData[16] };
            Int16[] dataX = new Int16[] { BitConverter.ToInt16(new byte[] { e.PipeData[0], e.PipeData[1] }, 0), BitConverter.ToInt16(new byte[] { e.PipeData[6], e.PipeData[7] }, 0), BitConverter.ToInt16(new byte[] { e.PipeData[12], e.PipeData[13] }, 0) };
            Int16[] dataY = new Int16[] { BitConverter.ToInt16(new byte[] { e.PipeData[2], e.PipeData[3] }, 0), BitConverter.ToInt16(new byte[] { e.PipeData[8], e.PipeData[9] }, 0), BitConverter.ToInt16(new byte[] { e.PipeData[14], e.PipeData[15] }, 0) };
            Int16[] dataZ = new Int16[] { BitConverter.ToInt16(new byte[] { e.PipeData[4], e.PipeData[5] }, 0), BitConverter.ToInt16(new byte[] { e.PipeData[10], e.PipeData[11] }, 0), BitConverter.ToInt16(new byte[] { e.PipeData[16], e.PipeData[17] }, 0) };

            foreach (byte element in e.PipeData)
            {
                stringBuffer.AppendFormat(" 0x{0:X2}", element);
            }

            TimeSpan span = DateTime.Now - begin;
            //int previousTime = items.Count > 0 ? items[items.Count - 1].Time : 0;

            //this.Dispatcher.BeginInvoke((Action)delegate ()
            //{
            //ShowInTextbox(stringBuffer.ToString());
            //RealtimeGraphItem newItem = new RealtimeGraphItem
            //{
            //    Time = (int)(previousTime + span.TotalMilliseconds),
            //    Value = dataX[0]
            //};
            //items.Add(newItem);
                double x = Convert.ToDouble(count++);// span.Milliseconds;
                double y1 = Convert.ToDouble(dataX[0]);
            double y2 = Convert.ToDouble(dataY[0]);
            double y3 = Convert.ToDouble(dataZ[0]);

            double x2 = Convert.ToDouble(count++);
            double y4 = Convert.ToDouble(dataX[1]);
            double y5 = Convert.ToDouble(dataY[1]);
            double y6 = Convert.ToDouble(dataZ[1]);
            double x3 = Convert.ToDouble(count++);
            double y7 = Convert.ToDouble(dataX[2]);
            double y8 = Convert.ToDouble(dataY[2]);
            double y9 = Convert.ToDouble(dataZ[2]);

            Point p1 = new Point(x, y1);
            Point p2 = new Point(x, y2);
            Point p3 = new Point(x, y3);

            Point p4 = new Point(x2, y4);
            Point p5 = new Point(x2, y5);
            Point p6 = new Point(x2, y6);
            Point p7 = new Point(x3, y7);
            Point p8 = new Point(x3, y8);
            Point p9 = new Point(x3, y9);

            source1.AppendAsync(Dispatcher, p1);
            source2.AppendAsync(Dispatcher, p2);
            source3.AppendAsync(Dispatcher, p3);

            source1.AppendAsync(Dispatcher, p4);
            source2.AppendAsync(Dispatcher, p5);
            source3.AppendAsync(Dispatcher, p6);

            source1.AppendAsync(Dispatcher, p7);
            source2.AppendAsync(Dispatcher, p8);
            source3.AppendAsync(Dispatcher, p9);

            //x = Convert.ToDouble(count++);
            //y1 = Convert.ToDouble(dataX[1]);
            //y2 = Convert.ToDouble(dataY[1]);
            //y3 = Convert.ToDouble(dataZ[1]);

            //p1 = new Point(x, y1);
            //p2 = new Point(x, y2);
            //p3 = new Point(x, y3);

            //source1.AppendAsync(Dispatcher, p1);
            //source2.AppendAsync(Dispatcher, p2);
            //source3.AppendAsync(Dispatcher, p3);

            //x = Convert.ToDouble(count++);
            //y1 = Convert.ToDouble(dataX[2]);
            //y2 = Convert.ToDouble(dataY[2]);
            //y3 = Convert.ToDouble(dataZ[2]);

            //p1 = new Point(x, y1);
            //p2 = new Point(x, y2);
            //p3 = new Point(x, y3);

            //source1.AppendAsync(Dispatcher, p1);
            //source2.AppendAsync(Dispatcher, p2);
            //source3.AppendAsync(Dispatcher, p3);

            this.Dispatcher.BeginInvoke((Action)delegate ()
            {
                headerContents.Text = String.Format("Count = {0}", count);
            });
            //Trace.WriteLine(string.Format("Data received on pipe number {0}:{1}", e.PipeNumber, stringBuffer.ToString()));
            last = DateTime.Now;
        }
        public void onDataReceived(object sender, PipeDataEventArgs e)
        {
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                ResponseReceived(this, e.PipeData[0]);
            };
            bw.RunWorkerAsync(e);
        }