//初始化OPC服务器 static void InitServer() { try { _opcServer = new OPCServerClass(); _opcServer.ClientName = "Test"; _opcServer.ServerShutDown += _opcServer_ServerShutDown; _opcServer.Connect("Knight.OPC.Server.Demo", "127.0.0.1"); PrintInfo("ServerName", _opcServer.ServerName); PrintInfo("ServerNode", _opcServer.ServerNode); PrintInfo("MajorVersion", _opcServer.MajorVersion.ToString()); PrintInfo("MinorVersion", _opcServer.MinorVersion.ToString()); PrintInfo("VendorInfo", _opcServer.VendorInfo); PrintInfo("Bandwidth", _opcServer.Bandwidth.ToString()); PrintInfo("BuildNumber", _opcServer.BuildNumber.ToString()); PrintInfo("LocaleID", _opcServer.LocaleID.ToString()); PrintInfo("StartTime", _opcServer.StartTime.ToString()); PrintInfo("CurrentTime", _opcServer.CurrentTime.ToString()); PrintInfo("LastUpdateTime", _opcServer.LastUpdateTime.ToString()); PrintInfo("ServerState", _opcServer.ServerState.ToString()); } catch (Exception ee) { PrintInfo("InitServer Error", ee.Message); } }
public SHHOPCServer(Guid id, IPAddress ip, string opcServerName, string name) { if (id == null || ip == null || string.IsNullOrEmpty(opcServerName) || string.IsNullOrEmpty(name)) { throw new ArgumentException("IP地址或者OPC服务名不能为空"); } Name = name; ID = id; _IPAddress = ip; _OPCServerName = opcServerName; _GroupList = new ObservableCollection <SHHOPCGroup>(); _OPCServer = new OPCServerClass(); _OPCServer.ServerShutDown += OPCServer_ServerShutDown; //初始化组默认属性 OPCGroups groups = _OPCServer.OPCGroups; groups.DefaultGroupIsActive = true; groups.DefaultGroupUpdateRate = 1000; groups.DefaultGroupDeadband = 0; groups.DefaultGroupTimeBias = 0; groups.DefaultGroupLocaleID = 1033; }
private void Form1_Load(object sender, EventArgs e) { OPCServerClass GlobalOPCServer = new OPCServerClass(); Array ServerList = (Array)GlobalOPCServer.GetOPCServers(""); for (int i = 1; i <= ServerList.Length; i++) { comboBox1.Items.Add(ServerList.GetValue(i).ToString()); } }