Merge branch 'master' of http://gitblit.broconcentric.com:8088/r/M071
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// IO定义类型 |
| | | /// IO预定义类型 主要针对输出 |
| | | /// </summary> |
| | | public enum IODefine |
| | | public enum IOPrestatement |
| | | { |
| | | Nothing, |
| | | InputStartLeft, |
| | | InputStartRight, |
| | | InputCurtainLeft, |
| | | InputCurtainRight, |
| | | InputSafeDoor, |
| | | InputEmergency, |
| | | InputReset, |
| | | InputScrew1, |
| | | InputScrew2, |
| | | InputSuckLeft, |
| | | InputSuckRight, |
| | | InputSuckXYZ, |
| | | InputCylinderLeftLimitFront, |
| | | InputCylinderLeftLimitBack, |
| | | InputCylinderRightLimitFront, |
| | | InputCylinderRightLimitBack, |
| | | [Description("自定义")] |
| | | Customized = 0, |
| | | |
| | | [Description("指示灯-黄")] |
| | | Light_Yellow = 1, |
| | | [Description("指示灯-红")] |
| | | Light_Green = 2, |
| | | [Description("指示灯-绿")] |
| | | Light_Red = 3, |
| | | [Description("蜂鸣器")] |
| | | Beep = 4, |
| | | [Description("照明灯")] |
| | | Light = 5, |
| | | |
| | | OutputYellow, |
| | | OutputGreen, |
| | | OutputRed, |
| | | OutputBeep, |
| | | OutputLight, |
| | | OutputMotorPower, |
| | | OutputInitOK, |
| | | OutputZLock, |
| | | OutputLeftCylinder, |
| | | OutputRightCylinder, |
| | | OutputLeftSuck, |
| | | OutputRightSuck, |
| | | OutputScrewBlow, |
| | | OutputCamera, |
| | | OutputScrewSuck, |
| | | [Description("急停")] |
| | | EmergencyStop = 99, |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public enum IOType |
| | | { |
| | | [Description("INPUT")] |
| | | In = 0, |
| | | INPUT = 0, |
| | | [Description("OUTPUT")] |
| | | Out = 1 |
| | | OUTPUT = 1 |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | public class EnumDescriptionConverter<T> : TypeConverter where T : Enum |
| | | { |
| | | Dictionary<T, string> itemDict = new Dictionary<T, string>(); |
| | | public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) |
| | | { |
| | | typeof(T).GetEnumNames().ToList().ForEach(e => |
| | | { |
| | | T temp = (T)Enum.Parse(typeof(T), e); |
| | | itemDict[temp] = temp.GetEnumDescription(); |
| | | }); |
| | | |
| | | return new StandardValuesCollection(itemDict.Keys); |
| | | } |
| | | public override bool GetStandardValuesSupported(ITypeDescriptorContext context) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) |
| | | { |
| | | if (sourceType == typeof(String)) |
| | | return true; |
| | | |
| | | return base.CanConvertFrom(context, sourceType); |
| | | } |
| | | |
| | | public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) |
| | | { |
| | | return base.CanConvertTo(context, destinationType); |
| | | } |
| | | |
| | | public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) |
| | | { |
| | | return base.CreateInstance(context, propertyValues); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="context"></param> |
| | | /// <param name="culture"></param> |
| | | /// <param name="value">string</param> |
| | | /// <returns></returns> |
| | | public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) |
| | | { |
| | | try |
| | | { |
| | | foreach (string e in typeof(T).GetEnumNames().ToList()) |
| | | { |
| | | T temp = (T)Enum.Parse(typeof(T), e); |
| | | |
| | | if (temp.GetEnumDescription() == value.ToString()) |
| | | return temp; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | |
| | | return base.ConvertFrom(context, culture, value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="context"></param> |
| | | /// <param name="culture"></param> |
| | | /// <param name="value">IOItem</param> |
| | | /// <param name="destinationType"></param> |
| | | /// <returns></returns> |
| | | public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) |
| | | { |
| | | if (value is T temp) |
| | | { |
| | | //foreach (KeyValuePair<T, string> pair in itemDict) |
| | | //{ |
| | | // if (Convert.ToInt32(pair.Key) == Convert.ToInt32(temp)) |
| | | // { |
| | | // return pair.Value; |
| | | // } |
| | | //} |
| | | |
| | | return temp.GetEnumDescription(); |
| | | } |
| | | |
| | | return base.ConvertTo(context, culture, value, destinationType); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region UITypeEditor |
| | |
| | | return false; |
| | | } |
| | | |
| | | public string GetDisplayText() |
| | | public virtual string GetDisplayText() |
| | | { |
| | | return $"{IOType.GetEnumDescription()}-{IONum}-{Value}"; |
| | | } |
| | |
| | | public class IODefinition : IOItem |
| | | { |
| | | [Category("IO配置")] |
| | | [Description("IO预定义")] |
| | | [TypeConverter(typeof(EnumDescriptionConverter<IOPrestatement>))] |
| | | public IOPrestatement IOPreStatement { get; set; } = IOPrestatement.Customized; |
| | | |
| | | [Category("IO配置")] |
| | | [Description("IO用途描述")] |
| | | public string IODesc { get; set; } |
| | | |
| | |
| | | [JsonIgnore] |
| | | public override int Value { get; set; } |
| | | |
| | | public new string GetDisplayText() |
| | | public override string GetDisplayText() |
| | | { |
| | | return $"{IODesc} {IOType.GetEnumDescription()} {IONum}"; |
| | | return $"{(IOPreStatement == IOPrestatement.Customized ? IODesc : IOPreStatement.GetEnumDescription())} {IOType.GetEnumDescription()} {IONum}"; |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | IONum = index, |
| | | Value = (inValue & (1 << index)) == 0 ? 1 : 0, |
| | | IOType = IOType.In |
| | | IOType = IOType.INPUT |
| | | }; |
| | | IOItem outItem = new IOItem() |
| | | { |
| | | IONum = index, |
| | | Value = (outValue & (1 << index)) == 0 ? 1 : 0, |
| | | IOType = IOType.Out |
| | | IOType = IOType.OUTPUT |
| | | }; |
| | | result.Add(inItem); |
| | | result.Add(outItem); |
| | |
| | | foreach (var replyIOData in monitorSet.ReplyIODatas) |
| | | { |
| | | //写入IO输出 |
| | | if (replyIOData.IOType == IOType.Out) |
| | | if (replyIOData.IOType == IOType.OUTPUT) |
| | | { |
| | | GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPI, (short)replyIOData.IONum, (short)replyIOData.Value); |
| | | } |
| | |
| | | InitialSetting(); |
| | | |
| | | base.Open(); |
| | | |
| | | CheckMachineState(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检查设备状态 |
| | | /// </summary> |
| | | private void CheckMachineState() |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | |
| | | private void InitialSetting() |
| | |
| | | { |
| | | throw new ProcessException("未输入产品条码,请勿开始测量"); |
| | | } |
| | | |
| | | //检查产品放置OK |
| | | |
| | | //气缸推动压板移动到产品上方 |
| | | |
| | | //压板压紧产品 |
| | | |
| | | OnMeasureStart?.BeginInvoke(null, null); |
| | | |