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 setSigTypeU(ref BPLibApi.SigTypeU sigTypeU, SignalDataItem.BPValueType valueType, Object value) { if (null == valueType) { return; } if (null == value) { return; } switch (valueType) { case SignalDataItem.BPValueType.U32: sigTypeU.t_u32 = (UInt32)value; break; case SignalDataItem.BPValueType.U16: sigTypeU.t_u16 = (UInt16)value; break; case SignalDataItem.BPValueType.I32: sigTypeU.t_i32 = (Int32)value; break; case SignalDataItem.BPValueType.I16: sigTypeU.t_i16 = (Int16)value; break; case SignalDataItem.BPValueType.ENUM: sigTypeU.t_enm = (UInt16)value; break; case SignalDataItem.BPValueType.FLOAT: sigTypeU.t_flt = (float)value; break; case SignalDataItem.BPValueType.STRING: /* TODO */ // sigTypeU.t_str = (UInt32)value; break; case SignalDataItem.BPValueType.BOOLEAN: sigTypeU.t_bool = (char)value; break; case SignalDataItem.BPValueType.MEM: break; } }
public static Boolean initBP_SigTable(ref BPLibApi.BP_SigTable sigTable, UInt16 sigId, UInt16 sigType, Boolean enStatistics, Boolean enDisplay, UInt16 accuracy, Boolean enAlarm, UInt16 perm, UInt16 alarmClass, Boolean hasCustomInfo, BPLibApi.SigTypeU min, BPLibApi.SigTypeU max, BPLibApi.SigTypeU def, char dba, char daa) { Boolean ret = false; sigTable.SigId = sigId; if (sigType > BPLibApi.SIG_TYPE_MAX_INDEX) { return(ret); } sigTable.SigType = sigType; sigTable.EnStatics = enStatistics ? (ushort)1 : (ushort)0; sigTable.IsDisplay = enDisplay ? (ushort)1 : (ushort)0; if (accuracy > BPLibApi.MAX_ACCURACY) { accuracy = BPLibApi.MAX_ACCURACY; } sigTable.Accuracy = accuracy; sigTable.EnAlarm = enAlarm ? (ushort)1 : (ushort)0; sigTable.Perm = perm > 0 ? (ushort)1 : (ushort)0; if (alarmClass > BPLibApi.MAX_ALARM_CLASS_INDEX) { alarmClass = BPLibApi.INVALID_ALARM_CLASS; } sigTable.MinVal = Marshal.AllocHGlobal(Marshal.SizeOf(min)); Marshal.StructureToPtr(min, sigTable.MinVal, false); sigTable.MaxVal = Marshal.AllocHGlobal(Marshal.SizeOf(max)); Marshal.StructureToPtr(max, sigTable.MaxVal, false); sigTable.DefVal = Marshal.AllocHGlobal(Marshal.SizeOf(def)); Marshal.StructureToPtr(def, sigTable.DefVal, false); sigTable.DelayBeforeAlm = dba; sigTable.DelayAfterAlm = daa; ret = true; return(ret); }