public bool Success(string name) { if (!Format.Match(name).Success) { return(false); } switch (Type) { case "BIT": if (ValueParser.ParseBitValue(name) == null) { return(false); } break; case "WORD": if (ValueParser.ParseWordValue(name) == null) { return(false); } break; case "DWORD": if (ValueParser.ParseDoubleWordValue(name) == null) { return(false); } break; case "FLOAT": if (ValueParser.ParseFloatValue(name) == null) { return(false); } break; } return(true); }
static public ArgumentValue Create(string argname, string argtype, string name, PLCDevice.Device device) { IValueModel argument = null; switch (argtype) { case "BIT*": if (!ValueParser.VerifyBitRegex3.Match(name).Success) { throw new ValueParseException(String.Format("{0:s}的寄存器名称错误!位寄存器只允许Y/M/S", argname)); } try { argument = ValueParser.ParseBitValue(name, device); } catch (ValueParseException) { throw new ValueParseException(String.Format("{0:s}的寄存器超出允许的范围!", argname)); } break; case "WORD*": if (!ValueParser.VerifyWordRegex2.Match(name).Success) { throw new ValueParseException(String.Format("{0:s}的寄存器名称错误!单字寄存器只允许D/TV/CV/AO", argname)); } try { argument = ValueParser.ParseWordValue(name, device); } catch (ValueParseException) { throw new ValueParseException(String.Format("{0:s}的寄存器超出允许的范围!", argname)); } break; case "DWORD*": if (!ValueParser.VerifyDoubleWordRegex1.Match(name).Success) { throw new ValueParseException(String.Format("{0:s}的寄存器名称错误!双字寄存器只允许D/CV", argname)); } try { argument = ValueParser.ParseDoubleWordValue(name, device); } catch (ValueParseException) { throw new ValueParseException(String.Format("{0:s}的寄存器超出允许的范围!", argname)); } break; case "FLOAT*": if (!ValueParser.VerifyFloatRegex.Match(name).Success) { throw new ValueParseException(String.Format("{0:s}的寄存器名称错误!浮点寄存器只允许D", argname)); } try { argument = ValueParser.ParseFloatValue(name, device); } catch (ValueParseException) { throw new ValueParseException(String.Format("{0:s}的寄存器超出允许的范围!", argname)); } break; } return(new ArgumentValue(argname, argtype, argument)); }