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); }
/// <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()) { } }
public void Init() { _plc = new PLC("PLC.txt"); while (!_plc.Connect()) { } }
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); }
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; } }
public void ConnectWrongPassTest() { PLC target = new PLC(ip, "3012893128"); // TODO: Initialize to an appropriate value target.Connect(); }
public void ConnectTest() { PLC target = new PLC(ip, password); // TODO: Initialize to an appropriate value target.Connect(); }
public bool Connect() => PLC.Connect();
/// <summary> /// 连接设备 /// </summary> public void Connect() { PLC?.Connect(); NotifyOfPropertyChange(() => IsConnect); }
public Control(IPEndPoint ip, string pass) { m_ip = ip; plc = new PLC(ip, pass); plc.Connect(); }