Пример #1
0
 private void ShutdownSerialPort(object sender, EventArgs e)
 {
     Log.Information("Closing Serial Port...");
     try
     {
         controller.Shutdown();
         Log.Information("Serial Port has been succesfully closed.");
     }
     catch (Exception ex)
     {
         Log.Error($"Error has occured. Serial Port failed to close.\n{ex.Message}");
     }
 }
        public void TestMethod1()
        {
            sp1 = new SerialPort()
            {
                PortName     = "COM1",
                BaudRate     = 9600,
                Parity       = Parity.None,
                DataBits     = 8,
                StopBits     = StopBits.One,
                Handshake    = Handshake.None,
                ReadTimeout  = 5000,
                WriteTimeout = 5000
            };
            sp2 = new SerialPort()
            {
                PortName     = "COM2",
                BaudRate     = 9600,
                Parity       = Parity.None,
                DataBits     = 8,
                StopBits     = StopBits.One,
                Handshake    = Handshake.None,
                ReadTimeout  = 500,
                WriteTimeout = 500
            };
            sp2.Open();
            sp2.DataReceived += OnDataReceived2;

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console(outputTemplate:
                                          "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Level:u4}] {Message:lj}{NewLine}{Exception}")
                         .WriteTo.File("logs\\myapp.txt", rollingInterval: RollingInterval.Day, shared: true)
                         .CreateLogger();
            IHeightSensorController ODValue = new SickODController(sp1);

            ODValue.Startup();
            ODValue.Shutdown();
        }