using HslCommunication.ModBus; using HslCommunication; 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; using HybirdFrameworkDriver.ModbusTcpMaster; using HybirdFrameworkServices.Plc; using HybirdFrameworkDriver.TcpServer; using Newtonsoft.Json.Linq; using Service.Init.Entity; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace WinFormStarter { public partial class FrmPlc : Form { public FrmPlc() { InitializeComponent(); } ModbusTcpNet ModbusTcpNet; int heart = 0; private void BtnWrite01_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue04.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.CommunicationDiagnosis.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.CommunicationDiagnosis); } private void BtnWrite02_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue05.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.ModeControl.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.ModeControl); } private void BtnWrite03_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue06.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.EquipmentControl.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.EquipmentControl); } private void BtnWrite04_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue07.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.ExhaustFanControl.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.ExhaustFanControl); } private void BtnWrite05_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue08.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.LightingControl.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.LightingControl); } private void BtnWrite06_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue09.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.Seconds.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.Seconds); } private void BtnWrite07_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue10.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.Points.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.Points); } private void BtnWrite08_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue11.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.Hour.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.Hour); } private void BtnWrite09_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue12.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.Day.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.Day); } private void BtnWrite10_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue13.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.Month.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.Month); } private void BtnWrite11_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue14.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.Years.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.Years); } /// /// 车辆驻车位置 /// /// /// private void BtnWrite14_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue15.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.VehicleParkingLocation.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.VehicleParkingLocation); } private void BtnWrite15_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue16.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.VehicleParkingStatus.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.VehicleParkingStatus); } /// /// 三色灯 /// /// /// private void BtnWrite16_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue17.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.LightIn.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.LightIn); } private void BtnWrite17_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue16.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.LightOut.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.LightOut); } /// /// 锁止异常 /// /// /// private void BtnWrite18_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue19.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.StopCommand.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.StopCommand); } private void button3_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue20.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.TaskType.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.TaskType); } /// /// 入仓仓位选择 /// /// /// private void button2_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue21.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.EntrySelection.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.EntrySelection); } private void button1_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue22.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.ExitSelection.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.ExitSelection); } private void button5_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue23.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.BatteryPackType.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.BatteryPackType); } private void button4_Click(object sender, EventArgs e) { bool bConvert = ushort.TryParse(this.txtValue24.Text, out ushort iValue); if (!bConvert) { MessageBox.Show("请输入有效值"); return; } ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo); if (plcInfo == null) { MessageBox.Show("PLC未连接"); return; } plcInfo.hostToPlc.TaskEnablement.Value = iValue; bool bResult = plcInfo.WriteUint16(plcInfo.hostToPlc.TaskEnablement); } private void button6_Click(object sender, EventArgs e) { bool bConvert1 = short.TryParse(this.txtValue01.Text, out short iValue1); bool bConvert2 = short.TryParse(this.txtValue02.Text, out short iValue2); bool bConvert3 = short.TryParse(this.txtValue03.Text, out short iValue3); ChargerStaticInfo.PlcInfos.TryGetValue(3, out PlcInfo plcInfo); if (plcInfo != null) { HostToPlc hostToPlc = new HostToPlc(); hostToPlc.ProtocolVersion1.Value = iValue1; hostToPlc.ProtocolVersion2.Value = iValue2; hostToPlc.ProtocolVersion3.Value = iValue3; plcInfo.Writeint16(hostToPlc.ProtocolVersion1); plcInfo.Writeint16(hostToPlc.ProtocolVersion2); plcInfo.Writeint16(hostToPlc.ProtocolVersion3); } } /// /// 把采集值显示上来 /// /// /// private void BtnCollectionAssignment_Click(object sender, EventArgs e) { ChargerStaticInfo.PlcInfos.TryGetValue(3, out PlcInfo plcInfo); if (plcInfo != null) { lblValue01.Text = plcInfo.plcToHost.ProtocolVersion1.Value + "." + plcInfo.plcToHost.ProtocolVersion2.Value + "." + plcInfo.plcToHost.ProtocolVersion3.Value; lblValue02.Text = plcInfo.plcToHost.CommunicationDiagnosis.Value.ToString(); lblValue03.Text = plcInfo.plcToHost.ModeControl.Value.ToString(); lblValue04.Text = plcInfo.plcToHost.DeviceSystemStatus.Value.ToString(); lblValue05.Text = plcInfo.plcToHost.RemoteLocalControlState.Value.ToString(); lblValue06.Text = plcInfo.plcToHost.LightStatus.Value.ToString(); lblValue07.Text = plcInfo.plcToHost.ExhaustFanStatus.Value.ToString(); lblValue08.Text = plcInfo.plcToHost.WaterStatusStation.Value.ToString(); lblValue09.Text = plcInfo.plcToHost.InPosition.Value.ToString(); lblValue10.Text = plcInfo.plcToHost.CarStatus.Value.ToString(); lblValue11.Text = plcInfo.plcToHost.PercentageTorqueX.Value.ToString(); lblValue12.Text = plcInfo.plcToHost.PercentageTorqueY.Value.ToString(); lblValue13.Text = plcInfo.plcToHost.PercentageTorqueZ.Value.ToString(); lblValue14.Text = plcInfo.plcToHost.RadarStatesIn.Value.ToString(); lblValue15.Text = plcInfo.plcToHost.RadarStatesOut.Value.ToString(); lblValue16.Text = plcInfo.plcToHost.SpotPhotoelectricSignal.Value.ToString(); lblValue17.Text = plcInfo.plcToHost.PhysicalButtonState.Value.ToString(); lblValue18.Text = plcInfo.plcToHost.LightIn.Value.ToString(); lblValue19.Text = plcInfo.plcToHost.LightOut.Value.ToString(); lblValue20.Text = plcInfo.plcToHost.TaskType.Value.ToString(); lblValue21.Text = plcInfo.plcToHost.TaskStates.Value.ToString(); lblValue22.Text = plcInfo.plcToHost.OperationalTrainNumber.Value.ToString(); lblValue23.Text = plcInfo.plcToHost.ChannelLocationState.Value.ToString(); lblValue24.Text = plcInfo.plcToHost.DeviationX.Value.ToString(); lblValue25.Text = plcInfo.plcToHost.DeviationY.Value.ToString(); lblValue26.Text = plcInfo.plcToHost.DeviationZ.Value.ToString(); txtValue01.Text = plcInfo.hostToPlc.ProtocolVersion1.Value.ToString(); txtValue02.Text = plcInfo.hostToPlc.ProtocolVersion2.Value.ToString(); txtValue03.Text = plcInfo.hostToPlc.ProtocolVersion3.Value.ToString(); txtValue04.Text = plcInfo.hostToPlc.CommunicationDiagnosis.Value.ToString(); txtValue05.Text = plcInfo.hostToPlc.ModeControl.Value.ToString(); txtValue06.Text = plcInfo.hostToPlc.EquipmentControl.Value.ToString(); txtValue07.Text = plcInfo.hostToPlc.ExhaustFanControl.Value.ToString(); txtValue08.Text = plcInfo.hostToPlc.LightingControl.Value.ToString(); txtValue09.Text = plcInfo.hostToPlc.Seconds.Value.ToString(); txtValue10.Text = plcInfo.hostToPlc.Points.Value.ToString(); txtValue11.Text = plcInfo.hostToPlc.Hour.Value.ToString(); txtValue12.Text = plcInfo.hostToPlc.Day.Value.ToString(); txtValue13.Text = plcInfo.hostToPlc.Month.Value.ToString(); txtValue14.Text = plcInfo.hostToPlc.Years.Value.ToString(); txtValue15.Text = plcInfo.hostToPlc.VehicleParkingLocation.Value.ToString(); txtValue16.Text = plcInfo.hostToPlc.VehicleParkingStatus.Value.ToString(); txtValue17.Text = plcInfo.hostToPlc.LightIn.Value.ToString(); txtValue18.Text = plcInfo.hostToPlc.LightOut.Value.ToString(); txtValue19.Text = plcInfo.hostToPlc.StopCommand.Value.ToString(); txtValue20.Text = plcInfo.hostToPlc.TaskType.Value.ToString(); txtValue21.Text = plcInfo.hostToPlc.EntrySelection.Value.ToString(); txtValue22.Text = plcInfo.hostToPlc.ExitSelection.Value.ToString(); txtValue23.Text = plcInfo.hostToPlc.BatteryPackType.Value.ToString(); txtValue24.Text = plcInfo.hostToPlc.TaskEnablement.Value.ToString(); textBox1.Text = plcInfo.hostToPlc.ChargingStatus01.Value.ToString(); textBox2.Text = plcInfo.hostToPlc.ChargingStatus02.Value.ToString(); textBox3.Text = plcInfo.hostToPlc.ChargingStatus03.Value.ToString(); textBox4.Text = plcInfo.hostToPlc.ChargingStatus04.Value.ToString(); textBox5.Text = plcInfo.hostToPlc.ChargingStatus05.Value.ToString(); textBox6.Text = plcInfo.hostToPlc.ChargingStatus06.Value.ToString(); textBox7.Text = plcInfo.hostToPlc.ChargingStatus07.Value.ToString(); textBox8.Text = plcInfo.hostToPlc.ChargingStatus08.Value.ToString(); textBox9.Text = plcInfo.hostToPlc.ChargingStatus09.Value.ToString(); textBox10.Text = plcInfo.hostToPlc.ChargingStatus10.Value.ToString(); textBox11.Text = plcInfo.hostToPlc.ChargingStatus11.Value.ToString(); textBox12.Text = plcInfo.hostToPlc.ChargingStatus12.Value.ToString(); textBox13.Text = plcInfo.hostToPlc.ChargingStatus13.Value.ToString(); textBox14.Text = plcInfo.hostToPlc.ChargingStatus14.Value.ToString(); textBox15.Text = plcInfo.hostToPlc.ChargingStatus15.Value.ToString(); textBox16.Text = plcInfo.hostToPlc.ChargingStatus16.Value.ToString(); textBox17.Text = plcInfo.hostToPlc.ChargingStatus17.Value.ToString(); textBox18.Text = plcInfo.hostToPlc.ChargingStatus18.Value.ToString(); textBox19.Text = plcInfo.hostToPlc.ChargingStatus19.Value.ToString(); textBox20.Text = plcInfo.hostToPlc.ChargingStatus20.Value.ToString(); textBox21.Text = plcInfo.hostToPlc.BatteryType01.Value.ToString(); textBox22.Text = plcInfo.hostToPlc.BatteryType02.Value.ToString(); textBox23.Text = plcInfo.hostToPlc.BatteryType03.Value.ToString(); textBox24.Text = plcInfo.hostToPlc.BatteryType04.Value.ToString(); textBox25.Text = plcInfo.hostToPlc.BatteryType05.Value.ToString(); textBox26.Text = plcInfo.hostToPlc.BatteryType06.Value.ToString(); textBox27.Text = plcInfo.hostToPlc.BatteryType07.Value.ToString(); textBox28.Text = plcInfo.hostToPlc.BatteryType08.Value.ToString(); textBox29.Text = plcInfo.hostToPlc.BatteryType09.Value.ToString(); textBox30.Text = plcInfo.hostToPlc.BatteryType10.Value.ToString(); textBox31.Text = plcInfo.hostToPlc.BatteryType11.Value.ToString(); textBox32.Text = plcInfo.hostToPlc.BatteryType12.Value.ToString(); textBox33.Text = plcInfo.hostToPlc.BatteryType13.Value.ToString(); textBox34.Text = plcInfo.hostToPlc.BatteryType14.Value.ToString(); textBox35.Text = plcInfo.hostToPlc.BatteryType15.Value.ToString(); textBox36.Text = plcInfo.hostToPlc.BatteryType16.Value.ToString(); textBox37.Text = plcInfo.hostToPlc.BatteryType17.Value.ToString(); textBox38.Text = plcInfo.hostToPlc.BatteryType18.Value.ToString(); textBox39.Text = plcInfo.hostToPlc.BatteryType19.Value.ToString(); textBox40.Text = plcInfo.hostToPlc.BatteryType20.Value.ToString(); } } } }