public static void AddUi(int ccd)
        {
            VirtualIo   vIo = VirtualIo.GetDevice(ccd);
            VirtualIoUi io  = new VirtualIoUi(vIo);

            var tabs = UiMainForm.MyTabs;

            var tp = tabs["Serial", ccd];

            io.Associate(tp);

            vIo.StartWatch();
        }
        public static VirtualIo GetDevice(int channel)
        {
            VirtualIo io = null;

            foreach (var device in Devices)
            {
                if (device.Channel == channel)
                {
                    io = device;
                    break;
                }
            }

            return(io);
        }
        public static VirtualIo GetDevice(string portName)
        {
            VirtualIo io = null;

            foreach (var device in Devices)
            {
                var sy = device.Device;
                if (sy != null)
                {
                    if (sy.PortName == portName)
                    {
                        io = device;
                        break;
                    }
                }
            }

            return(io);
        }
Exemple #4
0
        public VirtualIoUi(VirtualIo vIo)
        {
            Io      = vIo;
            Channel = vIo.Channel;
            CcdId   = vIo.Id;

            Io.DiChanged     += (s, e) => Di = Io.Di;
            Io.DoChanged     += (s, e) => Do = Io.Do;
            DiCount           = Sy.DiPortCount;
            DoCount           = Sy.DoPortCount;
            UiPanel           = new Panel();
            UiPanel.Width     = 640;
            UiPanel.Height    = 360;
            gboxMain          = new GroupBox();
            gboxMain.Text     = "串口IO通信模块";
            gboxMain.Location = new Point(20, 20);
            gboxMain.Width    = UiPanel.Width - 40;
            gboxMain.Height   = UiPanel.Height - 40;
            UiPanel.Controls.Add(gboxMain);
            AddMainUI(gboxMain);
            Data                  = new int[2];
            DiBlock               = new ActionBlock <int>(x => UiShowDi(x));
            DoBlock               = new ActionBlock <int>(x => UiShowDo(x));
            Buttons               = new Dictionary <string, Button>();
            Buttons["Connect"]    = btnConnect;
            Buttons["Disconnect"] = btnDisconnect;
            Buttons["On"]         = btnOn;
            Buttons["Off"]        = btnOff;
            Buttons["Refresh"]    = btnRefesh;
            Buttons["Ok"]         = btnOk;
            Buttons["Ng"]         = btnNg;
            Buttons["Done"]       = btnDone;

            foreach (var btn in Buttons.Values)
            {
                btn.Enabled = false;
            }

            Buttons["Connect"].Click     += (s, e) => ConnectDevice();
            Buttons["Disconnect"].Click  += (s, e) => DisconnectDevice();
            Buttons["Connect"].Enabled    = true;
            Buttons["Disconnect"].Enabled = false;

            Buttons["Refresh"].Enabled = true;
            Buttons["Refresh"].Click  += (s, e) => RefreshIo();

            Buttons["On"].Enabled  = true;
            Buttons["Off"].Enabled = true;
            Buttons["On"].Click   += (s, e) => SetOn();
            Buttons["Off"].Click  += (s, e) => SetOff();

            Buttons["Ok"].Enabled   = true;
            Buttons["Ng"].Enabled   = true;
            Buttons["Done"].Enabled = true;

            Buttons["Ok"].Click   += (s, e) => SetOk();
            Buttons["Ng"].Click   += (s, e) => SetNg();
            Buttons["Done"].Click += (s, e) => SetDone();

            ToolTip myTip = new ToolTip();

            myTip.SetToolTip(Buttons["Ok"], Io.DoPorts["Ok"].ToString());
            myTip.SetToolTip(Buttons["Ng"], Io.DoPorts["Ng"].ToString());
            myTip.SetToolTip(Buttons["Done"], Io.DoPorts["Done"].ToString());

            ConnectDevice();
        }