Ejemplo n.º 1
0
        public CommunicationsBus(string uartPort, int baudRate = 9600)
        {
            this.disposed    = false;
            this.commandFile = null;
            this.protocal    = CommunicationsProtocal.Uart;
            this.uartPort    = uartPort;

            this.serialPort = UartController.FromName(uartPort);

            var uartSetting = new UartSetting()
            {
                BaudRate    = baudRate,
                DataBits    = 8,
                Parity      = UartParity.None,
                StopBits    = UartStopBitCount.One,
                Handshaking = UartHandshake.None //UartHandshake.RequestToSend
            };

            this.serialPort.SetActiveSettings(uartSetting);

            this.serialPort.WriteBufferSize = 16 * 1024;
            this.serialPort.ReadBufferSize  = 16 * 1024;

            this.serialPort.Enable();
        }
Ejemplo n.º 2
0
        public CommunicationsBus(string uartPort, int baudRate = 115200)
        {
            this.disposed    = false;
            this.commandFile = null;
            this.protocal    = CommunicationsProtocal.Uart;

            this.serialPort = UartController.FromName(uartPort);

            this.serialPort.SetActiveSettings(baudRate, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);

            this.serialPort.Enable();

            this.serialPort.DataReceived += this.SerialPort_DataReceived;
        }
Ejemplo n.º 3
0
        public CommunicationsBus(string portName, int BaudRate = 9600)
        {
            //readTask = new Thread(new ThreadStart(ReadLoop));
            this.disposed    = false;
            this.commandFile = null;
            this.protocal    = CommunicationsProtocal.Uart;

            this.serialPort               = new SerialPort();
            this.serialPort.PortName      = portName;
            this.serialPort.BaudRate      = BaudRate;// 115200;
            this.serialPort.Parity        = Parity.None;
            this.serialPort.DataBits      = 8;
            this.serialPort.StopBits      = System.IO.Ports.StopBits.One;
            this.serialPort.Handshake     = Handshake.None;
            this.serialPort.ReadTimeout   = 4000; // some of the mount commands take a while, so waiting for result can take a while
            this.serialPort.DataReceived += SerialPort_DataReceived;
            this.serialPort.Open();
            //this.serialPort.DtrEnable = true;
            Thread.Sleep(250);

            this.serialPort.DiscardInBuffer();
            //readTask.Start();
        }