public PLClock plcClass(string plcName, ref string errText) { lock (plcLock) { try { errText = string.Empty; PLClock plcRead; if (plcCollection.Keys.Count(r => r == plcName) > 0) { plcRead = plcCollection[plcName]; return(plcRead); } plcRead = new PLClock(); plcRead.ConnectRemoteServer(); plcRead.PLCGroupAdd(); foreach (KeyValuePair <string, List <string> > item in typeClass) { string xmlName = item.Key; if (xmlName == plcName) { OpcRcw.Da.OPCITEMDEF[] Item = new OPCITEMDEF[item.Value.Count]; for (int i = 0; i < item.Value.Count; i++) { Item[i].szAccessPath = ""; Item[i].szItemID = item.Value[i].ToString(); Item[i].bActive = 1; //是否激活 Item[i].hClient = i + 1; //表示ID Item[i].dwBlobSize = 0; Item[i].pBlob = IntPtr.Zero; Item[i].vtRequestedDataType = 8; plcRead.PLCItemAdd(Item); } break; } } plcCollection.Add(plcName, plcRead); return(plcRead); } catch (Exception ex) { errText = ex.Message.ToString(); return(null); } } }