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.
649 lines
28 KiB
649 lines
28 KiB
using HslCommunication;
|
|
using HslCommunication.Core.Address;
|
|
using HslCommunication.ModBus;
|
|
using HybirdFrameworkCore.Utils;
|
|
using HybirdFrameworkDriver.ModbusTcpMaster;
|
|
using HybirdFrameworkDriver.TcpServer;
|
|
using HybirdFrameworkServices.Init.Entity;
|
|
using HybirdFrameworkServices.Plc;
|
|
using SqlSugar;
|
|
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 StackExchange.Redis.Role;
|
|
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
|
|
|
|
PlcDate PlcDate = new PlcDate();
|
|
|
|
public FrmPLCConnect()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region 连接
|
|
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") + "连接失败";
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 读取
|
|
private void BtnCollectionAssignment_Click(object sender, EventArgs e)
|
|
{
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo==null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
|
|
textBox1.Text = plcInfo.PlcReadAndWritten1.ProgrammingEnable.ToString();
|
|
textBox2.Text = plcInfo.PlcReadAndWritten1.Modbus1Addres.ToString();
|
|
textBox3.Text = plcInfo.PlcReadAndWritten1.BaudRate.ToString();
|
|
textBox4.Text = plcInfo.PlcReadAndWritten1.CheckBit.ToString();
|
|
textBox5.Text = plcInfo.PlcReadAndWritten2.Seconds.ToString();
|
|
textBox6.Text = plcInfo.PlcReadAndWritten2.Points.ToString();
|
|
textBox7.Text = plcInfo.PlcReadAndWritten2.When.ToString();
|
|
textBox8.Text = plcInfo.PlcReadAndWritten2.Weeks.ToString();
|
|
textBox9.Text = plcInfo.PlcReadAndWritten2.Day.ToString();
|
|
textBox10.Text = plcInfo.PlcReadAndWritten2.Month.ToString();
|
|
textBox11.Text = plcInfo.PlcReadAndWritten2.Years.ToString();
|
|
textBox12.Text = plcInfo.PlcReadAndWritten2.Modbus1Addres2.ToString();
|
|
textBox13.Text = plcInfo.PlcReadAndWritten2.Reserve.ToString();
|
|
textBox14.Text = plcInfo.PlcReadAndWritten2.VoltageRatio.ToString();
|
|
textBox15.Text = plcInfo.PlcReadAndWritten2.CurrentRatio.ToString();
|
|
textBox16.Text = plcInfo.PlcReadAndWritten1.PulsePerSecond.ToString();
|
|
textBox17.Text = plcInfo.PlcReadAndWritten1.CurrentReversal.ToString();
|
|
textBox18.Text = plcInfo.PlcReadAndWritten1.MeterReset.ToString();
|
|
string datetime = plcInfo.PlcReadAndWritten2.Years + "-" +
|
|
plcInfo.PlcReadAndWritten2.Month + "-" +
|
|
plcInfo.PlcReadAndWritten2.Day + " " +
|
|
plcInfo.PlcReadAndWritten2.When + ":" +
|
|
plcInfo.PlcReadAndWritten2.Points + ":" +
|
|
plcInfo.PlcReadAndWritten2.Seconds;
|
|
}
|
|
#endregion
|
|
|
|
#region 切换数据
|
|
bool now;
|
|
private void BtnToggle_Click(object sender, EventArgs e)
|
|
{
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
|
|
now = !now;
|
|
if (now)
|
|
{
|
|
|
|
#region
|
|
label31.Text = plcInfo.PlcReadonly.GroupHaveAll.ToString();
|
|
label29.Text = plcInfo.PlcReadonly.GroupHaveTip.ToString();
|
|
label27.Text = plcInfo.PlcReadonly.GroupHavePeak.ToString();
|
|
label25.Text = plcInfo.PlcReadonly.GroupHaveFlat.ToString();
|
|
label19.Text = plcInfo.PlcReadonly.GroupHaveValley.ToString();
|
|
label40.Text = plcInfo.PlcReadonly.ForwardHaveAll.ToString();
|
|
label38.Text = plcInfo.PlcReadonly.ForwardHaveTip.ToString();
|
|
label36.Text = plcInfo.PlcReadonly.ForwardHavePeak.ToString();
|
|
label34.Text = plcInfo.PlcReadonly.ForwardHaveFlat.ToString();
|
|
label32.Text = plcInfo.PlcReadonly.ForwardHaveValley.ToString();
|
|
label50.Text = plcInfo.PlcReadonly.ReverseHaveAll.ToString();
|
|
label48.Text = plcInfo.PlcReadonly.ReverseHaveTip.ToString();
|
|
label46.Text = plcInfo.PlcReadonly.ReverseHavePeak.ToString();
|
|
label44.Text = plcInfo.PlcReadonly.ReverseHaveFlat.ToString();
|
|
label42.Text = plcInfo.PlcReadonly.ReverseHaveValley.ToString();
|
|
label60.Text = plcInfo.PlcReadonly.GroupNoAll1.ToString();
|
|
label58.Text = plcInfo.PlcReadonly.GroupNoTip1.ToString();
|
|
label56.Text = plcInfo.PlcReadonly.GroupNoPeak1.ToString();
|
|
label54.Text = plcInfo.PlcReadonly.GroupNoFlat1.ToString();
|
|
label52.Text = plcInfo.PlcReadonly.GroupNoValley1.ToString();
|
|
label70.Text = plcInfo.PlcReadonly.GroupNoAll2.ToString();
|
|
label68.Text = plcInfo.PlcReadonly.GroupNoTip2.ToString();
|
|
label66.Text = plcInfo.PlcReadonly.GroupNoPeak2.ToString();
|
|
label64.Text = plcInfo.PlcReadonly.GroupNoFlat2.ToString();
|
|
label62.Text = plcInfo.PlcReadonly.GroupNoValley2.ToString();
|
|
label80.Text = plcInfo.PlcReadonly.QuadrantNoAll1.ToString();
|
|
label78.Text = plcInfo.PlcReadonly.QuadrantNoTip1.ToString();
|
|
label76.Text = plcInfo.PlcReadonly.QuadrantNoPeak1.ToString();
|
|
label74.Text = plcInfo.PlcReadonly.QuadrantNoFlat1.ToString();
|
|
label72.Text = plcInfo.PlcReadonly.QuadrantNoValley1.ToString();
|
|
label90.Text = plcInfo.PlcReadonly.QuadrantNoAll2.ToString();
|
|
label88.Text = plcInfo.PlcReadonly.QuadrantNoTip2.ToString();
|
|
label86.Text = plcInfo.PlcReadonly.QuadrantNoPeak2.ToString();
|
|
label84.Text = plcInfo.PlcReadonly.QuadrantNoFlat2.ToString();
|
|
label82.Text = plcInfo.PlcReadonly.QuadrantNoValley2.ToString();
|
|
label100.Text = plcInfo.PlcReadonly.QuadrantNoAll3.ToString();
|
|
label98.Text = plcInfo.PlcReadonly.QuadrantNoTip3.ToString();
|
|
label96.Text = plcInfo.PlcReadonly.QuadrantNoPeak3.ToString();
|
|
label94.Text = plcInfo.PlcReadonly.QuadrantNoFlat3.ToString();
|
|
label92.Text = plcInfo.PlcReadonly.QuadrantNoValley3.ToString();
|
|
label110.Text = plcInfo.PlcReadonly.QuadrantNoAll4.ToString();
|
|
label108.Text = plcInfo.PlcReadonly.QuadrantNoTip4.ToString();
|
|
label106.Text = plcInfo.PlcReadonly.QuadrantNoPeak4.ToString();
|
|
label104.Text = plcInfo.PlcReadonly.QuadrantNoFlat4.ToString();
|
|
label102.Text = plcInfo.PlcReadonly.QuadrantNoValley4.ToString();
|
|
label120.Text = plcInfo.PlcReadonly.ForwardHaveApparentAll.ToString();
|
|
label118.Text = plcInfo.PlcReadonly.ForwardHaveApparentTip.ToString();
|
|
label116.Text = plcInfo.PlcReadonly.ForwardHaveApparentPeak.ToString();
|
|
label114.Text = plcInfo.PlcReadonly.ForwardHaveApparentFlat.ToString();
|
|
label112.Text = plcInfo.PlcReadonly.ForwardHaveApparentValley.ToString();
|
|
label130.Text = plcInfo.PlcReadonly.ReverseHaveApparentAll.ToString();
|
|
label128.Text = plcInfo.PlcReadonly.ReverseHaveApparentTip.ToString();
|
|
label126.Text = plcInfo.PlcReadonly.ReverseHaveApparentPeak.ToString();
|
|
label124.Text = plcInfo.PlcReadonly.ReverseHaveApparentFlat.ToString();
|
|
label122.Text = plcInfo.PlcReadonly.ReverseHaveApparentValley.ToString();
|
|
|
|
|
|
label140.Text = plcInfo.PlcReadonly.PhaseVoltageA.ToString();
|
|
label138.Text = plcInfo.PlcReadonly.PhaseVoltageB.ToString();
|
|
label136.Text = plcInfo.PlcReadonly.PhaseVoltageC.ToString();
|
|
label134.Text = plcInfo.PlcReadonly.PhaseElectricityA.ToString();
|
|
label132.Text = plcInfo.PlcReadonly.PhaseElectricityB.ToString();
|
|
label172.Text = plcInfo.PlcReadonly.PhaseElectricityC.ToString();
|
|
|
|
label150.Text = plcInfo.PlcReadonly.TotalActivePower.ToString();
|
|
label148.Text = plcInfo.PlcReadonly.TotalActivePowerA.ToString();
|
|
label146.Text = plcInfo.PlcReadonly.TotalActivePowerB.ToString();
|
|
label144.Text = plcInfo.PlcReadonly.TotalActivePowerC.ToString();
|
|
|
|
label160.Text = plcInfo.PlcReadonly.TotalReactivePower.ToString();
|
|
label158.Text = plcInfo.PlcReadonly.TotalReactivePowerA.ToString();
|
|
label156.Text = plcInfo.PlcReadonly.TotalReactivePowerB.ToString();
|
|
label144.Text = plcInfo.PlcReadonly.TotalReactivePowerC.ToString();
|
|
|
|
label170.Text = plcInfo.PlcReadonly.TotalApparentPower.ToString();
|
|
label168.Text = plcInfo.PlcReadonly.TotalApparentPowerA.ToString();
|
|
label166.Text = plcInfo.PlcReadonly.TotalApparentPowerB.ToString();
|
|
label164.Text = plcInfo.PlcReadonly.TotalApparentPowerC.ToString();
|
|
|
|
label192.Text = plcInfo.PlcReadonly.OverallPowerFactor.ToString();
|
|
label190.Text = plcInfo.PlcReadonly.OverallPowerFactorA.ToString();
|
|
label188.Text = plcInfo.PlcReadonly.OverallPowerFactorB.ToString();
|
|
label184.Text = plcInfo.PlcReadonly.OverallPowerFactorC.ToString();
|
|
|
|
label174.Text = plcInfo.PlcReadonly.PhaseAngleA.ToString();
|
|
label162.Text = plcInfo.PlcReadonly.PhaseAngleB.ToString();
|
|
label152.Text = plcInfo.PlcReadonly.PhaseAngleC.ToString();
|
|
label142.Text = plcInfo.PlcReadonly.LineFrequency.ToString();
|
|
|
|
label184.Text = plcInfo.PlcReadonly.PhaseLineVoltageA.ToString();
|
|
label182.Text = plcInfo.PlcReadonly.PhaseLineVoltageB.ToString();
|
|
label180.Text = plcInfo.PlcReadonly.PhaseLineVoltageC.ToString();
|
|
label178.Text = plcInfo.PlcReadonly.ThreePhaseMeanLineVoltage.ToString();
|
|
label176.Text = plcInfo.PlcReadonly.ThreePhaseMeanPhaseVoltage.ToString();
|
|
|
|
#endregion
|
|
}
|
|
if (now)
|
|
{
|
|
#region
|
|
label31.Text = plcInfo.PlcTurnsRatio.GroupHaveAll.ToString();
|
|
label29.Text = plcInfo.PlcTurnsRatio.GroupHaveTip.ToString();
|
|
label27.Text = plcInfo.PlcTurnsRatio.GroupHavePeak.ToString();
|
|
label25.Text = plcInfo.PlcTurnsRatio.GroupHaveFlat.ToString();
|
|
label19.Text = plcInfo.PlcTurnsRatio.GroupHaveValley.ToString();
|
|
label40.Text = plcInfo.PlcTurnsRatio.ForwardHaveAll.ToString();
|
|
label38.Text = plcInfo.PlcTurnsRatio.ForwardHaveTip.ToString();
|
|
label36.Text = plcInfo.PlcTurnsRatio.ForwardHavePeak.ToString();
|
|
label34.Text = plcInfo.PlcTurnsRatio.ForwardHaveFlat.ToString();
|
|
label32.Text = plcInfo.PlcTurnsRatio.ForwardHaveValley.ToString();
|
|
label50.Text = plcInfo.PlcTurnsRatio.ReverseHaveAll.ToString();
|
|
label48.Text = plcInfo.PlcTurnsRatio.ReverseHaveTip.ToString();
|
|
label46.Text = plcInfo.PlcTurnsRatio.ReverseHavePeak.ToString();
|
|
label44.Text = plcInfo.PlcTurnsRatio.ReverseHaveFlat.ToString();
|
|
label42.Text = plcInfo.PlcTurnsRatio.ReverseHaveValley.ToString();
|
|
label60.Text = plcInfo.PlcTurnsRatio.GroupNoAll1.ToString();
|
|
label58.Text = plcInfo.PlcTurnsRatio.GroupNoTip1.ToString();
|
|
label56.Text = plcInfo.PlcTurnsRatio.GroupNoPeak1.ToString();
|
|
label54.Text = plcInfo.PlcTurnsRatio.GroupNoFlat1.ToString();
|
|
label52.Text = plcInfo.PlcTurnsRatio.GroupNoValley1.ToString();
|
|
label70.Text = plcInfo.PlcTurnsRatio.GroupNoAll2.ToString();
|
|
label68.Text = plcInfo.PlcTurnsRatio.GroupNoTip2.ToString();
|
|
label66.Text = plcInfo.PlcTurnsRatio.GroupNoPeak2.ToString();
|
|
label64.Text = plcInfo.PlcTurnsRatio.GroupNoFlat2.ToString();
|
|
label62.Text = plcInfo.PlcTurnsRatio.GroupNoValley2.ToString();
|
|
label80.Text = plcInfo.PlcTurnsRatio.QuadrantNoAll1.ToString();
|
|
label78.Text = plcInfo.PlcTurnsRatio.QuadrantNoTip1.ToString();
|
|
label76.Text = plcInfo.PlcTurnsRatio.QuadrantNoPeak1.ToString();
|
|
label74.Text = plcInfo.PlcTurnsRatio.QuadrantNoFlat1.ToString();
|
|
label72.Text = plcInfo.PlcTurnsRatio.QuadrantNoValley1.ToString();
|
|
label90.Text = plcInfo.PlcTurnsRatio.QuadrantNoAll2.ToString();
|
|
label88.Text = plcInfo.PlcTurnsRatio.QuadrantNoTip2.ToString();
|
|
label86.Text = plcInfo.PlcTurnsRatio.QuadrantNoPeak2.ToString();
|
|
label84.Text = plcInfo.PlcTurnsRatio.QuadrantNoFlat2.ToString();
|
|
label82.Text = plcInfo.PlcTurnsRatio.QuadrantNoValley2.ToString();
|
|
label100.Text = plcInfo.PlcTurnsRatio.QuadrantNoAll3.ToString();
|
|
label98.Text = plcInfo.PlcTurnsRatio.QuadrantNoTip3.ToString();
|
|
label96.Text = plcInfo.PlcTurnsRatio.QuadrantNoPeak3.ToString();
|
|
label94.Text = plcInfo.PlcTurnsRatio.QuadrantNoFlat3.ToString();
|
|
label92.Text = plcInfo.PlcTurnsRatio.QuadrantNoValley3.ToString();
|
|
label110.Text = plcInfo.PlcTurnsRatio.QuadrantNoAll4.ToString();
|
|
label108.Text = plcInfo.PlcTurnsRatio.QuadrantNoTip4.ToString();
|
|
label106.Text = plcInfo.PlcTurnsRatio.QuadrantNoPeak4.ToString();
|
|
label104.Text = plcInfo.PlcTurnsRatio.QuadrantNoFlat4.ToString();
|
|
label102.Text = plcInfo.PlcTurnsRatio.QuadrantNoValley4.ToString();
|
|
label120.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentAll.ToString();
|
|
label118.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentTip.ToString();
|
|
label116.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentPeak.ToString();
|
|
label114.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentFlat.ToString();
|
|
label112.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentValley.ToString();
|
|
label130.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentAll.ToString();
|
|
label128.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentTip.ToString();
|
|
label126.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentPeak.ToString();
|
|
label124.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentFlat.ToString();
|
|
label122.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentValley.ToString();
|
|
#endregion
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 方法
|
|
|
|
#endregion 写入方法
|
|
|
|
|
|
private void BtnWrite01_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox1.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if(plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult=session.Write<UInt16>(PlcDate.ProgrammingEnable);
|
|
|
|
}
|
|
|
|
private void BtnWrite02_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox2.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Modbus1Addres);
|
|
}
|
|
|
|
private void BtnWrite03_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox3.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.BaudRate);
|
|
}
|
|
|
|
private void BtnWrite04_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox4.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.CheckBit);
|
|
}
|
|
|
|
private void BtnWrite05_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox5.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Seconds);
|
|
}
|
|
|
|
private void BtnWrite06_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox6.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Points);
|
|
}
|
|
|
|
private void BtnWrite07_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox7.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.When);
|
|
}
|
|
|
|
private void BtnWrite08_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox8.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Weeks);
|
|
}
|
|
|
|
private void BtnWrite09_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox9.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Day);
|
|
}
|
|
|
|
private void BtnWrite10_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox10.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Month);
|
|
}
|
|
|
|
private void BtnWrite11_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox11.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Years);
|
|
}
|
|
|
|
private void BtnWrite12_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox12.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Modbus1Addres2);
|
|
}
|
|
|
|
private void BtnWrite13_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox13.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.Reserve);
|
|
}
|
|
|
|
private void BtnWrite14_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox14.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.VoltageRatio);
|
|
}
|
|
|
|
private void BtnWrite15_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox15.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.CurrentRatio);
|
|
}
|
|
|
|
private void BtnWrite16_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox16.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.PulsePerSecond);
|
|
}
|
|
|
|
private void BtnWrite17_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox15.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.CurrentReversal);
|
|
}
|
|
|
|
private void BtnWrite18_Click(object sender, EventArgs e)
|
|
{
|
|
bool bConvert = int.TryParse(this.textBox16.Text, out int iValue);
|
|
if (!bConvert)
|
|
{
|
|
MessageBox.Show("请输入有效值");
|
|
return;
|
|
}
|
|
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
|
|
if (plcInfo == null)
|
|
{
|
|
MessageBox.Show("PLC未连接");
|
|
return;
|
|
}
|
|
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
|
|
bool bResult = session.Write<UInt16>(PlcDate.MeterReset);
|
|
}
|
|
|
|
#region 进制数据转换
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|