public override void WriteOutputSignal(string signalName, object value) { if (Outputs.ContainsKey(signalName)) { AdressValueInfo output = (AdressValueInfo)Outputs[signalName]; switch (output.valueType.ToString()) { case "System.UInt16": Write(output.adress, (ushort)value); break; case "System.UInt32": Write(output.adress, (uint)value); break; case "System.UInt64": Write(output.adress, (ulong)value); break; case "System.Int16": Write(output.adress, (short)value); break; case "System.Int32": Write(output.adress, (int)value); break; case "System.Int64": Write(output.adress, (long)value); break; case "System.Boolean": Write(output.adress, (bool)value); break; case "System.Byte": Write(output.adress, (byte)value); break; case "System.SByte": Write(output.adress, (sbyte)value); break; case "System.Double": Write(output.adress, (double)value); break; case "System.Single": Write(output.adress, (float)value); break; case "System.String": Write(output.adress, (string)value); break; } } }
public override void WriteOutputSignal(string signalName, object value) { if (Outputs.ContainsKey(signalName)) { AdressValueInfo output = (AdressValueInfo)Outputs[signalName]; S7Adress signalAdress = (S7Adress)output.adress; plc.Write((DataType)signalAdress.dataType, signalAdress.dbAdress, signalAdress.startAdress, value); } }
public void ReadAressFile(string filePath) { string path = System.Environment.CurrentDirectory; path = filePath + "\\ModbusAdress"; if (!File.Exists(path)) { throw new Exception("配置文件不存在!"); } using (StreamReader sr = new StreamReader(path)) { var line = sr.ReadLine(); while (line != null) { line = sr.ReadLine(); string[] strs = line.Split(','); if (strs[0] != "No" && strs[0] != string.Empty) { if (strs[(int)eModbusAdressTitle.IsInput].Trim(' ') == "1") { ModbusAdress adress = new ModbusAdress(); adress.SignalAdress = strs[(int)eModbusAdressTitle.Adress]; AdressValueInfo valueInfo = new AdressValueInfo() { adress = adress, deviceValue = new ModbusValue(), length = Convert.ToUInt16(strs[(int)eModbusAdressTitle.AdressLenth]), valueType = GetAdressType(strs[(int)eModbusAdressTitle.AdressType]), }; this.AddInputSignal(strs[(int)eModbusAdressTitle.AdressName], valueInfo); } if (strs[(int)eModbusAdressTitle.IsOutput].Trim(' ') == "1") { ModbusAdress adress = new ModbusAdress(); adress.SignalAdress = strs[(int)eModbusAdressTitle.Adress]; AdressValueInfo valueInfo = new AdressValueInfo() { adress = adress, deviceValue = new ModbusValue(), length = Convert.ToUInt16(strs[(int)eModbusAdressTitle.AdressLenth]), valueType = GetAdressType(strs[(int)eModbusAdressTitle.AdressType]), }; this.AddOutputSignal(strs[(int)eModbusAdressTitle.AdressName], valueInfo); } } } } }
public override object ReadInputSignal(string signalName) { if (Inputs.ContainsKey(signalName)) { AdressValueInfo value = (AdressValueInfo)Inputs[signalName]; value.deviceValue = new ModbusValue(); switch (value.valueType.Name) { case "System.UInt16": return(ReadUInt16(value.adress)); case "System.UInt32": return(ReadUInt32(value.adress)); case "System.UInt64": return(ReadUInt64(value.adress)); case "System.Int16": return(ReadInt16(value.adress)); case "System.Int32": return(ReadInt32(value.adress)); case "System.Int64": return(ReadInt64(value.adress)); case "System.Boolean": return(ReadBoolean(value.adress)); case "System.Byte": return(ReadByte(value.adress)); case "System.SByte": return(ReadSbyte(value.adress)); case "System.Double": return(ReadDouble(value.adress)); case "System.Single": return(ReadSingle(value.adress)); case "System.String": return(ReadString(value.adress, value.length)); } } return(null); }