Ejemplo n.º 1
0
        static public void AddDumper(string nameSubs)
        {
            if (!nameSubs.Contains("."))
            {
                if (!dumps.ContainsKey(nameSubs))
                {
                    Dumper dump = new Dumper(MainWindow.project, nameSubs, MainWindow.project.subs[nameSubs].main);
                    if (!dump.Status)
                    {
                        throw new ArgumentException("Subsystem " + nameSubs + " not supported!");
                    }
                    dump.Connect();
                    if (!dump.isConnected())
                    {
                        throw new ArgumentException("Subsystem " + nameSubs + " not connected!");
                    }
                    dumps.Add(nameSubs, dump);
                }
                else
                {
                    throw new ArgumentException("Subsystem " + nameSubs + " is used!");
                }
                return;
            }
            if (masters.ContainsKey(nameSubs))
            {
                throw new ArgumentException("Subsystem and modbus" + nameSubs + " is used!");
            }
            string sub    = nameSubs.Substring(0, nameSubs.IndexOf("."));
            string modbus = nameSubs.Substring(nameSubs.IndexOf(".") + 1);

            if (!MainWindow.project.subs.ContainsKey(sub))
            {
                throw new ArgumentException("Subsystem " + sub + " is not loaded!");
            }
            Subsystem Sub = MainWindow.project.subs[sub];

            foreach (ModbusDevice md in Sub.modbuses)
            {
                if (md.isMaster())
                {
                    continue;
                }
                if (md.name.CompareTo(modbus) != 0)
                {
                    continue;
                }
                MasterModbus master = new MasterModbus(Sub, md);
                master.Connect();
                if (!master.IsConnected())
                {
                    throw new ArgumentException("Subsystem " + sub + " modbus " + modbus + " not connected!");
                }
                masters.Add(nameSubs, master);
                return;
            }
            throw new ArgumentException("Subsystem and modbus " + nameSubs + " not founded!");
        }
Ejemplo n.º 2
0
         private void buttonConnect_Click(object sender, EventArgs e)
        {
            if (activeDump == null) return;
            if (buttonConnect.Text.CompareTo("Подключить")>=0)
            {
                if (!activeDump.isConnected()) activeDump.Connect();
                if (activeDump.isConnected()) 
                {
                    viewTable.Redraw(activeSub, activeDump, seeking);
                }
            }
            else
            {
                if (activeDump.isConnected()) activeDump.Close();
            }
            if (activeDump.isConnected())
                buttonConnect.Text="Отключить";
            else buttonConnect.Text = "Подключить";

        }