Ejemplo n.º 1
0
        void Usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            if (canrefresh)
            {
                if (!Application.Current.Dispatcher.CheckAccess())
                {
                    Application.Current.Dispatcher.Invoke(() => Usb_OnDataRecieved(sender, args));
                    return;
                }
                else
                {
                    canrefresh = false;
                    refreshtimer.Start();

                    //ReportInput.Clear();
                    for (UInt16 i = 0; i < args.data.Length; i++)
                    {
                        if (ReportInput[i].Data != args.data[i])
                        {
                            ReportInput[i].Color = Brushes.Red;
                        }
                        else
                        {
                            ReportInput[i].Color = Brushes.Black;
                        }

                        ReportInput[i].Data = args.data[i];
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void UsbPort_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            if (DataChange(args))
            {
                int    currentPosition = 0;
                string str_rec         = "";
                foreach (byte byteData in args.data)
                {
                    this.BufferIn[currentPosition++] = byteData;
                }

                byte[] bufferCopy = new byte[BUFFER_SIZE];
                for (int i = 0; i < BUFFER_SIZE; i++)
                {
                    bufferCopy[i] = this.BufferIn[i];
                }

                str_rec = new string(UTF8Encoding.UTF8.GetChars(bufferCopy)); // Array convert in ASCII UTF8

                // if the cube is ready to receive data
                if (str_rec.Contains(STR_CUBE_READY))
                {
                    this.SendCommand(STR_START_DRAWING);
                    this.Send0x00();

                    this.CanCommunicate = true;
                }

                if (str_rec.Contains(STR_CUBE_NOT_READY))
                {
                    this.CanCommunicate = false;
                }
            }
        }
Ejemplo n.º 3
0
 private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
 {
     byte[] array = new byte[0x40];
     args.data.CopyTo(array, 0);
     if (this.usPrevFlag != array[1])
     {
         int destinationIndex = array[2] * 0x3d;
         Array.Copy(array, 3, this.UsbBuf_R, destinationIndex, 0x3d);
         this.usPrevFlag = array[1];
         if ((this.usPrevFlag & 0x80) == 0)
         {
             if (this.ComBuf_R == null)
             {
                 this.ComBuf_R = new byte[0x400];
             }
             this.ComDataLen  = (this.UsbBuf_R[2] << 8) | this.UsbBuf_R[1];
             this.ComDataLen -= 4;
             this.ComCmd      = this.UsbBuf_R[3];
             Array.Copy(this.UsbBuf_R, 4, this.ComBuf_R, 0, this.ComDataLen);
             if (this.ComCmd == this.AckCmd)
             {
                 this.IsAckCmd = true;
             }
             this.ComComplete();
         }
         this.UsbRCount += 0x40;
     }
 }
Ejemplo n.º 4
0
 void listener_DataRecieved(object sender, DataRecievedEventArgs e)
 {
     if (this.DataRecieved != null)
     {
         this.DataRecieved(sender, e);
     }
 }
Ejemplo n.º 5
0
 private void _client_DataRecieved(object sender, DataRecievedEventArgs e)
 {
     if (TryReadMessage(e.Data, out Message message))
     {
         ShowMessage(_client, message);
     }
 }
 protected virtual void Port_OnDataRecieved(object sender, DataRecievedEventArgs args)
 {
     if (args != null && this.working)
     {
         this.OnInput(args.data);
     }
 }
Ejemplo n.º 7
0
        private void usbPort_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            byte[]    bdata   = new byte[usbPort.SpecifiedDevice.InputReportLength];
            int       pos     = 0;
            W928_data data    = new W928_data();
            string    strData = "";

            //Traitement de données reçues
            foreach (byte byteData in args.data)
            {
                bdata[pos++] = byteData;
                strData     += byteData.ToString("X2");
            }
            strData = strData.Substring(2, strData.Length - 2); //supprime le 00 de début de buffer
            Console.WriteLine(strData);
            buffer += strData;

            int bytes = System.Convert.ToInt16(buffer[0]);

            char[] test  = new char[35];
            char[] test2 = buffer.ToArray <char>();

            if ((count + bytes) < 35)
            {
                char[] tbl2 = new char[test2.Length - 1];
                for (int i = 1; i < test2.Length - 1; i++)
                {
                    tbl2[i] = test2[i];
                }
                Array.Copy(tbl2, test, bytes);
                strData = new string(test);
            }
            count += bytes;
        }
Ejemplo n.º 8
0
        private void usbHidPort1_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke(new DataRecievedEventHandler(usbHidPort1_OnDataRecieved), new object[] { sender, args });
                }
                catch (Exception hata)
                {
                    MessageBox.Show(hata.ToString());
                }
            }
            else
            {
                int    diziUzunlugu = usbHidPort1.SpecifiedDevice.OutputReportLength;
                byte[] alinanVeri   = new byte[diziUzunlugu + 1];
                alinanVeri   = args.data;
                gelenDenetim = alinanVeri[1];
                tam          = alinanVeri[2];
                ondalik      = alinanVeri[3];
                if (denetim_istemci1.Checked)
                {
                    etiket_sicaklik1.Text = tam + "." + ondalik + " °C";
                }
                else if (denetim_istemci2.Checked)
                {
                    etiket_sicaklik2.Text = tam + "." + ondalik + " °C";
                }

                veriAkisi = false;
            }
        }
