Пример #1
0
        public NMEASerialPort(SerialPortSettings portSettings)
            : base()
        {
            #region serialPort initialization

            if (portSettings == null)
            {
                throw new ArgumentNullException("portSettings");
            }

            PortSettings = portSettings;

            serialPort = new SerialPort(
                PortSettings.PortName,
                (int)PortSettings.PortBaudRate,
                PortSettings.PortParity,
                (int)PortSettings.PortDataBits,
                PortSettings.PortStopBits);

            serialPort.Handshake    = portSettings.PortHandshake;
            serialPort.Encoding     = Encoding.ASCII;
            serialPort.WriteTimeout = 1000;
            serialPort.ReadTimeout  = 1000;

            serialPort.ReceivedBytesThreshold = 1;

            serialErrorReceivedHandler = new SerialErrorReceivedEventHandler(serialPort_ErrorReceived);
            serialDataReceivedHandler  = new SerialDataReceivedEventHandler(serialPort_DataReceived);

            #endregion
        }
Пример #2
0
        public USplitterDriver(SerialPortSettings portSettings)
        {
            for (int i = 0; i < CM_CH_NUMBER; i++)
            {
                C_CH_RX_RING[i] = new byte[CM_CH_TX_BUFFER_SIZE];
                C_CH_TX_RING[i] = new byte[CM_CH_TX_BUFFER_SIZE];
            }

            port = new SerialPort(portSettings.PortName, (int)portSettings.PortBaudRate, portSettings.PortParity, (int)portSettings.PortDataBits, portSettings.PortStopBits);
            port.DataReceived  += new SerialDataReceivedEventHandler(port_DataReceived);
            port.ErrorReceived += new SerialErrorReceivedEventHandler(port_ErrorReceived);
            port.ReadTimeout    = 1000;
        }