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 System.Threading; using Monitor.Models; using DataBase.MySql.Tool; using Module.EMeter.ModbusTcp; using Monitor.LogService; namespace Monitor.ModbusTcpEMeterTest { public partial class FrmElecMeterResult : Form { private delegate void PrintParamValueCallBack(); //委托事件 private PrintParamValueCallBack DlgParamRealValue; private bool IsPrintReadValue = true; public FrmElecMeterResult() { InitializeComponent(); } /// /// 窗体初始化 /// /// /// private void FrmRwEMeterResult_Load(object sender, EventArgs e) { //委托展示参数实时值 DlgParamRealValue = new PrintParamValueCallBack(PrintParamRealValue); //开始显示实时值线程 Thread printRealValueThread = new Thread(StartPrintParamRealValue); printRealValueThread.IsBackground = true; printRealValueThread.Start(); } /// /// 开始显示实时值线程 /// private void StartPrintParamRealValue() { while (IsPrintReadValue) { if (this.IsHandleCreated) { this.BeginInvoke(DlgParamRealValue, null); } Thread.Sleep(100); } } /// /// 展示参数实时值 /// private void PrintParamRealValue() { try { txtEnergy03.Text = CmnElecMeterBaseInfo.EBC01.F_TotalActiveEnergy.ToString(); txtEnergy04.Text = CmnElecMeterBaseInfo.EBC02.F_TotalActiveEnergy.ToString(); txtEnergy05.Text = CmnElecMeterBaseInfo.EBC03.F_TotalActiveEnergy.ToString(); } catch(Exception ex) { ex.ToString(); } } /// /// 连接电表 /// /// /// private void BtnConnect_Click(object sender, EventArgs e) { new ElecMeterEqmManger().ElecMeterNetConnectThread(); } /// /// 窗体关闭按钮 /// /// /// private void BtnClose_Click(object sender, EventArgs e) { Application.Exit(); } /// /// 电表断开 /// /// /// private void BtnDisconnect_Click(object sender, EventArgs e) { } /// /// 数据测试 /// /// /// private async void BtnDataTest_Click(object sender, EventArgs e) { //TEgEmeterHourEnergyValue val = new TEgEmeterHourEnergyValue() //{ // FEmeterNo = "M001", // FHourValue = 458.32f, // FStartTime = DateTime.Now, // FEndTime = DateTime.Now //}; //await new SEgEMeterHourEnergyValue().AddEMeterHourEnergyValue(val); TEgEmeterTotalEnergyValue val = new TEgEmeterTotalEnergyValue() { FEmeterNo = "M001", FTotalValue = 3258.26f, FTime = DateTime.Now }; await new SEgEMeterTotalEnergyValue().AddEMeterTotalEnergyValue(val); } } }