public void SerialConnection_OpenAndClose()
        {
            var connection = new SerialConnection();

            connection.Open();
            connection.Close();
            connection.Open();
            connection.Close();
        }
Beispiel #2
0
        /// <summary>
        /// Autodetect monochromator controller in connected devices
        /// </summary>
        /// <returns>Controller's device name</returns>
        /// <exception cref="ControllerDetectionException"></exception>
        public string Autodetect()
        {
            // Get connected controllers
            var controllers = Controllers();

            foreach (var controller in controllers)
            {
                try {
                    // Open connection
                    using var conn = new SerialConnection(controller, 1000);
                    conn.Open();

                    // Check connection
                    if (IsMonochromator(conn))
                    {
                        Logger.Info($"Autodection has chosen: {controller}");
                        return(controller);
                    }
                } catch (Exception e) {
                    Logger.Error(e);
                }
            }

            throw new ControllerDetectionException(controllers);
        }
Beispiel #3
0
 public void OpenSerialConnection(string portName, int baudRate, int dataBits, StopBits stopBits, Parity parity)
 {
     spManager              = new SerialConnection(portName, baudRate, dataBits, stopBits, parity);
     spManager.OnTelemetry += SerialPort_OnTelemetry;
     spManager.OnError     += SerialPort_OnError;
     spManager.Open();
 }
Beispiel #4
0
        public void CheckOpenConnectionBadPortName()
        {
            _serialParameters.PortName = "JUNK";
            SerialConnection sc = new SerialConnection(_serialParameters);

            sc.Open();
        }
    // Connect to the serial port
    private void btn_Connect_Click(object sender, EventArgs e)
    {
        if (port == null)
        {
            // Port is closed

            int baudrate = -1;
            try {
                baudrate = int.Parse(cmb_baudRate.Text);
            } catch { }

            if (baudrate < 0)
            {
                btn_Connect.BackColor = colorClosed;
                Program.errors.Add("Faulty baud rate.");
            }
            else
            {
                btn_Connect.BackColor = colorOpen;
                port = new SerialConnection(cmb_port.Text, baudrate, this);
                port.Open();
                timerbuffer.Start();
            }
        }
        else
        {
            // Port is open
            btn_Connect.BackColor = colorClosed;
            if (port.IsOpen())
            {
                port.Close();
            }
            timerbuffer.Stop();
        }
    }
        public void EnhancedSerialConnection_OpenAndDoubleClose()
        {
            var connection = new SerialConnection();

            connection.Open();
            connection.Close();
            connection.Close();
        }
Beispiel #7
0
        public void SerialPortReadVoltage()
        {
            event_1.Reset();
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Trace.WriteLine($"SerialPortReadVoltage");
            var serial = new SerialConnection();

            serial.Open(_port, 9600, Parity.None, StopBits.One, 8, Handshake.None, NewLine.SlashN, ReadMode.ReadChunksTillNoneMore);
            serial.SendCommand("VOUT1?");
            event_1.WaitOne(timeout: TimeSpan.FromSeconds(3));
            serial.ClosePort();
        }
        public void SerialConnection_OpenAndClose()
        {
            if (!AreSerialPortsAvailable())
            {
                return;
            }

            var connection = new SerialConnection();

            connection.Open();
            connection.Close();
        }
Beispiel #9
0
        public void SerialPortTestCommand()
        {
            event_1.Reset();

            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Trace.WriteLine($"SerialPortTestCommand");
            var serial = new SerialConnection();

            serial.Open(_port, 9600, Parity.None, StopBits.One, 8, Handshake.None, NewLine.SlashN, ReadMode.ReadLine);
            serial.PortDataRead += serial_dataReceived;
            serial.SendCommand("*IDN?");
            event_1.WaitOne(timeout: TimeSpan.FromSeconds(3));
            serial.ClosePort();
        }
Beispiel #10
0
        public ConfigurationViewModel(BinarySet binarySet, string comPort)
        {
            Connection    = SerialConnection.Open(comPort, binarySet.BaudRate);
            GetStatus     = Command.Create(async() => StatusValue = await Connection.Prompt("?", true));
            Verifications = binarySet.Verifications.Select(v => new VerificationViewModel(v, Connection)).ToList();
            Parameters    = binarySet.ConfigTemplate?.Parameters.Select(p => new ParameterViewModel(p)).ToList() as IReadOnlyCollection <ParameterViewModel>
                            ?? Array.Empty <ParameterViewModel>();
            CommitConfig = Command.Create(
                () => Connection.Prompt($"{binarySet.ConfigTemplate!.SerialCommand} {binarySet.ConfigTemplate!.Build(GetValue)}"),
                () => (binarySet.ConfigTemplate?.SerialCommand) != null && Parameters.All(p => !p.IsRequired || p.Value != null));

            foreach (var parameter in Parameters)
            {
                parameter.PropertyChanged += (sender, args) => CommitConfig.RaiseCanExecuteChanged();
            }
        }
Beispiel #11
0
        /// <summary>
        /// Try to connect to the given device
        /// </summary>
        /// <param name="request">Connection request</param>
        /// <returns>Connection</returns>
        public SerialConnection Connect(ChromelyRequest request)
        {
            // Check parameters
            if (!request.Parameters.ContainsKey("device"))
            {
                throw new ArgumentException("device isn't specified");
            }

            // Open connection
            var device = request.Parameters["device"];
            var conn   = new SerialConnection(device);

            conn.Open();

            // Check connection
            if (!IsMonochromator(conn))
            {
                throw new Exception($"{device} isn't a monochromator controller");
            }

            return(conn);
        }
		public void CheckOpenConnectionBadPortName()
		{
			_serialParameters.PortName = "JUNK";
			SerialConnection sc = new SerialConnection(_serialParameters);
			sc.Open();
		}
Beispiel #13
0
        private static void Main(string[] args)
        {
            var consoleListener = new TextWriterTraceListener(Console.Out);
            Trace.Listeners.Add(consoleListener);

            var portName = args.Length > 1 ? args[1] : GetPortName();

            using(var conn = new SerialConnection(portName))
            {
                conn.Open();

                //conn.WritePriorityMessage("Hello World!");
                conn.SetDateTime(DateTime.Now);
                //conn.Send(Clear());
                //Thread.Sleep(10000);

                //conn.Send(DemoPicture());
                //DemoWriteTextCommands(conn);
            }

            Console.ReadLine();
        }
Beispiel #14
0
 public void CheckOpenConnection()
 {
     _serialConnection.Open();
     Assert.IsTrue(_serialConnection.IsOpen);
 }