You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Plc
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Plc帮助类
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class StaticPlcHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 进行高低位转换后,写入Plc地址
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="plc"> plc </param>
|
|
|
|
|
|
/// <param name="address"> 写入地址 </param>
|
|
|
|
|
|
/// <param name="valueString"> 值 </param>
|
|
|
|
|
|
/// <param name="len"> 长度 </param>
|
|
|
|
|
|
public static void WriteToPoint(this Plc.S7.Plc plc,string address,string valueString,string len)
|
|
|
|
|
|
{
|
|
|
|
|
|
var value = GetValue(len, valueString);
|
|
|
|
|
|
plc.Write(address, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 电气写入点位高低位转换
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="len">点位地址位长度</param>
|
|
|
|
|
|
/// <param name="value">写入数值</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static object GetValue(string len, string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (len == "2")
|
|
|
|
|
|
{
|
|
|
|
|
|
return Convert.ToInt16(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (len == "4")
|
|
|
|
|
|
{
|
|
|
|
|
|
return Convert.ToInt32(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|