public static void setSigTable(ref BPLibApi.BP_SigTable sigTable, SignalDataItem sdi) { if (null == sdi) { return; } sigTable.SigId = (UInt16)(sdi.SignalId & 0xFFFF); setValueType(ref sigTable.SigType, sdi.ValueType1); sigTable.EnStatics = sdi.Statistics ? BPLibApi.BP_EN_STATISTICS : BPLibApi.BP_DIS_STATISTICS; sigTable.IsDisplay = sdi.Display ? BPLibApi.BP_NOT_DISPLAY : BPLibApi.BP_DISPLAY; sigTable.Accuracy = (UInt16)(sdi.Accuracy & 0xFFFF); sigTable.EnAlarm = sdi.Alarm ? BPLibApi.BP_EN_ALARM : BPLibApi.BP_DIS_ALARM; setPermission(ref sigTable.Perm, sdi.BcPermission1); setAlarmClass(ref sigTable.AlmClass, sdi.AlarmClass); /* TODO: set hasCustomInfo flag */ // sigTable.HasCustomInfo = sdi.HasCustomInfo ? BPLibApi.BP_SYS_SIGNAL_CUSTOM : BPLibApi.BP_SYS_SIGNAL_NONE_CUSTOM; BPLibApi.SigTypeU sigTypeUTmp = new BPLibApi.SigTypeU(); sigTypeUTmp.t_u32 = 0; setSigTypeU(ref sigTypeUTmp, sdi.ValueType1, sdi.MinValue); sigTable.MinVal = Marshal.AllocHGlobal(Marshal.SizeOf(sigTypeUTmp)); Marshal.StructureToPtr(sigTypeUTmp, sigTable.MinVal, false); sigTypeUTmp.t_u32 = 0; setSigTypeU(ref sigTypeUTmp, sdi.ValueType1, sdi.MaxValue); sigTable.MaxVal = Marshal.AllocHGlobal(Marshal.SizeOf(sigTypeUTmp)); Marshal.StructureToPtr(sigTypeUTmp, sigTable.MaxVal, false); sigTypeUTmp.t_u32 = 0; setSigTypeU(ref sigTypeUTmp, sdi.ValueType1, sdi.DefaultValue); sigTable.DefVal = Marshal.AllocHGlobal(Marshal.SizeOf(sigTypeUTmp)); Marshal.StructureToPtr(sigTypeUTmp, sigTable.DefVal, false); sigTable.DelayBeforeAlm = (char)(sdi.AlarmBefDelay & 0xFF); sigTable.DelayAfterAlm = (char)(sdi.AlarmAftDelay & 0xFF); }
public static void setDefaultValue(ref BPLibApi.BP_SigId2Val sigId2Value, SignalDataItem sdi) { if (null == sdi) { return; } sigId2Value.SigId = (UInt16)(sdi.SignalId); setSigTypeU(ref sigId2Value.SigVal, sdi.ValueType1, sdi.DefaultValue); }
public static Boolean judgeEqual(SignalDataItem signalDataItemVal, ref SignalDataItem signalDataItem, int index) { Boolean ret = false; if (null == signalDataItemVal) { return(ret); } if (null == signalDataItem[index]) { return(ret); } try { object value = signalDataItemVal[index]; if (13 == index && signalDataItem.ValueType1 == BPValueType.ENUM) { Dictionary <UInt16, UInt32> enumMap = (Dictionary <ushort, uint>)value; if (signalDataItem.EnumLangIdTable.Count == enumMap.Count) { ret = true; foreach (UInt16 key in signalDataItem.EnumLangIdTable.Keys) { if (!enumMap.ContainsKey(key)) { ret = false; break; } if (enumMap[key] != signalDataItem.EnumLangIdTable[key]) { ret = false; break; } } } } else { ret = value.Equals(signalDataItem[index]); } } catch (Exception e) { Console.Write(e.Message); ret = false; } return(ret); }
public static UInt32 parseCustomInfoMask(int offset, ref SignalDataItem signalDataItem, string newValue) { UInt32 ret = CUSTOM_INFO_PARSE_ERROR; try { switch (offset) { /* * case 0: * return SignalId; */ case 1: if (SignalDataItem.yesOrNoTable.ContainsKey(newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_INFO_ENABLED); signalDataItem.Enabled = SignalDataItem.yesOrNoTable[newValue]; } break; case 2: ret = (1 << BPLibApi.SYS_SIG_CUSTOM_INFO_MACRO); signalDataItem.Macro = newValue; break; case 3: if (SignalDataItem.yesOrNoTable.ContainsKey(newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_IS_ALARM); signalDataItem.Alarm = SignalDataItem.yesOrNoTable[newValue]; } break; case 4: if (SignalDataItem.valueTypeTable.ContainsKey(newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_INFO_VALUE_TYPE); signalDataItem.ValueType1 = SignalDataItem.valueTypeTable[newValue]; } break; case 5: { int unitId = -1; try { if (string.IsNullOrWhiteSpace(newValue)) { unitId = DEFAULT_UNIT_ID; } else { Match mat = unitIDRegex.Match(newValue); if (null != mat && mat.Groups.Count >= 2) { unitId = Convert.ToInt32(mat.Groups[1].Value); } } } catch (Exception e) { unitId = -1; } if (unitId >= 0) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_UNIT_LANG); signalDataItem.UnitLangId = unitId; } break; } case 6: if (permissionTable.ContainsKey(newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_PERMISSION); signalDataItem.BcPermission1 = permissionTable[newValue]; } break; case 7: if (yesOrNoTable.ContainsKey(newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_IS_DISPLAY); signalDataItem.Display = yesOrNoTable[newValue]; } break; case 8: int accuracy = -1; try { if (string.IsNullOrWhiteSpace(newValue)) { accuracy = DEFAULT_ACCURACY; } else { accuracy = Convert.ToInt32(newValue); } if (accuracy >= 0) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_ACCURACY); signalDataItem.Accuracy = accuracy; } } catch (Exception e) { accuracy = -1; } break; case 9: if (Tools.setSigValue(ref signalDataItem.minValue, signalDataItem.ValueType1, newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_MIN_VAL); } break; case 10: if (Tools.setSigValue(ref signalDataItem.maxValue, signalDataItem.ValueType1, newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_MAX_VAL); } break; case 11: if (Tools.setSigValue(ref signalDataItem.defaultValue, signalDataItem.ValueType1, newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_DEF_VAL); } break; case 12: { int groupId = -1; try { if (string.IsNullOrWhiteSpace(newValue)) { groupId = DEFAULT_GROUP_ID; } else { Match mat = groupIDRegex.Match(newValue); if (null != mat && mat.Groups.Count >= 2) { groupId = Convert.ToInt32(mat.Groups[1].Value); } } } catch (Exception e) { groupId = -1; } if (groupId >= 0) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_GROUP_LANG); signalDataItem.GroupLangId = groupId; } break; } case 13: Dictionary <UInt16, UInt32> enumMap = new Dictionary <ushort, uint>(); if (!string.IsNullOrWhiteSpace(newValue)) { string[] enumIDArray = newValue.Split('/'); if (null != enumIDArray && 0 != enumIDArray.Length) { foreach (string enumIDEntry in enumIDArray) { Match mat = enumIDRegex.Match(enumIDEntry); if (null == mat || mat.Groups.Count < 3) { enumMap = null; break; } UInt16 key = Convert.ToUInt16(mat.Groups[1].Value); UInt32 val = Convert.ToUInt16(mat.Groups[2].Value); if (enumMap.ContainsKey(key)) { enumMap = null; break; } enumMap[key] = val; } } else { enumMap = null; } } if (null != enumMap) { signalDataItem.EnumLangIdTable = enumMap; ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_ENUM_LANG); } break; case 14: if (yesOrNoTable.ContainsKey(newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_EN_STATISTICS); signalDataItem.Statistics = yesOrNoTable[newValue]; } break; case 15: { if (alarmClassTable.ContainsKey(newValue)) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_ALM_CLASS); signalDataItem.AlarmClass = alarmClassTable[newValue]; } break; } case 16: { int dba = -1; try { if (string.IsNullOrWhiteSpace(newValue)) { dba = DEFAULT_DBA;; } else { dba = Convert.ToUInt16(newValue); } } catch (Exception e) { dba = -1; } if (dba >= 0) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_ALM_DLY_BEFORE); signalDataItem.AlarmBefDelay = dba; } break; } case 17: { int daa = -1; try { if (string.IsNullOrWhiteSpace(newValue)) { daa = DEFAULT_DBA;; } else { daa = Convert.ToUInt16(newValue); } } catch (Exception e) { daa = -1; } if (daa >= 0) { ret = (1 << BPLibApi.SYS_SIG_CUSTOM_TYPE_ALM_DLY_AFTER); signalDataItem.AlarmBefDelay = daa; } break; } default: ret = CUSTOM_INFO_PARSE_ERROR; break; } } catch (Exception e) { ret = CUSTOM_INFO_PARSE_ERROR; } return(ret); }