Exemple #1
0
        private static void SerialPortCountChange(List <string> serialPortNames)
        {
            ViewCallFunction.ViewSerialPortCountChanged(serialPortNames);

            if (SerialPortManager.Device1.SerialPortDevice.IsOpen)
            {
                CurrentPortIsDisconnected(SerialPortManager.Device1.SerialPortDevice, serialPortNames);
            }

            if (SerialPortManager.Device2.SerialPortDevice.IsOpen)
            {
                CurrentPortIsDisconnected(SerialPortManager.Device2.SerialPortDevice, serialPortNames);
            }

            if (ConnectionSerialDevice.AutoConnectioinDevice)
            {
                if (!SerialPortManager.Device1.SerialPortDevice.IsOpen || !SerialPortManager.Device2.SerialPortDevice.IsOpen)
                {
                    ConnectionSerialDevice.Start();
                }
            }
        }
Exemple #2
0
        public Main()
            : base("http://res.app.local/main.html")
        {
            InitializeComponent();
            GetMain = this;

            this.Load += OnLoadForm;

            LoadHandler.OnLoadEnd += (sender, args) =>
            {
                PortMonitor.StartMonitor();
            };

            GlobalObject.AddFunction("ShowDevTools").Execute += (sender, args) =>
            {
                Chromium.ShowDevTools();
            };

            GlobalObject.AddFunction("HostOpenAndCloseSerialDevice").Execute += (sender, args) =>
            {
                try
                {
                    var          callback   = args.Arguments.FirstOrDefault(e => e.IsFunction);
                    string       deviceName = args.Arguments[0].StringValue;
                    SerialPortEx serial     = SelectSerialDevice(deviceName);
                    string       portName   = args.Arguments[1].StringValue;
                    if (!serial.IsOpen)
                    {
                        SerialPortManager.OpenSerialPort(serial, portName);
                    }
                    else
                    {
                        SerialPortManager.CloseSerialPort(serial);
                    }
                    string json = Utility.JsonSerializerBySingleData(serial);
                    callback.ExecuteFunction(null, new Chromium.Remote.CfrV8Value[] { json });
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    ViewCallFunction.ViewAlert(ex.Message);
                }
            };

            GlobalObject.AddFunction("HostAutoConnectionDeviced").Execute += (sender, args) =>
            {
                try
                {
                    bool autoConnection = args.Arguments[0].BoolValue;
                    if (autoConnection)
                    {
                        ConnectionSerialDevice.Start();
                    }
                    else
                    {
                        ConnectionSerialDevice.Stop();
                    }
                    ConnectionSerialDevice.AutoConnectioinDevice = autoConnection;
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    ViewCallFunction.ViewAlert(ex.Message);
                }
            };

            CardManagerEvh.InitEvent();
            PwdManagerEvh.InitEvent();
            ConfigureManagerEvh.InitEvent();
            WirelessManagerEvh.InitEvent();
            UserManagerEvh.InitEvent();
        }