/// <summary> /// Constructor for SerialPortController that allows data to be read from and /// written to the serial port. /// </summary> /// <param name="isThreaded">Determines if the object uses multiple threads (with no blocking) or a single thread (with possible blocking)</param> /// <param name="isPrintWarnings">Print warnings to Console when buffers overflow is set to true</param> /// <param name="maxBufferSize">The maximum size of the bytes buffer (2048 a good value in practice)</param> public SerialPortController(bool isThreaded, bool isPrintWarnings, int maxBufferSize) { this.isThreaded= isThreaded; this.maxBufferSize = maxBufferSize; bytesBuffer = new byte[maxBufferSize]; //if (SAVE_TIMING) // bytesBufferTiming = new long[maxBufferSize]; // create the port settings portSettings = new HandshakeNone(); // create a default port on COM2 with no handshaking port = new Port("COM1:", portSettings); // these are fairly inefficient settings // for a terminal we want to send/receive all data as it is queued // so 1 byte at a time is the best way to go port.RThreshold = 1; // get an event for every 1 byte received port.InputLen = 1; // calling Input will read 1 byte port.SThreshold = 1; // send 1 byte at a time // define an event handler if using threaded option if (isThreaded) port.DataReceived +=new Port.CommEvent(port_DataReceived); this.isPrintWarnings = isPrintWarnings; }
/// <summary> /// Create a serial port class. /// </summary> /// <param name="PortName">The port to open (i.e. "COM1:")</param> /// <param name="InitialSettings">DetailedPortSettings to apply to the new Port</param> public Port(string PortName, DetailedPortSettings InitialSettings) { this.PortName = PortName; Init(); //override default ettings portSettings = InitialSettings; }
/// <summary> /// Create a serial port class. /// </summary> /// <param name="PortName">The port to open (i.e. "COM1:")</param> /// <param name="InitialSettings">DetailedPortSettings to apply to the new Port</param> /// <param name="RxBufferSize">Receive buffer size, in bytes</param> /// <param name="TxBufferSize">Transmit buffer size, in bytes</param> public Port(string PortName, DetailedPortSettings InitialSettings, int RxBufferSize, int TxBufferSize) { rxBufferSize = RxBufferSize; txBufferSize = TxBufferSize; this.PortName = PortName; Init(); //override default ettings portSettings = InitialSettings; }
private void Init() { if (Environment.OSVersion.Platform != PlatformID.WinCE) { this.m_CommAPI = new WinCommAPI(); } else { this.m_CommAPI = new CECommAPI(); } this.closeEvent = this.m_CommAPI.CreateEvent(true, false, this.closeEventName); this.rxFIFO = new Queue(this.rxBufferSize); this.txBuffer = new byte[this.txBufferSize]; this.portSettings = new DetailedPortSettings(); }
public Port(string PortName, DetailedPortSettings InitialSettings) { this.hPort = (IntPtr) (-1); this.rxBufferSize = 0x400000; this.rthreshold = 1; this.txBufferSize = 0x400000; this.sthreshold = 1; this.rxBufferBusy = new Mutex(); this.dcb = new DCB(); this.threadStarted = new ManualResetEvent(false); this.closeEventName = "CloseEvent"; this.txOverlapped = IntPtr.Zero; this.rxOverlapped = IntPtr.Zero; this.Capabilities = new CommCapabilities(); this.PortName = PortName; this.Init(); this.portSettings = InitialSettings; }
public Port(string PortName, DetailedPortSettings InitialSettings) { this.hPort = (IntPtr)(-1); this.rxBufferSize = 0x400000; this.rthreshold = 1; this.txBufferSize = 0x400000; this.sthreshold = 1; this.rxBufferBusy = new Mutex(); this.dcb = new DCB(); this.threadStarted = new ManualResetEvent(false); this.closeEventName = "CloseEvent"; this.txOverlapped = IntPtr.Zero; this.rxOverlapped = IntPtr.Zero; this.Capabilities = new CommCapabilities(); this.PortName = PortName; this.Init(); this.portSettings = InitialSettings; }
private void Init() { // create the API class based on the target if (System.Environment.OSVersion.Platform != PlatformID.WinCE) { m_CommAPI = new IO.Serial.WinCommAPI(); } else { m_CommAPI = new IO.Serial.CECommAPI(); } // create a system event for synchronizing Closing closeEvent = m_CommAPI.CreateEvent(true, false, closeEventName); rxFIFO = new Queue(rxBufferSize); txBuffer = new byte[txBufferSize]; portSettings = new DetailedPortSettings(); }
private void Init() { // create the API class based on the target if (System.Environment.OSVersion.Platform != PlatformID.WinCE) m_CommAPI=new IO.Serial.WinCommAPI(); else m_CommAPI=new IO.Serial.CECommAPI(); // create a system event for synchronizing Closing closeEvent = m_CommAPI.CreateEvent(true, false, closeEventName); rxFIFO = new Queue(rxBufferSize); txBuffer = new byte[txBufferSize]; portSettings = new DetailedPortSettings(); }
public void UpdatePortSettings(DetailedPortSettings mySettings) { this.portSettings = mySettings; }