You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
15 KiB
293 lines
15 KiB
using HslCommunication;
|
|
using HslCommunication.Core.Address;
|
|
using HslCommunication.ModBus;
|
|
using HybirdFrameworkCore.Utils;
|
|
using HybirdFrameworkServices.Plc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
|
|
|
namespace WinFormStarter
|
|
{
|
|
public partial class FrmPLCConnect : Form
|
|
{
|
|
#region 连接参数
|
|
/// <summary>
|
|
/// ModbusTcp客户端
|
|
/// </summary>
|
|
public static ModbusTcpNet _client = null;
|
|
public string _ipaddr
|
|
{
|
|
get
|
|
{
|
|
return TxtIp.Text;
|
|
}
|
|
set { }
|
|
}
|
|
public int _port
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToInt32(TxtPort.Text);
|
|
}
|
|
set { }
|
|
}
|
|
public byte _site
|
|
{
|
|
get
|
|
{
|
|
return Convert.ToByte(TxtSite.Text);
|
|
}
|
|
set { }
|
|
}
|
|
#endregion
|
|
|
|
PlcReadAndWritten PlcReadAndWritten;
|
|
PlcReadonly PlcReadonly;
|
|
PlcTurnsRatio PlcTurnsRatio;
|
|
|
|
public FrmPLCConnect()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void BtnConnect_Click(object sender, EventArgs e)
|
|
{
|
|
//简单判断
|
|
if (string.IsNullOrEmpty(_ipaddr))
|
|
{
|
|
MessageBox.Show("IP地址不能为空");
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(TxtPort.Text))
|
|
{
|
|
MessageBox.Show("端口号不能为空");
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(TxtSite.Text))
|
|
{
|
|
MessageBox.Show("站号不能为空");
|
|
return;
|
|
}
|
|
_client = new ModbusTcpNet(_ipaddr, _port, _site);
|
|
OperateResult OptRet = _client.ConnectServer();
|
|
if (OptRet.IsSuccess)
|
|
{
|
|
LblConState.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "连接成功";
|
|
BtnCollectionAssignment.Enabled = true;
|
|
//OperateResult writeResult = _client.Write("x=6;1", "");
|
|
}
|
|
if (OptRet.IsSuccess)
|
|
{
|
|
LblConState.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "连接失败";
|
|
}
|
|
}
|
|
|
|
private void BtnCollectionAssignment_Click(object sender, EventArgs e)
|
|
{
|
|
OperateResult<byte[]> read1 = _client.Read("x=3;100", 164);
|
|
OperateResult<byte[]> read2 = _client.Read("x=3;39424", 110);
|
|
OperateResult<byte[]> read3 = _client.Read("x=3;40960", 18);
|
|
|
|
PlcReadAndWritten = ModelConvert.Decode<PlcReadAndWritten>(read1.Content);
|
|
PlcReadonly = ModelConvert.Decode<PlcReadonly>(read1.Content);
|
|
PlcTurnsRatio = ModelConvert.Decode<PlcTurnsRatio>(read1.Content);
|
|
|
|
textBox1.Text = PlcReadAndWritten.ProgrammingEnable.ToString();
|
|
textBox2.Text = PlcReadAndWritten.Modbus1Addres.ToString();
|
|
textBox3.Text = PlcReadAndWritten.BaudRate.ToString();
|
|
textBox4.Text = PlcReadAndWritten.CheckBit.ToString();
|
|
textBox5.Text = PlcReadAndWritten.Seconds.ToString();
|
|
textBox6.Text = PlcReadAndWritten.Points.ToString();
|
|
textBox7.Text = PlcReadAndWritten.When.ToString();
|
|
textBox8.Text = PlcReadAndWritten.Weeks.ToString();
|
|
textBox9.Text = PlcReadAndWritten.Day.ToString();
|
|
textBox10.Text = PlcReadAndWritten.Month.ToString();
|
|
textBox11.Text = PlcReadAndWritten.Years.ToString();
|
|
textBox12.Text = PlcReadAndWritten.Modbus1Addres2.ToString();
|
|
textBox13.Text = PlcReadAndWritten.Reserve.ToString();
|
|
textBox14.Text = PlcReadAndWritten.VoltageRatio.ToString();
|
|
textBox17.Text = PlcReadAndWritten.CurrentRatio.ToString();
|
|
textBox18.Text = PlcReadAndWritten.PulsePerSecond.ToString();
|
|
textBox19.Text = PlcReadAndWritten.CurrentReversal.ToString();
|
|
textBox20.Text = PlcReadAndWritten.MeterReset.ToString();
|
|
}
|
|
|
|
bool now;
|
|
private void BtnToggle_Click(object sender, EventArgs e)
|
|
{
|
|
now = !now;
|
|
if (now)
|
|
{
|
|
|
|
#region
|
|
label31.Text = PlcReadonly.GroupHaveAll.ToString();
|
|
label29.Text = PlcReadonly.GroupHaveTip.ToString();
|
|
label27.Text = PlcReadonly.GroupHavePeak.ToString();
|
|
label25.Text = PlcReadonly.GroupHaveFlat.ToString();
|
|
label19.Text = PlcReadonly.GroupHaveValley.ToString();
|
|
label40.Text = PlcReadonly.ForwardHaveAll.ToString();
|
|
label38.Text = PlcReadonly.ForwardHaveTip.ToString();
|
|
label36.Text = PlcReadonly.ForwardHavePeak.ToString();
|
|
label34.Text = PlcReadonly.ForwardHaveFlat.ToString();
|
|
label32.Text = PlcReadonly.ForwardHaveValley.ToString();
|
|
label50.Text = PlcReadonly.ReverseHaveAll.ToString();
|
|
label48.Text = PlcReadonly.ReverseHaveTip.ToString();
|
|
label46.Text = PlcReadonly.ReverseHavePeak.ToString();
|
|
label44.Text = PlcReadonly.ReverseHaveFlat.ToString();
|
|
label42.Text = PlcReadonly.ReverseHaveValley.ToString();
|
|
label60.Text = PlcReadonly.GroupNoAll1.ToString();
|
|
label58.Text = PlcReadonly.GroupNoTip1.ToString();
|
|
label56.Text = PlcReadonly.GroupNoPeak1.ToString();
|
|
label54.Text = PlcReadonly.GroupNoFlat1.ToString();
|
|
label52.Text = PlcReadonly.GroupNoValley1.ToString();
|
|
label70.Text = PlcReadonly.GroupNoAll2.ToString();
|
|
label68.Text = PlcReadonly.GroupNoTip2.ToString();
|
|
label66.Text = PlcReadonly.GroupNoPeak2.ToString();
|
|
label64.Text = PlcReadonly.GroupNoFlat2.ToString();
|
|
label62.Text = PlcReadonly.GroupNoValley2.ToString();
|
|
label80.Text = PlcReadonly.QuadrantNoAll1.ToString();
|
|
label78.Text = PlcReadonly.QuadrantNoTip1.ToString();
|
|
label76.Text = PlcReadonly.QuadrantNoPeak1.ToString();
|
|
label74.Text = PlcReadonly.QuadrantNoFlat1.ToString();
|
|
label72.Text = PlcReadonly.QuadrantNoValley1.ToString();
|
|
label90.Text = PlcReadonly.QuadrantNoAll2.ToString();
|
|
label88.Text = PlcReadonly.QuadrantNoTip2.ToString();
|
|
label86.Text = PlcReadonly.QuadrantNoPeak2.ToString();
|
|
label84.Text = PlcReadonly.QuadrantNoFlat2.ToString();
|
|
label82.Text = PlcReadonly.QuadrantNoValley2.ToString();
|
|
label100.Text = PlcReadonly.QuadrantNoAll3.ToString();
|
|
label98.Text = PlcReadonly.QuadrantNoTip3.ToString();
|
|
label96.Text = PlcReadonly.QuadrantNoPeak3.ToString();
|
|
label94.Text = PlcReadonly.QuadrantNoFlat3.ToString();
|
|
label92.Text = PlcReadonly.QuadrantNoValley3.ToString();
|
|
label110.Text = PlcReadonly.QuadrantNoAll4.ToString();
|
|
label108.Text = PlcReadonly.QuadrantNoTip4.ToString();
|
|
label106.Text = PlcReadonly.QuadrantNoPeak4.ToString();
|
|
label104.Text = PlcReadonly.QuadrantNoFlat4.ToString();
|
|
label102.Text = PlcReadonly.QuadrantNoValley4.ToString();
|
|
label120.Text = PlcReadonly.ForwardHaveApparentAll.ToString();
|
|
label118.Text = PlcReadonly.ForwardHaveApparentTip.ToString();
|
|
label116.Text = PlcReadonly.ForwardHaveApparentPeak.ToString();
|
|
label114.Text = PlcReadonly.ForwardHaveApparentFlat.ToString();
|
|
label112.Text = PlcReadonly.ForwardHaveApparentValley.ToString();
|
|
label130.Text = PlcReadonly.ReverseHaveApparentAll.ToString();
|
|
label128.Text = PlcReadonly.ReverseHaveApparentTip.ToString();
|
|
label126.Text = PlcReadonly.ReverseHaveApparentPeak.ToString();
|
|
label124.Text = PlcReadonly.ReverseHaveApparentFlat.ToString();
|
|
label122.Text = PlcReadonly.ReverseHaveApparentValley.ToString();
|
|
|
|
|
|
label140.Text = PlcReadonly.PhaseVoltageA.ToString();
|
|
label138.Text = PlcReadonly.PhaseVoltageB.ToString();
|
|
label136.Text = PlcReadonly.PhaseVoltageC.ToString();
|
|
label134.Text = PlcReadonly.PhaseElectricityA.ToString();
|
|
label132.Text = PlcReadonly.PhaseElectricityB.ToString();
|
|
label172.Text = PlcReadonly.PhaseElectricityC.ToString();
|
|
|
|
label150.Text = PlcReadonly.TotalActivePower.ToString();
|
|
label148.Text = PlcReadonly.TotalActivePowerA.ToString();
|
|
label146.Text = PlcReadonly.TotalActivePowerB.ToString();
|
|
label144.Text = PlcReadonly.TotalActivePowerC.ToString();
|
|
|
|
label160.Text = PlcReadonly.TotalReactivePower.ToString();
|
|
label158.Text = PlcReadonly.TotalReactivePowerA.ToString();
|
|
label156.Text = PlcReadonly.TotalReactivePowerB.ToString();
|
|
label144.Text = PlcReadonly.TotalReactivePowerC.ToString();
|
|
|
|
label170.Text = PlcReadonly.TotalApparentPower.ToString();
|
|
label168.Text = PlcReadonly.TotalApparentPowerA.ToString();
|
|
label166.Text = PlcReadonly.TotalApparentPowerB.ToString();
|
|
label164.Text = PlcReadonly.TotalApparentPowerC.ToString();
|
|
|
|
label192.Text = PlcReadonly.OverallPowerFactor.ToString();
|
|
label190.Text = PlcReadonly.OverallPowerFactorA.ToString();
|
|
label188.Text = PlcReadonly.OverallPowerFactorB.ToString();
|
|
label184.Text = PlcReadonly.OverallPowerFactorC.ToString();
|
|
|
|
label174.Text = PlcReadonly.PhaseAngleA.ToString();
|
|
label162.Text = PlcReadonly.PhaseAngleB.ToString();
|
|
label152.Text = PlcReadonly.PhaseAngleC.ToString();
|
|
label142.Text = PlcReadonly.LineFrequency.ToString();
|
|
|
|
label184.Text = PlcReadonly.PhaseLineVoltageA.ToString();
|
|
label182.Text = PlcReadonly.PhaseLineVoltageB.ToString();
|
|
label180.Text = PlcReadonly.PhaseLineVoltageC.ToString();
|
|
label178.Text = PlcReadonly.ThreePhaseMeanLineVoltage.ToString();
|
|
label176.Text = PlcReadonly.ThreePhaseMeanPhaseVoltage.ToString();
|
|
|
|
#endregion
|
|
}
|
|
if (now)
|
|
{
|
|
#region
|
|
label31.Text = PlcTurnsRatio.GroupHaveAll.ToString();
|
|
label29.Text = PlcTurnsRatio.GroupHaveTip.ToString();
|
|
label27.Text = PlcTurnsRatio.GroupHavePeak.ToString();
|
|
label25.Text = PlcTurnsRatio.GroupHaveFlat.ToString();
|
|
label19.Text = PlcTurnsRatio.GroupHaveValley.ToString();
|
|
label40.Text = PlcTurnsRatio.ForwardHaveAll.ToString();
|
|
label38.Text = PlcTurnsRatio.ForwardHaveTip.ToString();
|
|
label36.Text = PlcTurnsRatio.ForwardHavePeak.ToString();
|
|
label34.Text = PlcTurnsRatio.ForwardHaveFlat.ToString();
|
|
label32.Text = PlcTurnsRatio.ForwardHaveValley.ToString();
|
|
label50.Text = PlcTurnsRatio.ReverseHaveAll.ToString();
|
|
label48.Text = PlcTurnsRatio.ReverseHaveTip.ToString();
|
|
label46.Text = PlcTurnsRatio.ReverseHavePeak.ToString();
|
|
label44.Text = PlcTurnsRatio.ReverseHaveFlat.ToString();
|
|
label42.Text = PlcTurnsRatio.ReverseHaveValley.ToString();
|
|
label60.Text = PlcTurnsRatio.GroupNoAll1.ToString();
|
|
label58.Text = PlcTurnsRatio.GroupNoTip1.ToString();
|
|
label56.Text = PlcTurnsRatio.GroupNoPeak1.ToString();
|
|
label54.Text = PlcTurnsRatio.GroupNoFlat1.ToString();
|
|
label52.Text = PlcTurnsRatio.GroupNoValley1.ToString();
|
|
label70.Text = PlcTurnsRatio.GroupNoAll2.ToString();
|
|
label68.Text = PlcTurnsRatio.GroupNoTip2.ToString();
|
|
label66.Text = PlcTurnsRatio.GroupNoPeak2.ToString();
|
|
label64.Text = PlcTurnsRatio.GroupNoFlat2.ToString();
|
|
label62.Text = PlcTurnsRatio.GroupNoValley2.ToString();
|
|
label80.Text = PlcTurnsRatio.QuadrantNoAll1.ToString();
|
|
label78.Text = PlcTurnsRatio.QuadrantNoTip1.ToString();
|
|
label76.Text = PlcTurnsRatio.QuadrantNoPeak1.ToString();
|
|
label74.Text = PlcTurnsRatio.QuadrantNoFlat1.ToString();
|
|
label72.Text = PlcTurnsRatio.QuadrantNoValley1.ToString();
|
|
label90.Text = PlcTurnsRatio.QuadrantNoAll2.ToString();
|
|
label88.Text = PlcTurnsRatio.QuadrantNoTip2.ToString();
|
|
label86.Text = PlcTurnsRatio.QuadrantNoPeak2.ToString();
|
|
label84.Text = PlcTurnsRatio.QuadrantNoFlat2.ToString();
|
|
label82.Text = PlcTurnsRatio.QuadrantNoValley2.ToString();
|
|
label100.Text = PlcTurnsRatio.QuadrantNoAll3.ToString();
|
|
label98.Text = PlcTurnsRatio.QuadrantNoTip3.ToString();
|
|
label96.Text = PlcTurnsRatio.QuadrantNoPeak3.ToString();
|
|
label94.Text = PlcTurnsRatio.QuadrantNoFlat3.ToString();
|
|
label92.Text = PlcTurnsRatio.QuadrantNoValley3.ToString();
|
|
label110.Text = PlcTurnsRatio.QuadrantNoAll4.ToString();
|
|
label108.Text = PlcTurnsRatio.QuadrantNoTip4.ToString();
|
|
label106.Text = PlcTurnsRatio.QuadrantNoPeak4.ToString();
|
|
label104.Text = PlcTurnsRatio.QuadrantNoFlat4.ToString();
|
|
label102.Text = PlcTurnsRatio.QuadrantNoValley4.ToString();
|
|
label120.Text = PlcTurnsRatio.ForwardHaveApparentAll.ToString();
|
|
label118.Text = PlcTurnsRatio.ForwardHaveApparentTip.ToString();
|
|
label116.Text = PlcTurnsRatio.ForwardHaveApparentPeak.ToString();
|
|
label114.Text = PlcTurnsRatio.ForwardHaveApparentFlat.ToString();
|
|
label112.Text = PlcTurnsRatio.ForwardHaveApparentValley.ToString();
|
|
label130.Text = PlcTurnsRatio.ReverseHaveApparentAll.ToString();
|
|
label128.Text = PlcTurnsRatio.ReverseHaveApparentTip.ToString();
|
|
label126.Text = PlcTurnsRatio.ReverseHaveApparentPeak.ToString();
|
|
label124.Text = PlcTurnsRatio.ReverseHaveApparentFlat.ToString();
|
|
label122.Text = PlcTurnsRatio.ReverseHaveApparentValley.ToString();
|
|
#endregion
|
|
}
|
|
}
|
|
//TODO::没有数据写入,稍后添加
|
|
}
|
|
}
|