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 TryDiscardOutputBuffer(ObjectClasses.ISerialPortIo serialPort1) { if (serialPort1.IsOpen == true) { try { serialPort1.DiscardOutBuffer(); return true; } catch (System.IO.IOException e) { DataComms.CreateThreadInstance("TryDiscardOutputBuffer - IOException"); } catch (System.InvalidOperationException e) { DataComms.CreateThreadInstance("TryDiscardOutputBuffer - InvalidOperation"); } catch (UnauthorizedAccessException) { DataComms.CreateThreadInstance("TryDiscardOutputBuffer - UnauthorizedAccessException"); } finally { } return false; } else { return false; } }