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); } } } }
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); } } } }
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(); } }