Ejemplo n.º 9
0
 private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
 {
     if (InvokeRequired)
     {
         try
         {
             Invoke(new DataRecievedEventHandler(usb_OnDataRecieved), new object[] { sender, args });
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     else
     {
         string rec_data     = "Recv:";
         int    is_report_id = 1;
         foreach (byte myData in args.data)
         {
             if (is_report_id > 0)
             {
                 is_report_id = 0;
             }
             else
             {
                 rec_data += myData.ToString("X2") + " ";
             }
         }
         this.lb_read.Items.Insert(0, rec_data);
     }
 }
Ejemplo n.º 10
0
        private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke(new DataRecievedEventHandler(usb_OnDataRecieved), new object[] { sender, args });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                string rec_data = "Data: ";
                foreach (byte myData in args.data)
                {
                    if (myData.ToString().Length == 1)
                    {
                        rec_data += "00";
                    }

                    if (myData.ToString().Length == 2)
                    {
                        rec_data += "0";
                    }

                    rec_data += myData.ToString() + " ";
                }

                this.lb_read.Items.Insert(0, rec_data);
            }
        }
Ejemplo n.º 11
0
 private void _server_DataRecieved(object sender, DataRecievedEventArgs e)
 {
     if (TryReadMessage(e.Data, out Message message))
     {
         ShowMessage(_server, message);
         RelayToClients(message);
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// The parse barcode.
        /// </summary>
        /// <param name="strBarCode">
        /// The str bar code.
        /// </param>
        /// <returns>
        /// The <see cref="PolicyData"/> .
        /// </returns>
        public PolicyData ParseBarcode(string strBarCode)
        {
            var tempBytes = Encoding.GetEncoding(1251).GetBytes(strBarCode);
            var strXml    = DecomposeBarcode(tempBytes);
            var drea      = new DataRecievedEventArgs(strXml);

            return(drea.PolicyData);
        }
Ejemplo n.º 13
0
        void usbPort_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            lastState = thisState;
            thisState = new AcceptorDataFrame(args.data);

            Thread.Sleep(25);
            sendFrame();
        }
 private void DataReceived(object sender, DataRecievedEventArgs args)
 {
     if (args.data[1] == TurretState.ShotComplete)
     {
         //Тут произошел выстрел
         Stop();
         return;
     }
     _state = args.data[1];
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Check if the buffer change
        /// </summary>
        /// <param name="args"></param>
        /// <returns>True -> buffer changed, False -> Buffer unchanged</returns>
        private bool DataChange(DataRecievedEventArgs args)
        {
            bool changed = false;

            int bufferIndex = 0;

            foreach (byte byteData in args.data)
            {
                changed |= byteData != this.BufferIn[bufferIndex++];
            }

            return(changed);
        }
Ejemplo n.º 16
0
        private void UsbOnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            // Gets byte with the info about which buttons/pads/pedals are down
            Debug.Assert(args.data.GetLength(0) == 15, "Length detected != 15");

            HandleDPad(args.data);

            if (HandleButtons(args.data) == false)
            {
                if (args.data[11] != 0)
                {
                    HandleDrumPads(args.data);
                }
            }
        }
Ejemplo n.º 17
0
        private void usbPort_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            byte[]    bdata   = new byte[usbPort.SpecifiedDevice.InputReportLength];
            int       pos     = 0;
            W928_data data    = new W928_data();
            string    strData = "";

            //Traitement de données reçues
            foreach (byte byteData in args.data)
            {
                bdata[pos++] = byteData;
                strData     += byteData.ToString("X2");
            }
            strData = strData.Substring(2, strData.Length - 2); //supprime le 00 de début de buffer
            if (debug > 0)
            {
                Console.WriteLine(strData);
            }
            buffer += strData;//remplie le buffer avec la trame reçue

            char first = buffer[0];
            int  bytes = charToInt(first);

            char[] test2 = strData.ToCharArray();
            char[] test  = buffer.ToArray <char>();

            //Test de traitement des données selon le projet "weewx"
            //Certainement le traitement nécéssaire pour le bon fonctionnement de notre projet
            //Malheureusement incompris
            if ((count + bytes) < 35)
            {
                char[] tbl2 = new char[test2.Length - 1];
                for (int i = 1; i < test2.Length - 1; i++)
                {
                    tbl2[i] = test2[i];
                }

                char[] tbl1 = new char[test.Length - 1];
                for (int i = count; i < test2.Length - count - 1; i++)
                {
                    tbl1[i] = test[i];
                }

                Array.Copy(tbl2, tbl1, bytes);
                strData = new string(test);
            }
            count += bytes;
        }
