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.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjDeliverControlBoard/ControlsHelper.cs

119 lines
3.6 KiB
C#

using DataBlockHelper;
using HslCommunication.Profinet.Siemens;
using Mesnac.Action.ChemicalWeighing.AutoControl.Entity;
using Mesnac.Action.ChemicalWeighing.LjDeliverControlBoard.Entity;
using Mesnac.Action.ChemicalWeighing.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MCRadioButtonEntity = Mesnac.Action.ChemicalWeighing.LjDeliverControlBoard.Entity.MCRadioButtonEntity;
namespace Mesnac.Action.ChemicalWeighing.LjDeliverControlBoard
{
public class ControlsHelper : ControlsImprot
{
private static SiemensS7Net siemensS7Net = PlcConnect.Instance;
public static int BottleSelectA(MCRadioButtonEntity RadioButtonE)
{
int no = 0;
if (Convert.ToBoolean(RadioButtonE.SingleBottle1A.MCValue))
{
no = 1;
}
else if (Convert.ToBoolean(RadioButtonE.SingleBottle2A.MCValue))
{
no = 2;
}
else if (Convert.ToBoolean(RadioButtonE.DoubleBottleA.MCValue))
{
no = 3;
}
return no;
}
public static int BottleSelectB(MCRadioButtonEntity RadioButtonE)
{
int no = 0;
if (Convert.ToBoolean(RadioButtonE.SingleBottle1B.MCValue))
{
no = 1;
}
else if (Convert.ToBoolean(RadioButtonE.SingleBottle2B.MCValue))
{
no = 2;
}
else if (Convert.ToBoolean(RadioButtonE.DoubleBottleB.MCValue))
{
no = 3;
}
return no;
}
public static int BottleSelectC(MCRadioButtonEntity RadioButtonE)
{
int no = 0;
if (Convert.ToBoolean(RadioButtonE.SingleBottle1C.MCValue))
{
no = 1;
}
else if (Convert.ToBoolean(RadioButtonE.SingleBottle2C.MCValue))
{
no = 2;
}
else if (Convert.ToBoolean(RadioButtonE.DoubleBottleC.MCValue))
{
no = 3;
}
return no;
}
/// <summary>
/// 读取手自动模式状态
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static byte ReadMode(string str)
{
var bytes = PlcConnect.Instance.Read($"DB91.{str}.0", 1).Content;
return bytes[0];
}
/// <summary>
/// 写入手自动模式
/// </summary>
/// <param name="str"></param>
/// <param name="state">第一位为state 第二位相反</param>
public static void WriteMode(string str, bool state)
{
siemensS7Net.Write($"DB91.{str}.0", state);
siemensS7Net.Write($"DB91.{str}.1", !state);
}
/// <summary>
/// 写入34位置
/// </summary>
/// <param name="str"></param>
/// <param name="state">第一位为state 第二位相反</param>
public static void WriteModeP1(string str, bool state)
{
siemensS7Net.Write($"DB91.{str}.2", state);
siemensS7Net.Write($"DB91.{str}.3", !state);
}
/// <summary>
/// 写入56位置
/// </summary>
/// <param name="str"></param>
/// <param name="state">第一位为state 第二位相反</param>
public static void WriteModeP2(string str, bool state)
{
siemensS7Net.Write($"DB91.{str}.4", state);
siemensS7Net.Write($"DB91.{str}.5", !state);
}
}
}