/// <summary> /// ExecuteFromHostTransaction /// </summary> /// <param name="data"></param> /// <returns></returns> public Result ExecuteFromHostTransaction(byte[] data) { Result result = Result.eERR_INITIAL_STATE; if ((CommState == CommunicationState.Ready) && SerialPortSTB.IsOpen) { result = Result.eERR_SUCCESS; try { SerialPortSTB.BaseStream.Flush(); SerialPortSTB.Write(data, 0, data.Length); SerialPortSTB.BaseStream.Flush(); } catch (InvalidOperationException exception) { STBLogger.AddEvent(this, STBLogger.EventLevel.Warning, "Transaction requested with port closed", exception.Message + exception.Source + exception.StackTrace); result = Result.eERR_OTHER_ERROR; } catch (UnauthorizedAccessException exception2) { STBLogger.AddEvent(this, STBLogger.EventLevel.Warning, "The port was closed", exception2.Message + exception2.Source + exception2.StackTrace); result = Result.eERR_NOT_READY; } catch (IOException exception3) { STBLogger.AddEvent(this, STBLogger.EventLevel.Warning, "The port was closed", exception3.Message + exception3.Source + exception3.StackTrace); result = Result.eERR_NOT_READY; } return(result); } return(Result.eERR_NOT_READY); }
private bool SendCommCMD(string send, string receive) { string str = ""; m_serialPort.Write(send); if (receive.Length > 0) { str = m_serialPort.ReadLine() + m_serialPort.NewLine; } else { Thread.Sleep(30); m_serialPort.ReadExisting(); } return(str.IndexOf(receive) != -1); }