Ejemplo n.º 18
0
        private static void Usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            foreach (byte myData in args.data)
            {
                if (myData != 0x00) //иногда попадаются нулевые байты - игнорируем, засоряют только
                {
                    char c = Convert.ToChar(myData);
                    rawDataDecoded += c.ToString(); //набиваем буферную строку
                }

                if (myData == 0x0D)                     //если пришёл символ возврата строки
                {
                    UpsData.UpdateData(rawDataDecoded); //значит это конец буферной строки, отправляем её на обработку
                    rawDataDecoded = "";                //и очищаем для приёма новой порции данных
                }
            }
        }
Ejemplo n.º 19
0
        private void EasyUSBHidNetClass1_DeviceUSB_dataReceived(object sender, DataRecievedEventArgs args)
        {
            //  InvokeRequired required compares the thread ID of the
            //  calling thread to the thread ID of the creating thread.
            //  If these threads are different, it returns true.  We can
            //  use this attribute to determine if we can append text
            //  directly to the textbox or if we must launch an a delegate
            //  function instance to write to the textbox.

            if (InvokeRequired)
            {
                //  InvokeRequired returned TRUE meaning that this function
                //  was called from a thread different than the current
                //  thread.  We must launch a deleage function.
                //  Invoke the new delegate sending the same Data to the
                //  delegate that was passed into this function from the
                //  other thread.

                Invoke(new DataRecievedEventHandler(EasyUSBHidNetClass1_DeviceUSB_dataReceived), new object[] { sender, args });
            }
            else
            {
                //  If this function was called from the same thread that
                //  holds the required objects then just add the text.
                ////***********************************
                //Example:
                // args.data contains the value received on the USB.
                // Buffer PC        Buffer Microcontroller
                if (args.data[19] == 37)
                {
                    //lblValorUSB.Text = args.data[20].ToString();
                }

                if (args.data[0] == 0x37)
                {
                    //lblValorUSB.Text = args.data[1].ToString();
                    //aGauge.Value = (Double)args.data[1];
                }
                // args.data[1] <=> writebuff[1]
                // args.data[2] <=> writebuff[2]
                // ...
                // args.data[63] <=> writebuff[63]
                //********
            }
        }
