Пример #1
0
        public static DriverSettings CreateFromSettingFile(string filePath = DEFAULT_SERIAL_SETTINGS_PATH)
        {
            var settings = new DriverSettings();

            try
            {
                var     json         = File.ReadAllText(filePath);
                dynamic deserialized = JsonConvert.DeserializeObject(json);
                settings.BaudRate     = deserialized.BaudRate;
                settings.DataBits     = deserialized.DataBits;
                settings.Parity       = deserialized.Parity;
                settings.RtsEnable    = deserialized.RtsEnable;
                settings.ReadTimeout  = deserialized.ReadTimeout;
                settings.WriteTimeout = deserialized.WriteTimeout;
                settings.Path         = filePath;
            }
            catch (FileNotFoundException)
            {
                Console.Error.WriteLine("Specified file does not exist. Restoring defaults.");
                settings.RestoreDefaults();
            }
            catch
            {
                Console.Error.WriteLine("Could not load settings from specified file. File may be corrupted. Restoring defaults.");
                settings.RestoreDefaults();
            }
            return(settings);
        }
Пример #2
0
        public static DriverSettings CreateDefaultSettings()
        {
            var settings = new DriverSettings();

            settings.RestoreDefaults();
            settings.Path = string.Empty;
            return(settings);
        }
Пример #3
0
        public SerialCOM(DriverSettings settings)
        {
            port              = new SerialPort();
            bufferedMessages  = new Queue <string>();
            BaudRate          = settings.BaudRate;
            DataBits          = settings.DataBits;
            Parity            = settings.Parity;
            StopBits          = settings.StopBits;
            RtsEnable         = settings.RtsEnable;
            port.WriteTimeout = settings.WriteTimeout;
            port.ReadTimeout  = settings.ReadTimeout;

            FrameTerminator    = DEFAULT_FRAME_TERMINATOR;
            port.DataReceived += Port_DataReceived;

            heartBeatThread = new Thread(HeartBeat)
            {
                IsBackground = true
            };
            heartBeatThread.Start();
        }
Пример #4
0
 public E3JManipulator(DriverSettings settings)
 {
     Port = new SerialCOM(settings);
     Port.DataReceived += Port_DataReceived;
 }
Пример #5
0
 public SerialBuilder()
 {
     settings = DriverSettings.CreateDefaultSettings();
 }