private static bool TransmitCommand(ObjectClasses.ISerialPortIo serialPort1, byte[] Command, int ArrayLength) { try { serialPort1.DiscardInBuffer(); serialPort1.DiscardOutBuffer(); serialPort1.Write(Command, 0, ArrayLength); } catch (System.IO.IOException e) { DataComms.CreateThreadInstance("Transm. Command - exception Thrown! " + e.Message); return false; } catch (UnauthorizedAccessException e) { DataComms.CreateThreadInstance("Transm. Command - exception Thrown! " + e.Message); return false; } catch (Exception e) { DataComms.CreateThreadInstance("Transm. Command - exception Thrown! " + e.Message); return false; } return true; }
public static bool TryDiscardInputBuffer(ObjectClasses.ISerialPortIo serialPort1) { if (serialPort1.IsOpen == true) { try { serialPort1.DiscardInBuffer(); return true; } catch (System.IO.IOException) { DataComms.CreateThreadInstance("TryDiscardInputBuffer - IOException"); } catch (System.InvalidOperationException) { DataComms.CreateThreadInstance("TryDiscardInputBuffer - InvalidOperation"); } catch (UnauthorizedAccessException) { DataComms.CreateThreadInstance("TryDiscardInputBuffer - UnauthorizedAccessException"); } finally { } return false; } else { return false; } }