Ejemplo n.º 20
0
        private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke(new DataRecievedEventHandler(usb_OnDataRecieved), new object[] { sender, args });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            if (!paused)
            {
                int captureval1 = (int)((args.data[1] * 256 + args.data[2]) * 0.92f);
                int captureval2 = (int)((args.data[3] * 256 + args.data[4]) * 0.92f);
                smplcnt++;

                if (checkBox2.Checked)
                // filtrage moyenne mobile
                {
                    valbuf1[bufptr] = captureval1;
                    valbuf2[bufptr] = captureval2;
                    bufptr++; if (bufptr > maxbuf)
                    {
                        bufptr = 0;
                    }

                    float filtered1 = 0f;
                    float filtered2 = 0f;
                    for (int i = 0; i < maxbuf; i++)
                    {
                        filtered1 += valbuf1[i]; filtered2 += valbuf2[i];
                    }
                    captureval1 = (int)(filtered1 / maxbuf);
                    captureval2 = (int)(filtered2 / maxbuf);
                }

                display(captureval1, captureval2);
            }
        }
Ejemplo n.º 21
0
        private void spt_DataRecieved(object sender, DataRecievedEventArgs args)
        {
            string value = Utils.ToHexString(args.data);
            string head  = value.Substring(0, 4);
            string key   = "";
            string data  = "";

            switch (head)
            {
            case "68AB":    //read reponse
                key  = value.Substring(0, 12);
                data = value.Substring(12, 64);
                lock (_lock)
                    AllData[key] = data;
                break;

            case "6856":    //write response
                key  = value.Substring(0, 12);
                data = value.Substring(12, 64);
                lock (_lock)
                    AllData[key] = data;

                //key = PDFCmd.ReadResponse + value.Substring(6, 6);
                //data = value.Substring(12, 64);
                //lock (_lock)
                //    AllData[key] = data;
                break;

            case "68C3":    // cmd exec
                key  = value.Substring(0, 10);
                data = value.Substring(10, 68);
                lock (_lock)
                    AllData[key] = data;
                break;

            default:
                key  = value.Substring(0, 4);
                data = value.Substring(4, 72);
                lock (_lock)
                    AllData[key] = data;
                break;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// The reading timer elapsed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ReadingTimerElapsed(object sender, ElapsedEventArgs e)
        {
            lock (this)
            {
                try
                {
                    var readedStr = serialPort.ReadExisting();

                    if (!string.IsNullOrEmpty(readedStr))
                    {
                        buffer += readedStr;
                        Thread.Sleep(ReadToEndTimeout);
                        if (serialPort.BytesToRead == 0)
                        {
                            OnBeep(buffer);
                            var tempBytes = Encoding.GetEncoding(28591).GetBytes(buffer);
                            buffer = string.Empty;
                            var manager = new BarcodeManager();
                            var strXml  = manager.DecomposeBarcode(tempBytes);
                            var drea    = new DataRecievedEventArgs(strXml);
                            OnDataRecieved(drea.PolicyData);
                        }
                    }
                }
                catch (TimeoutException)
                {
                }
                catch (BarcodeConverterException exc)
                {
                    OnErrorOccurred(new ErrorEventArgs(exc));
                }
                catch (BarcodeServiceException exc)
                {
                    OnErrorOccurred(new ErrorEventArgs(exc));
                }
                catch (InvalidOperationException)
                {
                }
                catch (IOException)
                {
                }
            }
        }
Ejemplo n.º 23
0
        private void usbHidPort1_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke(new DataRecievedEventHandler(usbHidPort1_OnDataRecieved), new object[] { sender, args });
                }
                catch { }
            }
            else
            {
                readbuff = args.data;

                if (readbuff[1].ToString() == "115")
                {
                    count++;
                    text_sw1.Text = count.ToString();
                }
                else if (readbuff[1].ToString() == "119")
                {
                    count1++;
                    text_sw2.Text = count1.ToString();
                }
                else if (readbuff[1] == 5)
                {
                    pictureBox1.Image = app2led.Properties.Resources.LED_Sang;
                }
                else if (readbuff[1] == 6)
                {
                    pictureBox1.Image = app2led.Properties.Resources.t;
                }
                else if (readbuff[1] == 7)
                {
                    pictureBox2.Image = app2led.Properties.Resources.LED_Sang;
                }
                else if (readbuff[1] == 8)
                {
                    pictureBox2.Image = app2led.Properties.Resources.t;
                }
            }
        }
