Ejemplo n.º 1
0
 public bool InitializeSerialPort(string aPortName, object client)
 {
     if (string.IsNullOrEmpty(aPortName))
     {
         return(false);
     }
     return(base.InitializeSerialPort(aPortName.Equals("AUTO")
         ? SerialPortProvider.GetPortNames(DEVICE_ID_QUERY, addDivider: false, addGenericPorts: false).FirstOrDefault()
         : aPortName, client, newLine: "\r\n", readTimeout: 1500));
 }
Ejemplo n.º 2
0
 public bool InitializeSerialPort(string aPortName, object client)
 {
     if (string.IsNullOrEmpty(aPortName))
     {
         return(false);
     }
     base.InitializeSerialPort(aPortName.Equals("AUTO")
         ? SerialPortProvider.GetPortNames(FLATMASTER_QUERY, addDivider: false, addGenericPorts: false).FirstOrDefault()
         : aPortName, client);
     return(SerialPort != null);
 }
Ejemplo n.º 3
0
        public async Task <bool> InitializeSerialPort(string aPortName, object client, int rtsDelay = 2000)
        {
            if (string.IsNullOrEmpty(aPortName))
            {
                return(false);
            }
            base.InitializeSerialPort(aPortName.Equals("AUTO")
                ? SerialPortProvider.GetPortNames(ALNITAK_QUERY, addDivider: false, addGenericPorts: false).FirstOrDefault()
                : aPortName, client);
            if (SerialPort == null)
            {
                return(false);
            }
            await Task.Delay(rtsDelay); //need to wait {rtsDelay} seconds after port is open before setting RtsEnable or it won't work

            SerialPort.RtsEnable = false;
            return(true);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Application.Init();
            var top = Application.Top;

            // Creates the top-level window to show
            var win = new Window("Fencing Score Board")
            {
                X = 0,
                Y = 1, // Leave one row for the toplevel menu

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            top.Add(win);

            // Creates a menubar, the item "New" has a help menu.
            var menu = new MenuBar(new MenuBarItem[] {
                new MenuBarItem("_File", new MenuItem [] {
                    //new MenuItem ("_New", "Creates new file", NewFile),
                    //new MenuItem ("_Close", "", () => Close ()),
                    new MenuItem("_Quit", "", () => { if (Quit())
                                                      {
                                                          top.Running = false;
                                                      }
                                 })
                }),
                //new MenuBarItem ("_Edit", new MenuItem [] {
                //    new MenuItem ("_Copy", "", null),
                //    new MenuItem ("C_ut", "", null),
                //    new MenuItem ("_Paste", "", null)
                //})
            });

            top.Add(menu);

            var ms        = new MemoryStream();
            var hexViewer = new HexView(ms);

            IParseScoreMachineState parser = new FaveroStateParser();
            var provider = new SerialPortProvider(data =>
            {
                Debug.WriteLine(data);
                ms.Write(data.ToArray(), 0, data.Length);

                return(Task.FromResult(0));
            });

            var deviceTypes     = new ListView(new[] { "SG", "Favero" }.ToList());
            var deviceTypeFrame = new FrameView("Devices")
            {
                Height = Dim.Percent(50),
                Width  = Dim.Percent(25),
            };

            deviceTypeFrame.Add(deviceTypes);

            var ports     = new ListView(provider.ListPorts().ToList());
            var portFrame = new FrameView("Serial Ports")
            {
                Y      = Pos.Percent(50),
                Height = Dim.Percent(100),
                Width  = Dim.Percent(25),
            };

            portFrame.Add(ports);

            //var connect = new Button("Open")
            //{
            //    Y = Pos.Bottom(portFrame),
            //};
            //connect.Clicked = () =>
            //{
            //    var portName = ports.Source is List<string> names ? names[ports.SelectedItem] : null;
            //    Debug.WriteLine(portName);
            //    if (!string.IsNullOrWhiteSpace(portName))
            //        provider.Open(portName);
            //};
            //portFrame.Add(connect);

            var scoreFrame = new FrameView("Scores")
            {
                X      = Pos.Percent(25),
                Height = Dim.Percent(85),
                Width  = Dim.Percent(100),
            };

            var dataFrame = new FrameView("Data")
            {
                X      = Pos.Percent(25),
                Y      = Pos.Percent(85),
                Height = Dim.Percent(100),
                Width  = Dim.Percent(100),
            };


            win.Add(deviceTypeFrame);
            win.Add(portFrame);
            win.Add(scoreFrame);
            win.Add(dataFrame);


            //var ports =  provider.ListPorts();
            // foreach(var port in ports)
            // {
            //     Console.WriteLine(port);
            // }

            Application.Run();
        }