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.

147 lines
3.9 KiB

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();
}
/// <summary>
/// 窗体初始化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmRwEMeterResult_Load(object sender, EventArgs e)
{
//委托展示参数实时值
DlgParamRealValue = new PrintParamValueCallBack(PrintParamRealValue);
//开始显示实时值线程
Thread printRealValueThread = new Thread(StartPrintParamRealValue);
printRealValueThread.IsBackground = true;
printRealValueThread.Start();
}
/// <summary>
/// 开始显示实时值线程
/// </summary>
private void StartPrintParamRealValue()
{
while (IsPrintReadValue)
{
if (this.IsHandleCreated)
{
this.BeginInvoke(DlgParamRealValue, null);
}
Thread.Sleep(100);
}
}
/// <summary>
/// 展示参数实时值
/// </summary>
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();
}
}
/// <summary>
/// 连接电表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnConnect_Click(object sender, EventArgs e)
{
new ElecMeterEqmManger().ElecMeterNetConnectThread();
}
/// <summary>
/// 窗体关闭按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
/// <summary>
/// 电表断开
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnDisconnect_Click(object sender, EventArgs e)
{
}
/// <summary>
/// 数据测试
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}