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.
53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
using Mesnac.PlcUtils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.EngineeringDebuggingMode
|
|
{
|
|
|
|
public class PlcCommunicationUtil
|
|
{
|
|
string DmName;
|
|
BasePlcHelper Plc = BasePlcHelper.Instance;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 根据属性名和现在选择的数据块名得到PLC数据块的具体引用
|
|
/// </summary>
|
|
/// <param name="dmValue">数据块属性名</param>
|
|
/// <returns></returns>
|
|
private DataKeyValue GetDataNameValue(string dmValue)
|
|
{
|
|
return new DataKeyValue(DmName + dmValue);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从PLC中读取值
|
|
/// </summary>
|
|
/// <param name="dmValue">要读取的属性</param>
|
|
/// <returns></returns>
|
|
private int GetDataToInt(String dmValue)
|
|
{
|
|
return GetDataNameValue(dmValue).NowValue.ToInt();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 向PLC中写入值
|
|
/// </summary>
|
|
/// <param name="dmValue">要写入的属性</param>
|
|
/// <param name="value">写入的值</param>
|
|
private void SetDataValue(String dmValue, int value)
|
|
{
|
|
Plc.PlcWriteByDataKey(GetDataNameValue(dmValue), new Object[] { value });
|
|
}
|
|
}
|
|
}
|