public void updateAlertToOPCLabel(PacketData data, Dictionary <string, Dictionary <string, uint> > handles) { if (handles.ContainsKey(data.moduleID)) { Dictionary <string, uint> moduleHandle = handles[data.moduleID]; int pos = data.alertPos; int value = data.alertValue; if (moduleHandle.ContainsKey(data.resolvePos(pos))) { deactive(); OPClib.UpdateTag(moduleHandle[data.resolvePos(pos)], data.transformValue(value, pos), 192); } } }
public void registerOPCServer() { string exepath; exepath = System.Windows.Forms.Application.StartupPath + "\\OPCServerProject.exe"; deactive(); OPClib.WriteNotificationDelegate WriteCallback = new OPClib.WriteNotificationDelegate(MyWriteCallback); OPClib.UpdateRegistry("{4FEFF1A0-5B75-4EF3-BC6D-37145069E552}", "My OPC Server", "My OPC Server", exepath); OPClib.SetVendorInfo("OPCServer.Com"); OPClib.InitWTOPCsvr("{4FEFF1A0-5B75-4EF3-BC6D-37145069E552}", 1000); OPClib.EnableWriteNotification(WriteCallback, true); }
private void TimeoutCheckingThreadWork(object obj) { int timeout = (int)obj; while (true) { Thread.Sleep(1000); DateTime now = DateTime.Now; Dictionary <string, DateTime> oneTimeUpdate = new Dictionary <string, DateTime>(); foreach (KeyValuePair <string, DateTime> updatedItem in lastUpdate) { oneTimeUpdate.Add(updatedItem.Key, updatedItem.Value); } foreach (KeyValuePair <string, DateTime> updatedItem in oneTimeUpdate) { DateTime dt = updatedItem.Value; TimeSpan span = now - dt; string moduleID = updatedItem.Key; if ((span.Minutes > timeout) || (span.Minutes == timeout && span.Seconds > 0)) { if (handles.ContainsKey(moduleID)) { Dictionary <string, uint> handle = handles[moduleID]; foreach (KeyValuePair <string, uint> singleLabel in handle) { string labelName = singleLabel.Key; uint labelHandle = singleLabel.Value; if (lastUpdateData.ContainsKey(moduleID) && lastUpdateData[moduleID].packetDataMap.ContainsKey(labelName)) { OPClib.UpdateTag(labelHandle, lastUpdateData[moduleID].packetDataMap[labelName], 0x18); //LogUtil.writeLog(LogUtil.getFileName(), "[" + DateTime.Now.ToString() + "]: 信号差"); } } lastUpdate.Remove(moduleID); lastUpdateData.Remove(moduleID); } } } } }
public void updateToOPCLabel(PacketData data, Dictionary <string, Dictionary <string, uint> > handles) { if (handles.ContainsKey(data.moduleID)) { Dictionary <string, uint> moduleHandle = handles[data.moduleID]; foreach (KeyValuePair <string, uint> handle in moduleHandle) { if (data.packetDataMap.ContainsKey(handle.Key)) { //System.Runtime.InteropServices.FILETIME f = new System.Runtime.InteropServices.FILETIME(); deactive(); if (!handle.Key.StartsWith("DO")) { OPClib.UpdateTag(handle.Value, data.packetDataMap[handle.Key], 192);//, System.Runtime.InteropServices.FILETIME); } // LogUtil.writeLog(LogUtil.getFileName(), "[" + DateTime.Now.ToString() + "]: OPC标签更新"); } } } }
public Dictionary <string, Dictionary <string, uint> > addOPCLabels(LabelStructure label) { Dictionary <string, Dictionary <string, uint> > labelHandles = new Dictionary <string, Dictionary <string, uint> >(); foreach (string equip in label.equipmentNames) { Dictionary <string, LabelItem> items = label.labelItemNamems[equip]; Dictionary <string, uint> handles = new Dictionary <string, uint>(); foreach (KeyValuePair <string, LabelItem> pair in items) { deactive(); uint handle = OPClib.CreateTag(equip + "." + pair.Key, getDefaultValue(pair.Value.labelType), 0, true); handles.Add(pair.Key, handle); } labelHandles.Add(equip, handles); } return(labelHandles); }
private void sendCommandWorkThread() { while (true) { Thread.Sleep(1000); List <string> nowOnline = new List <string>(); nowOnline.AddRange(onlineLabel); foreach (string module in nowOnline) { if (handles.ContainsKey(module)) { Dictionary <string, uint> handle = handles[module]; uint DO1 = handle["DO1"]; uint DO2 = handle["DO2"]; uint DO3 = handle["DO3"]; uint DO4 = handle["DO4"]; uint DO5 = handle["DO5"]; uint DO6 = handle["DO6"]; object value1 = null; object value2 = null; object value3 = null; object value4 = null; object value5 = null; object value6 = null; try { OPClib.ReadTag(DO1, ref value1); OPClib.ReadTag(DO2, ref value2); OPClib.ReadTag(DO3, ref value3); OPClib.ReadTag(DO4, ref value4); OPClib.ReadTag(DO5, ref value5); OPClib.ReadTag(DO6, ref value6); } catch (Exception ex) { continue; } Dictionary <string, object> values = new Dictionary <string, object>(); values.Add("DO1", value1); values.Add("DO2", value2); values.Add("DO3", value3); values.Add("DO4", value4); values.Add("DO5", value5); values.Add("DO6", value6); if (!currentOutputValue.ContainsKey(module)) { currentOutputValue.Add(module, values); } else { Dictionary <string, object> savedValue = currentOutputValue[module]; if (!compareOutputValues(savedValue, values)) { try { listener.Send(constructDataPacket(values, module)); currentOutputValue[module] = values; } catch (Exception ex) { continue; } } } } } } }
public void deactive() { OPClib.Deactivate30MinTimer("JVRPS53R5V64226N62H4"); }
public void unRegisterOPCServer() { deactive(); OPClib.UnregisterServer("{4FEFF1A0-5B75-4EF3-BC6D-37145069E552}", "My OPC Server"); }