Exemplo n.º 1
0
        static void Main(string[] args)
        {
            bool testVal1, testVal2;
            PLC  plc = new PLC("PLC.txt");

            while (!plc.Connect())
            {
            }
            while (!plc.WriteBit("OUT[4]", true))
            {
            }
            while (!plc.ReadBit("IN[5]", out testVal1))
            {
            }
            while (!plc.ReadBit("IN[6]", out testVal2))
            {
            }

            while (!plc.WriteBit("OUT[3]", true))
            {
            }
            while (!plc.ReadBit("IN[5]", out testVal1))
            {
            }
            while (!plc.ReadBit("IN[6]", out testVal2))
            {
            }

            Console.Write("Closed: " + testVal1.ToString() + "\nOpen: " + testVal2.ToString());
            Console.Read();
        }
        /// <summary>
        /// 更新硬件
        /// </summary>
        public void UpdateHardware()
        {
            if (Scope?.IsConnect != true)
            {
                Scope?.Connect();
            }

            if (Power?.IsConnect != true)
            {
                Power?.Connect();
            }

            if (PLC?.IsConnect != true)
            {
                PLC?.Connect();
            }

            if (PWM?.IsConnect != true)
            {
                PWM?.Connect();
            }

            NotifyOfPropertyChange(() => IsHardwareValid);
            NotifyOfPropertyChange(() => CanMeasure);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PLCController"/> class.
        /// </summary>
        /// <param name="fileName">Name of the config file for the plc simulator.</param>
        public PLCController(string fileName)
        {
            _plc = new PLC(fileName);

            while (!_plc.Connect())
            {
            }
        }
Exemplo n.º 4
0
        public void Init()
        {
            _plc = new PLC("PLC.txt");

            while (!_plc.Connect())
            {
            }
        }
Exemplo n.º 5
0
        internal protected override bool Connect(string OPCServerIP)
        {
            bool success = true;

            success &= PLC.Connect("OPC.SimaticNET", OPCServerIP);
            success &= PLC.AddGroup(GROUP_NAME_CTRL, 1, 0);
            success &= PLC.AddItems(GROUP_NAME_CTRL, ItemCtrl);
            success &= PLC.AddGroup(GROUP_NAME_STATE, 1, 0);
            success &= PLC.AddItems(GROUP_NAME_STATE, ItemStatus);
            PLC.SetState(GROUP_NAME_CTRL, true);
            PLC.SetState(GROUP_NAME_STATE, true);
            ConnectionState = (success) ? (ConnectionState.Open) : (ConnectionState.Closed);
            return(success);
        }
Exemplo n.º 6
0
        private void connectB_Click(object sender, EventArgs e)
        {
            PLC p = SelectedPLC;

            if (p == null)
            {
                return;
            }
            connectStatusL.Text = "Connecting synchronously...";
            Application.DoEvents();
            try
            {
                p.Connect();
                connectStatusL.Text = "Connected synchronously!";
            }
            catch (InvalidCredentialException exc)
            {
                connectStatusL.Text = "Invalid password";
            }
            catch (Exception exc)
            {
                connectStatusL.Text = "Error: " + exc.Message;
            }
        }
Exemplo n.º 7
0
        public void ConnectWrongPassTest()
        {
            PLC target = new PLC(ip, "3012893128"); // TODO: Initialize to an appropriate value

            target.Connect();
        }
Exemplo n.º 8
0
        public void ConnectTest()
        {
            PLC target = new PLC(ip, password); // TODO: Initialize to an appropriate value

            target.Connect();
        }
Exemplo n.º 9
0
 public bool Connect() => PLC.Connect();
Exemplo n.º 10
0
 /// <summary>
 /// 连接设备
 /// </summary>
 public void Connect()
 {
     PLC?.Connect();
     NotifyOfPropertyChange(() => IsConnect);
 }
Exemplo n.º 11
0
 public Control(IPEndPoint ip, string pass)
 {
     m_ip = ip;
     plc  = new PLC(ip, pass);
     plc.Connect();
 }