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/SetFromValue/FormEnqPar.cs

81 lines
2.7 KiB
C#

12 months ago
using DataBlockHelper;
using HslCommunication.Profinet.Siemens;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.SetValueInfo
{
public partial class FormEnqPar : Form
{
public FormEnqPar()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.FixedDialog;//设置边框为不可调节
this.MaximizeBox = false;//取消最大化按键
this.MinimizeBox = false;//取消最小化按键
Init();
}
private void Init()
{
///临时着急用 直接访问plc
string db = "DB2105.222.0";
var siemensS7Net = PlcConnect.Instance;
var byts = siemensS7Net.Read(db, 32).Content;
txtValue1.Text = siemensS7Net.ByteTransform.TransSingle(byts, 0).ToString();
txtValue2.Text = siemensS7Net.ByteTransform.TransSingle(byts, 4).ToString();
txtValue3.Text = siemensS7Net.ByteTransform.TransSingle(byts, 8).ToString();
txtValue4.Text = siemensS7Net.ByteTransform.TransSingle(byts, 12).ToString();
txtValue5.Text = siemensS7Net.ByteTransform.TransSingle(byts, 16).ToString();
txtValue6.Text = siemensS7Net.ByteTransform.TransSingle(byts, 20).ToString();
txtValue7.Text = siemensS7Net.ByteTransform.TransSingle(byts, 24).ToString();
txtValue8.Text = siemensS7Net.ByteTransform.TransSingle(byts, 28).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
var s7 = PlcConnect.Instance;
int start = 222;
s7.Write($"DB2105.{start}.0", Convert.ToSingle(txtValue1.Text));
start += 4;
s7.Write($"DB2105.{start}.0", Convert.ToSingle(txtValue2.Text));
start += 4;
s7.Write($"DB2105.{start}.0", Convert.ToSingle(txtValue3.Text));
start += 4;
s7.Write($"DB2105.{start}.0", Convert.ToSingle(txtValue4.Text));
start += 4;
s7.Write($"DB2105.{start}.0", Convert.ToSingle(txtValue5.Text));
start += 4;
s7.Write($"DB2105.{start}.0", Convert.ToSingle(txtValue6.Text));
start += 4;
s7.Write($"DB2105.{start}.0", Convert.ToSingle(txtValue7.Text));
start += 4;
s7.Write($"DB2105.{start}.0", Convert.ToSingle(txtValue8.Text));
MessageBox.Show("现场按钮下发成功");
}
}
}