public AlgorithmAction(DeviceAlgorithm device, AlgorithmAction algorithmAction, ActionSettings actionSettings) { Device = device; ParentAction = algorithmAction; ActionSettings = actionSettings; Type = actionSettings.Type; Name = actionSettings.Name; OnDbWriteOnly = actionSettings.OnDbWriteOnly; CommonConstruction(); }
public ActionParameter(DeviceAlgorithm device, AlgorithmAction algorithmAction, ParameterSettings parameterSettings) { Device = device; AlgorithmAction = algorithmAction; ParameterSettings = parameterSettings; Name = ParameterSettings.Name; IsSpecialValue = Name.StartsWith("!"); Content = ParameterSettings.Content; if (Content != "") ContentVariable = Device.FindVariable(Content); else ContentVariable = null; ParameterValue = ParameterSettings.ParameterValue; }
public DeviceBlock(DeviceAlgorithm device, BlockSettings blockSettings, Protocol protocol) { AlarmFound = false; ErrorFound = false; Device = device; //DeviceManager = Device.DeviceManager; //DeviceManager = Device.Manager; BlockSettings = blockSettings; retryCount = BlockSettings.TimeoutRetries; Protocol = protocol; ProtocolType = Protocol.Type; Conversation = Protocol.GetConversation(BlockSettings.Conversation); Name = BlockSettings.Name; Type = BlockSettings.Type; OnDbWriteOnly = BlockSettings.OnDbWriteOnly; LoadRegisters(); int? temp = BlockSettings.Base; Base = temp.HasValue ? temp.Value : -1; }
public static void DecimalToBytes(DeviceAlgorithm device, decimal value, RegisterSettings.RegisterValueType valueType, ref byte[] registerData, int size, int registerIndex, bool cStringNull) { byte[] bytes = null; // rv_uint16_exp and rv_sint16_exp not supported for data writes // ordered to minimise tests if (valueType == RegisterSettings.RegisterValueType.rv_uint16) bytes = device.Params.EndianConverter16Bit.GetExternalBytes((UInt16)value); else if (valueType == RegisterSettings.RegisterValueType.rv_uint32) bytes = device.Params.EndianConverter32Bit.GetExternalBytes((UInt32)value); else if (valueType == RegisterSettings.RegisterValueType.rv_byte) { bytes = new byte[1]; bytes[0] = (byte)value; } else if (valueType == RegisterSettings.RegisterValueType.rv_sint16) bytes = device.Params.EndianConverter16Bit.GetExternalBytes((Int16)value); else if (valueType == RegisterSettings.RegisterValueType.rv_sint32) bytes = device.Params.EndianConverter32Bit.GetExternalBytes((Int32)value); else if (valueType == RegisterSettings.RegisterValueType.rv_bcd) bytes = EndianConverter32Bit.GetBCDFromDecimal(value, size, 0, false); else if (valueType == RegisterSettings.RegisterValueType.rv_string) bytes = StringToBytes(value.ToString(), size, cStringNull ? (byte)0 : (byte)' '); int j = registerIndex; for (int i = 0; i < bytes.Length; ) registerData[j++] = bytes[i++]; }
public static String BytesToString(DeviceAlgorithm device, RegisterSettings.RegisterValueType valueType, ref byte[] input, int size, int start, bool cStringNull) { if (valueType == RegisterSettings.RegisterValueType.rv_string) { int outSize = size; if (start + outSize > input.Length) outSize = input.Length - start; if (outSize < 1) // return ""; // Need to know if this is occuring throw new ConvException("BytesToString size error - Size: " + size + " - Start: " + start); char[] output = new char[outSize]; int inPos = start; int strSize = outSize; for (int i = 0; i < outSize; i++) { byte b = input[inPos]; if (cStringNull && b == 0) { strSize = inPos - start; break; } output[i] = (char)b; inPos++; } StringBuilder sb = new StringBuilder(output.Length); sb.Append(output, 0, strSize); return sb.ToString(); } if (valueType == RegisterSettings.RegisterValueType.rv_bytes) return ""; return RegisterNumber.BytesToDecimal(device, valueType, ref input, size, start, cStringNull).ToString(); }
public static void BytesToRegisterBytes(DeviceAlgorithm device, byte[] value, int valueIndex, ref byte[] registerData, int size, int registerIndex, bool cStringNull) { int j = registerIndex; int i; for (i = 0; i < value.Length && i < size; i++) registerData[j++] = value[valueIndex++]; byte pad = cStringNull ? (byte)0 : (byte)' '; while (i < size) registerData[j++] = pad; }
public static decimal BytesToDecimal(DeviceAlgorithm device, RegisterSettings.RegisterValueType valueType, ref byte[] registerData, int size, int registerIndex, bool cStringNull) { Decimal val = 0; // ordered to minimise tests if (valueType == RegisterSettings.RegisterValueType.rv_uint16) val = device.Params.EndianConverter16Bit.GetUInt16FromBytes(ref registerData, registerIndex); else if (valueType == RegisterSettings.RegisterValueType.rv_uint16_exp) { UInt16 raw = device.Params.EndianConverter16Bit.GetUInt16FromBytes(ref registerData, registerIndex); byte exp = registerData[registerIndex + 2]; val = ApplyExponent(raw, exp); } else if (valueType == RegisterSettings.RegisterValueType.rv_uint32) val = device.Params.EndianConverter32Bit.GetUInt32FromBytes(ref registerData, registerIndex); else if (valueType == RegisterSettings.RegisterValueType.rv_byte) val = registerData[registerIndex]; else if (valueType == RegisterSettings.RegisterValueType.rv_sint16) val = device.Params.EndianConverter16Bit.GetInt16FromBytes(ref registerData, registerIndex); else if (valueType == RegisterSettings.RegisterValueType.rv_sint16_exp) { Int16 raw = device.Params.EndianConverter16Bit.GetInt16FromBytes(ref registerData, registerIndex); byte exp = registerData[registerIndex + 2]; val = ApplyExponent(raw, exp); } else if (valueType == RegisterSettings.RegisterValueType.rv_sint32) val = device.Params.EndianConverter32Bit.GetInt32FromBytes(ref registerData, registerIndex); else if (valueType == RegisterSettings.RegisterValueType.rv_bcd) val = EndianConverter32Bit.GetDecimalFromBCD(ref registerData, size, registerIndex); else if (valueType == RegisterSettings.RegisterValueType.rv_string) val = Decimal.Parse(RegisterString.BytesToString(device, valueType, ref registerData, size, registerIndex, cStringNull)); return val; }
public AlgorithmAction_Repeat(DeviceAlgorithm device, Algorithm algorithm, ActionSettings actionSettings) : base(device, algorithm, actionSettings) { CommonConstruction(); }
public static byte[] RegisterBytesToBytes(DeviceAlgorithm device, ref byte[] registerData, int size, int registerIndex, bool cStringNull) { byte[] bytes = new byte[size]; int j = registerIndex; int i; for (i = 0; i < size; i++) bytes[i] = registerData[j++]; return bytes; }
public DeviceBlock_NonModbus(DeviceAlgorithm device, BlockSettings blockSettings, Protocol protocol) : base(device, blockSettings, protocol) { }
public DeviceBlock_Modbus(DeviceAlgorithm device, BlockSettings blockSettings, Protocol protocol) : base(device, blockSettings, protocol) { CommandId = BlockSettings.CommandId; IsKLNEModbus = protocol.ProtocolSettings.Name == "KLNEModbus"; }
public AlgorithmAction_SendBlock(DeviceAlgorithm device, AlgorithmAction action, ActionSettings actionSettings) : base(device, action, actionSettings) { CommonConstruction(); }
public AlgorithmAction_RepeatCountTimes(DeviceAlgorithm device, AlgorithmAction action, ActionSettings actionSettings) : base(device, action, actionSettings) { CommonConstruction(); }
public Algorithm(DeviceAlgorithm device, ActionSettings actionSettings) : base(device, null, actionSettings) { }
public static string FroniusModelFromBytes(DeviceAlgorithm device, RegisterSettings.RegisterValueType valueType, ref byte[] input, int size, int start, bool cStringNull) { if (size != 1) return "Unknown"; byte id = input[start]; foreach (FroniusModel model in FroniusModels) if (id == model.Id) return model.Name; return "Fronius - Unknown"; }
public DeviceBlock_Phoenixtec(DeviceAlgorithm device, BlockSettings blockSettings, Protocol protocol) : base(device, blockSettings, protocol) { }
public static string GrowattModelFromBytes(DeviceAlgorithm device, RegisterSettings.RegisterValueType valueType, ref byte[] input, int size, int start, bool cStringNull) { if (size < 2) return "Unknown"; String hex = SystemServices.BytesToHex(ref input, 1, "", "", start, size); string result = String.Format("P{0} U{1} M{2} S{3}", hex[0], hex[1], hex[2], hex[3]); return result; }
public DeviceBlock_RequestResponse(DeviceAlgorithm device, BlockSettings blockSettings, Protocol protocol) : base(device, blockSettings, protocol) { }
public static void StringToBytes(DeviceAlgorithm device, String value, ref byte[] registerData, int size, int registerIndex, bool cStringNull) { byte[] bytes = StringToBytes(value, size, cStringNull ? (byte)0 : (byte)' '); int j = registerIndex; for (int i = 0; i < bytes.Length; ) registerData[j++] = bytes[i++]; }
public AlgorithmAction_LogError(DeviceAlgorithm device, AlgorithmAction action, ActionSettings actionSettings) : base(device, action, actionSettings) { CommonConstruction(); }