예제 #1
0
 public void DecodeInternal()
 {
     while (RunDecodeThread)
     {
         if (Decode)
         {
             List <Original> list = RxQueue.PopAll();
             {
                 if (list != null && list.Count > 0)
                 {
                     foreach (var o in list)
                     {
                         OriginalBytes obytes = o as OriginalBytes;
                         if (o != null)
                         {
                             MotorProtocol     mp           = motorProtocol.DePackage(obytes.Data);
                             byte[]            data         = mp.CodeRegion;
                             byte              commandCode  = data[0];
                             byte              additionCode = data[1];
                             MotorBaseResponse mr           = Decoders[commandCode].Decode(obytes);
                             if (mr != null)
                             {
                                 RxMsgQueue.Push(mr);
                                 LogHelper.GetLogger <LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}",
                                                                                                  ByteHelper.Byte2ReadalbeXstring(obytes.Data)));
                             }
                         }
                     }
                 }
             }
         }
         Thread.Sleep(10);
     }
 }
예제 #2
0
 void ComPort_SerialDataReceived(ComPort ReceivingComPort, ComPortSerialDataEventArgs args)
 {
     foreach (byte b in args.SerialData.ToByteArray())
     {
         RxQueue.Enqueue(b);
     }
 }
예제 #3
0
        //private log4net.ILog log = log4net.LogManager.GetLogger("MyLogger");

        public ProcThread()
        {
            UsbTxPrepare();
            txQueue = usb.TxQueue;
            rxQueue = usb.RxQueue;
            latch   = usb.Latch;
        }
예제 #4
0
 private void ComPortOnSerialDataReceived(IComPortDevice device, ComPortSerialDataEventArgs args)
 {
     foreach (var b in args.SerialData.ToByteArray())
     {
         RxQueue.Enqueue(b);
     }
 }
예제 #5
0
 public void DecodeInternal()
 {
     while (RunDecodeThread)
     {
         if (Decode)
         {
             List <Original> list = RxQueue.PopAll();
             if (list != null && list.Count > 0)
             {
                 foreach (var o in list)
                 {
                     OriginalBytes obytes = o as OriginalBytes;
                     if (o != null && obytes.Data.Count() == 6)
                     {
                         LaserBaseResponse responseList = Decoder.Decode(obytes);
                         if (responseList != null)
                         {
                             RxMsgQueue.Push(responseList);
                         }
                         //LogHelper.GetLogger<LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}",
                         //        ByteHelper.Byte2ReadalbeXstring(obytes.Data)));
                     }
                 }
             }
         }
         Thread.Sleep(10);
     }
 }
예제 #6
0
 public void DecodeInternal()
 {
     while (RunDecodeThread)
     {
         if (Decode)
         {
             List <Original> list = RxQueue.PopAll();
             if (list != null && list.Count > 0)
             {
                 foreach (var o in list)
                 {
                     OriginalBytes obytes = o as OriginalBytes;
                     if (o != null)
                     {
                         LaserProtocol lp       = laserProtocol.DePackage(obytes.Data);
                         byte[]        data     = lp.Body;
                         byte          markHead = data[0];
                         byte          type     = GetMsgType();
                         byte[]        appData  = new byte[data.Length - 2];
                         Array.Copy(data, 1, appData, 0, data.Length - 2);
                         LaserBasePackage         bp           = new LaserBasePackage(markHead, type, appData);
                         List <LaserBaseResponse> responseList = Decoder.Decode(bp, obytes);
                         if (responseList != null && responseList.Count > 0)
                         {
                             RxMsgQueue.Push(responseList);
                         }
                         LogHelper.GetLogger <LaserProtocolFactory>().Error(string.Format("接受到的原始数据为: {0}",
                                                                                          ByteHelper.Byte2ReadalbeXstring(obytes.Data)));
                     }
                 }
             }
         }
         Thread.Sleep(10);
     }
 }
예제 #7
0
        object ReceiveBufferProcess(object obj)
        {
            Byte[] bytes     = new Byte[1000];
            int    byteIndex = 0;

            while (true)
            {
                try
                {
                    byte b = RxQueue.Dequeue();

                    if (programStopping)
                    {
                        return(null);
                    }

                    if (b == 10)
                    {
                        // skip line feed
                    }

                    // If find byte = CR
                    else if (b == 13)
                    {
                        // Copy bytes to new array with length of packet and ignoring the CR.
                        Byte[] copiedBytes = new Byte[byteIndex];
                        Array.Copy(bytes, copiedBytes, byteIndex);

                        byteIndex = 0;
#if DEBUG
                        CrestronConsole.Print("Revolabs Rx: ");
                        Tools.PrintBytes(copiedBytes, copiedBytes.Length, true);
#endif
                        if (ReceivedData != null)
                        {
                            ReceivedData(this, Encoding.ASCII.GetString(copiedBytes, 0, copiedBytes.Length));
                        }
                        CrestronEnvironment.AllowOtherAppsToRun();
                    }
                    else
                    {
                        bytes[byteIndex] = b;
                        byteIndex++;
                    }
                }
                catch (Exception e)
                {
                    if (e.Message != "ThreadAbortException")
                    {
#if DEBUG
                        CrestronConsole.Print("Error in Revolabs Rx: ");
                        Tools.PrintBytes(bytes, byteIndex);
#endif
                        ErrorLog.Exception(string.Format("{0} - Exception in rx thread", GetType().Name), e);
                    }
                }
            }
        }
