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); }
public static DriverSettings CreateDefaultSettings() { var settings = new DriverSettings(); settings.RestoreDefaults(); settings.Path = string.Empty; return(settings); }
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(); }
public E3JManipulator(DriverSettings settings) { Port = new SerialCOM(settings); Port.DataReceived += Port_DataReceived; }
public SerialBuilder() { settings = DriverSettings.CreateDefaultSettings(); }