|
|
|
@ -160,64 +160,64 @@ namespace HighWayIot.Plc
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC2写入数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address">地址</param>
|
|
|
|
|
/// <param name="value">值</param>
|
|
|
|
|
/// <param name="type">数据类型</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static OperateResult PlcWrite2(string address, object value, DataTypeEnum type)
|
|
|
|
|
{
|
|
|
|
|
var result = new OperateResult() { IsSuccess = false };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case DataTypeEnum.Bool:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToBoolean(value));
|
|
|
|
|
break;
|
|
|
|
|
//case DataTypeEnum.Byte:
|
|
|
|
|
// result = Instance.Write(address, Convert.ToByte(value));
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// PLC2写入数据
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address">地址</param>
|
|
|
|
|
///// <param name="value">值</param>
|
|
|
|
|
///// <param name="type">数据类型</param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static OperateResult PlcWrite2(string address, object value, DataTypeEnum type)
|
|
|
|
|
//{
|
|
|
|
|
// var result = new OperateResult() { IsSuccess = false };
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// switch (type)
|
|
|
|
|
// {
|
|
|
|
|
// case DataTypeEnum.Bool:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToBoolean(value));
|
|
|
|
|
// break;
|
|
|
|
|
case DataTypeEnum.Int16:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToInt16(value));
|
|
|
|
|
break;
|
|
|
|
|
case DataTypeEnum.UInt16:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToUInt16(value));
|
|
|
|
|
break;
|
|
|
|
|
case DataTypeEnum.Int32:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToInt32(value));
|
|
|
|
|
break;
|
|
|
|
|
case DataTypeEnum.UInt32:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToUInt32(value));
|
|
|
|
|
break;
|
|
|
|
|
case DataTypeEnum.Int64:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToInt64(value));
|
|
|
|
|
break;
|
|
|
|
|
case DataTypeEnum.UInt64:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToUInt64(value));
|
|
|
|
|
break;
|
|
|
|
|
case DataTypeEnum.Float:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToSingle(value));
|
|
|
|
|
break;
|
|
|
|
|
case DataTypeEnum.Double:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToDouble(value));
|
|
|
|
|
break;
|
|
|
|
|
case DataTypeEnum.String:
|
|
|
|
|
result = MelsecInstance2.Write(address, Convert.ToString(value));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentException($"Unsupported data type: {type}");
|
|
|
|
|
}
|
|
|
|
|
logHelper.PlcLog($"Read address:[{address}] value:[{value}] type:[{type.ToString()}] result:[{result.IsSuccess}]");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("PLC写入数据发生错误!", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
// //case DataTypeEnum.Byte:
|
|
|
|
|
// // result = Instance.Write(address, Convert.ToByte(value));
|
|
|
|
|
// // break;
|
|
|
|
|
// case DataTypeEnum.Int16:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToInt16(value));
|
|
|
|
|
// break;
|
|
|
|
|
// case DataTypeEnum.UInt16:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToUInt16(value));
|
|
|
|
|
// break;
|
|
|
|
|
// case DataTypeEnum.Int32:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToInt32(value));
|
|
|
|
|
// break;
|
|
|
|
|
// case DataTypeEnum.UInt32:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToUInt32(value));
|
|
|
|
|
// break;
|
|
|
|
|
// case DataTypeEnum.Int64:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToInt64(value));
|
|
|
|
|
// break;
|
|
|
|
|
// case DataTypeEnum.UInt64:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToUInt64(value));
|
|
|
|
|
// break;
|
|
|
|
|
// case DataTypeEnum.Float:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToSingle(value));
|
|
|
|
|
// break;
|
|
|
|
|
// case DataTypeEnum.Double:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToDouble(value));
|
|
|
|
|
// break;
|
|
|
|
|
// case DataTypeEnum.String:
|
|
|
|
|
// result = MelsecInstance2.Write(address, Convert.ToString(value));
|
|
|
|
|
// break;
|
|
|
|
|
// default:
|
|
|
|
|
// throw new ArgumentException($"Unsupported data type: {type}");
|
|
|
|
|
// }
|
|
|
|
|
// logHelper.PlcLog($"Read address:[{address}] value:[{value}] type:[{type.ToString()}] result:[{result.IsSuccess}]");
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error("PLC写入数据发生错误!", ex);
|
|
|
|
|
// }
|
|
|
|
|
// return result;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 字符串读取1
|
|
|
|
@ -460,246 +460,246 @@ namespace HighWayIot.Plc
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字符串读取2
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <param name="length"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string ReadString2(string address, ushort length)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<string> result = new OperateResult<string>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadString(address, length);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC2读取String发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 字符串读取2
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <param name="length"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static string ReadString2(string address, ushort length)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<string> result = new OperateResult<string>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadString(address, length);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC2读取String发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取bool
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool ReadBool2(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<bool> result = new OperateResult<bool>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadBool(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Bool发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取bool
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static bool ReadBool2(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<bool> result = new OperateResult<bool>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadBool(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Bool发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取Int16
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static short ReadInt162(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<short> result = new OperateResult<short>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadInt16(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取Int16
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static short ReadInt162(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<short> result = new OperateResult<short>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadInt16(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取UInt16
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static ushort ReadUInt162(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<ushort> result = new OperateResult<ushort>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadUInt16(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取UInt16
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static ushort ReadUInt162(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<ushort> result = new OperateResult<ushort>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadUInt16(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取Int32
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static int ReadInt322(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<int> result = new OperateResult<int>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadInt32(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取Int32
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static int ReadInt322(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<int> result = new OperateResult<int>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadInt32(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取UInt32
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static uint ReadUInt322(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<uint> result = new OperateResult<uint>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadUInt32(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取UInt32
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static uint ReadUInt322(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<uint> result = new OperateResult<uint>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadUInt32(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取Int64
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static long ReadInt642(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<long> result = new OperateResult<long>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadInt64(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取Int64
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static long ReadInt642(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<long> result = new OperateResult<long>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadInt64(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取UInt64
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static ulong ReadUInt642(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<ulong> result = new OperateResult<ulong>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadUInt64(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取UInt64
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static ulong ReadUInt642(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<ulong> result = new OperateResult<ulong>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadUInt64(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Int16发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取Float
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static float ReadFloat2(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<float> result = new OperateResult<float>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadFloat(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Float发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取Float
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static float ReadFloat2(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<float> result = new OperateResult<float>();
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadFloat(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Float发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读取Double
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="address"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static double ReadDouble2(string address)
|
|
|
|
|
{
|
|
|
|
|
OperateResult<double> result = new OperateResult<double>();
|
|
|
|
|
///// <summary>
|
|
|
|
|
///// 读取Double
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <param name="address"></param>
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
//public static double ReadDouble2(string address)
|
|
|
|
|
//{
|
|
|
|
|
// OperateResult<double> result = new OperateResult<double>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result = MelsecInstance2.ReadDouble(address);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error($"PLC读取Double发生错误!address:[{address}]", ex);
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
return result.Content;
|
|
|
|
|
}
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// result = MelsecInstance2.ReadDouble(address);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// logHelper.Error($"PLC读取Double发生错误!address:[{address}]", ex);
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// if (!result.IsSuccess)
|
|
|
|
|
// {
|
|
|
|
|
// return default;
|
|
|
|
|
// }
|
|
|
|
|
// return result.Content;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|