Ejemplo n.º 24
0
        private static void client_OnDataRecieved(object sender, DataRecievedEventArgs e)
        {
            Console.WriteLine("Data of size " + e.DataSize + " recieved! Accept? y/n ");
            switch (Console.ReadLine().ToLower())
            {
            case "y":
            case "yes":
                Console.WriteLine("Enter path to save location: ");
                e.Save(Console.ReadLine());
                break;

            case "n":
            case "no":
                break;

            default:
                client_OnDataRecieved(sender, e);
                break;
            }
        }
Ejemplo n.º 25
0
 private void UsbOnDataRecieved(object sender, DataRecievedEventArgs args)
 {
     // Gets byte with the info about which buttons/pads/pedals are down
     if (args.data.GetLength(0) == 28)
     {
         //byte[] test = new byte[28] { 0, 0, 0, 8, 127, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0 };
         HandleDPad(args.data);
         HandleButtons(args.data);
         if (args.data[1] > 0)
         {
             if (args.data[2] != 0)
             {
                 TriggerNotes(args.data[1], args.data[2], args.data[3], args.data, 12);
             }
         }
     }
     else
     {
         Debug.Assert(false, "Length detected != 28");
     }
 }
Ejemplo n.º 26
0
 private void NetworkManager_NotifyDataReceived(object sender, DataRecievedEventArgs e)
 {
     try {
         Int32 nIndex = 0;
         Int32 nCount = this.MeterDataObjList.Count;
         foreach (String strData in e.DataList)
         {
             if (nCount > nIndex)
             {
                 Debug.WriteLine(String.Format("Received Data String : {0}", strData));
                 this.MeterDataObjList[nIndex].MeterValue = Convert.ToDouble(strData);
                 nIndex++;
             }
             else
             {
                 break;
             }
         }
     } catch (Exception ex) {
         Debug.WriteLine(String.Format("DataReceived Failure : {0}", ex.ToString()));
     }
 }
Ejemplo n.º 27
0
        private void usbHidPort_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            int loop;

            if (InvokeRequired)
            {
                try
                {
                    Invoke(new DataRecievedEventHandler(usbHidPort_OnDataRecieved), new object[] { sender, args });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                for (loop = 0; loop < 64; loop++)
                {
                    PortRxBuf[PortBufWrPos] = args.data[loop + 1];
                    PortBufWrPos            = (PortBufWrPos + 1) % PortRxBuf.Length;
                }
            }
        }
Ejemplo n.º 28
0
 private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
 {
     if (InvokeRequired)
     {
         try
         {
             Invoke(new DataRecievedEventHandler(usb_OnDataRecieved), new object[] { sender, args });
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     else
     {
         string recData     = "Data: ";
         bool   allAreZeros = true;
         foreach (byte myData in args.data)
         {
             if (myData != 0)
             {
                 allAreZeros = false;
             }
             var str = string.Format("{0:X} ", myData);
             if (str.Length == 2)
             {
                 str = "0" + str;
             }
             recData += str;
         }
         if (!allAreZeros)
         {
             this.lb_read.Items.Insert(0, recData);
         }
     }
 }
Ejemplo n.º 29
0
 void listener_DataRecieved(object sender, DataRecievedEventArgs e)
 {
     if (this.DataRecieved != null)
     {
         this.DataRecieved(sender, e);
     }
 }
Ejemplo n.º 30
0
 //事件触发方法
 protected virtual void OnDataRecievedEvent(DataRecievedEventArgs e)
 {
     if (DataRecievedEvent != null)
         DataRecievedEvent(this, e);
 }
Ejemplo n.º 31
0
 private void USB_OnDataRecieved(object sender, DataRecievedEventArgs args)
 {
 }
Ejemplo n.º 32
0
 private void USB_OnDataRecieved(object sender, DataRecievedEventArgs args)
 {
     this.CMDHandle(args.data);
 }
Ejemplo n.º 33
0
 //引发事件
 private void RaiseDataRecievedEvent(String msg)
 {
     DataRecievedEventArgs e = new DataRecievedEventArgs(msg);
     OnDataRecievedEvent(e);
 }