Exemplo n.º 1
0
		/// <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; 
		}
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
 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();
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        /// <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;
        }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
        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();
        }
Exemplo n.º 11
0
 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();
 }
Exemplo n.º 12
0
 public void UpdatePortSettings(DetailedPortSettings mySettings)
 {
     this.portSettings = mySettings;
 }
Exemplo n.º 13
0
 public void UpdatePortSettings(DetailedPortSettings mySettings)
 {
     this.portSettings = mySettings;
 }