예제 #8
0
        void ComPort_SerialDataReceived(ComPort ReceivingComPort, ComPortSerialDataEventArgs args)
        {
            foreach (byte b in args.SerialData.ToByteArray())
            {
                RxQueue.Enqueue(b);
            }

            if (!RxHandlerThreadRunning)
            {
                CreateRxHandlerThread();
            }
        }
예제 #9
0
        void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
        {
            if (programEventType == eProgramStatusEventType.Stopping)
            {
#if DEBUG
                CrestronConsole.PrintLine("Samsung com port handler - Program Stopping!");
#endif
                programStopping = true;

                if (RxThread != null && RxThread.ThreadState == Thread.eThreadStates.ThreadRunning)
                {
                    if (RxQueue.IsEmpty)
                    {
                        RxQueue.Enqueue(0x00);
                    }
                }
            }
        }
예제 #10
0
        private USB()
        {
            _isUSBAvailable = false;
            _delayms        = 10;
            usbName         = "Bulkloop - no device";

            try
            {
                usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
                usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
                usbDevices.DeviceRemoved  += new EventHandler(usbDevices_DeviceRemoved);

                intDevice();
                txQueue = new TxQueue();
                rxQueue = new RxQueue();
                latch   = new Latch();
            }
            catch
            {
                // the old CyUSB.dll is not compatible with Win10
            }
        }
예제 #11
0
        protected object ReceiveBufferProcess(object obj)
        {
            Byte[] bytes     = new Byte[1000];
            int    byteIndex = 0;

            while (true)
            {
                try
                {
                    byte b = RxQueue.Dequeue();

                    // If find byte = CR
                    if (b == 13)
                    {
                        // Copy bytes to new array with length of packet and ignoring the CR.
                        Byte[] copiedBytes = new Byte[byteIndex];
                        Array.Copy(bytes, copiedBytes, byteIndex);

                        byteIndex = 0;

                        int chk = 0;

                        for (int i = 1; i < (copiedBytes.Length - 1); i++)
                        {
                            chk = chk ^ copiedBytes[i];
                        }

                        if (chk == copiedBytes.Last())
                        {
#if DEBUG
                            //CrestronConsole.Print("NEC Rx: ");
                            //Tools.PrintBytes(copiedBytes, copiedBytes.Length);
#endif
                            if (ReceivedPacket != null)
                            {
                                ReceivedPacket(this, copiedBytes);
                            }
                            CrestronEnvironment.AllowOtherAppsToRun();
                        }
                        else
                        {
#if DEBUG
                            CrestronConsole.PrintLine("NEC Display Rx - Checksum Error");
#endif
                            ErrorLog.Error("NEC Display Rx - Checksum Error");
                        }
                    }
                    else
                    {
                        bytes[byteIndex] = b;
                        byteIndex++;
                    }
                }
                catch (Exception e)
                {
                    if (e.Message != "ThreadAbortException")
                    {
                        ErrorLog.Exception("Error in NEC Rx Thread Handler", e);
                    }
                }
            }
        }
예제 #12
0
        object ReceiveBufferProcess(object obj)
        {
            Byte[] bytes      = new Byte[1000];
            int    byteIndex  = 0;
            int    dataLength = 0;

            while (true)
            {
                try
                {
                    byte b = RxQueue.Dequeue();

                    if (programStopping)
                    {
                        return(null);
                    }

                    if (b == 0xAA)
                    {
                        byteIndex  = 0;
                        dataLength = 0;
                    }
                    else
                    {
                        byteIndex++;
                    }

                    bytes[byteIndex] = b;
                    if (byteIndex == 3)
                    {
                        dataLength = bytes[byteIndex];
                    }

                    if (byteIndex == (dataLength + 4))
                    {
                        int chk = bytes[byteIndex];

                        int test = 0;
                        for (int i = 1; i < byteIndex; i++)
                        {
                            test = test + bytes[i];
                        }

                        if (chk == (byte)test)
                        {
                            byte[] copiedBytes = new byte[byteIndex];
                            Array.Copy(bytes, copiedBytes, byteIndex);
#if DEBUG
                            //CrestronConsole.Print("Samsung Rx: ");
                            //Tools.PrintBytes(copiedBytes, copiedBytes.Length);
#endif
                            if (ReceivedPacket != null)
                            {
                                ReceivedPacket(this, copiedBytes);
                            }

                            Thread.Sleep(10);
                            if (RxQueue.IsEmpty)
                            {
                                return(null);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e.Message != "ThreadAbortException")
                    {
#if DEBUG
                        CrestronConsole.Print("Error in Samsung Rx: ");
                        Tools.PrintBytes(bytes, byteIndex);
#endif
                        ErrorLog.Exception(string.Format("{0} - Exception in rx thread", GetType().Name), e);
                    }
                }

                CrestronEnvironment.AllowOtherAppsToRun();
            }
        }