예제 #1
0
        public override object CreateDefault()
        {
            var res = new ComPortSettings
            {
                PortName        = "COM1",
                BaudRate        = 38400,
                DataBits        = 8,
                Parity          = Parity.None,
                StopBits        = StopBits.One,
                Handshake       = Handshake.None,
                ReadBufferSize  = 1024 * 1024,
                WriteBufferSize = 1024 * 1024
            };

            return(res);
        }
예제 #2
0
        protected ComPort(ComPortSettings settings, Action <ComPortErrorNames, Exception> errorCallback)
        {
            try
            {
                if (settings == null)
                {
                    throw new ArgumentNullException(nameof(settings));
                }

                if (settings.Validate() == false)
                {
                    throw new ArgumentException(Tran.Instance.Get("InvalidSettings"), nameof(settings));
                }

                Error = errorCallback ?? throw new ArgumentNullException(nameof(errorCallback));

                port = new SerialPort
                {
                    PortName        = settings.PortName,
                    BaudRate        = settings.BaudRate,
                    DataBits        = settings.DataBits,
                    Parity          = settings.Parity,
                    StopBits        = settings.StopBits,
                    Handshake       = settings.Handshake,
                    ReadBufferSize  = settings.ReadBufferSize,
                    WriteBufferSize = settings.WriteBufferSize
                };
            }
            catch (Exception ex)
            {
                raiseError(ComPortErrorNames.OnConstruction, ex);
            }

            try
            {
                mainTask = new DelayedTask(main, 1);
                mainTask.Start();
            }
            catch (Exception ex)
            {
                raiseError(ComPortErrorNames.OnStartingReadOperation, ex);
            }
        }
예제 #3
0
 public ComPort(ComPortSettings settings, Action <byte> newByteCallback,
                Action <ComPortErrorNames, Exception> errorCallback)
     : this(settings, errorCallback)
 {
     NewByteCallback = newByteCallback ?? throw new ArgumentNullException(nameof(newByteCallback));
 }