Ejemplo n.º 1
0
        public void Open(SerialDevice device, int BaudRate)
        {
            if (IsOpen())
            {
                return;
            }

            _device = new SerialPort(device.Device, BaudRate, Parity.None, 8, StopBits.One)
            {
                Handshake              = Handshake.None,
                ReadTimeout            = 100,
                WriteTimeout           = 100,
                ReceivedBytesThreshold = 0x1,
                ReadBufferSize         = 0x100000
            };
            _device.DataReceived  += _device_DataReceived;
            _device.ErrorReceived += _device_ErrorReceived;

            _device.Open();
        }
Ejemplo n.º 2
0
        public void Open(SerialDevice device, int BaudRate)
        {
            uint baud = (uint)BaudRate;

            _FtdiInfo = (FTDI_DeviceInfo)FTDI_DeviceInfo.EnumerateDevices().First(x => x.DeviceSerialNumber == device.Device);
            if (_FtdiInfo == null)
            {
                return;
            }
            _FtdiDevice = new FTDI_Device(_FtdiInfo);
            _FtdiDevice.SetParameters(DataLength.EightBits, Parity.None, StopBits.OneStopBit);
            _FtdiDevice.SetBaudrate(baud);

            //this is to change the USB buffer before it passes data to applications. on high baudrates it allows for faster response times instead of getting data in dirty blocks
            _FtdiDevice.SetBufferSizes(64, 64);

            //set the timer for the event
            aTimer.Elapsed  += DataToReadTimer;
            aTimer.AutoReset = true;
            aTimer.Enabled   = true;
        }