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.

653 lines
21 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 BatCharging.Model;
using BatCharging.Service;
using Monitor.LogService;
using Newtonsoft.Json;
namespace Monitor.ChargeTest
{
public partial class FrmChargeResult : Form
{
#region 处理结果消息委托
//ListBox文本框类型委托
private delegate void SetListBoxCallBack(string str);
private SetListBoxCallBack MsgConnectLogCallBack; //服务端或客户端连接状态信息委托
//RichTextBox文本框类型委托
private delegate void SetRTxtCallBack(string str);
private SetRTxtCallBack RTxtSendFramesInfoCallBack; //客户端发送数据帧委托
private SetRTxtCallBack RTxtRecvFramesInfoCallBack; //客户端接收数据帧委托
#endregion 处理结果消息委托
public FrmChargeResult()
{
InitializeComponent();
MsgConnectLogCallBack = new SetListBoxCallBack(PrintConnectLogMsg);
RTxtSendFramesInfoCallBack = new SetRTxtCallBack(PrintSendFramesInfo);
RTxtRecvFramesInfoCallBack = new SetRTxtCallBack(PrintRecvFramesInfo);
}
/// <summary>
/// 窗体加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmRwTcpCanResult_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 字节数组转16进制字符串空格分隔
/// </summary>
/// <param name="byteDatas"></param>
/// <returns></returns>
public string BytesToHexStr(byte[] byteDatas)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < byteDatas.Length; i++)
{
builder.Append(string.Format("{0:X2} ", byteDatas[i]));
}
return builder.ToString().Trim();
}
#region 委托事件方法
/// <summary>
/// 连接状态日志
/// </summary>
/// <param name="message"></param>
private void PrintConnectLogMsg(string message)
{
if (lstBoxConnect.Items.Count <= 12)
{
lstBoxConnect.Items.Add(message);
lstBoxConnect.SelectedIndex = lstBoxConnect.Items.Count - 1;
lstBoxConnect.ClearSelected();
}
else
{
lstBoxConnect.Items.Clear();
lstBoxConnect.Items.Add(message);
lstBoxConnect.SelectedIndex = lstBoxConnect.Items.Count - 1;
lstBoxConnect.ClearSelected();
}
}
/// <summary>
/// 显示发送的数据帧信息
/// </summary>
/// <param name="msg">发送的数据帧信息</param>
private void PrintSendFramesInfo(string msg)
{
if (lstSendFrameInfo.Items.Count <= 12)
{
lstSendFrameInfo.Items.Add(msg);
lstSendFrameInfo.SelectedIndex = lstSendFrameInfo.Items.Count - 1;
lstSendFrameInfo.ClearSelected();
}
else
{
lstSendFrameInfo.Items.Clear();
lstSendFrameInfo.Items.Add(msg);
lstSendFrameInfo.SelectedIndex = lstSendFrameInfo.Items.Count - 1;
lstSendFrameInfo.ClearSelected();
}
}
/// <summary>
/// 显示接收到的数据帧信息
/// </summary>
/// <param name="msg">接收到的数据帧信息</param>
private void PrintRecvFramesInfo(string msg)
{
if (lstRecvFrameInfo.Items.Count <= 12)
{
lstRecvFrameInfo.Items.Add(msg);
lstRecvFrameInfo.SelectedIndex = lstRecvFrameInfo.Items.Count - 1;
lstSendFrameInfo.ClearSelected();
}
else
{
lstRecvFrameInfo.Items.Clear();
lstRecvFrameInfo.Items.Add(msg);
lstRecvFrameInfo.SelectedIndex = lstRecvFrameInfo.Items.Count - 1;
lstRecvFrameInfo.ClearSelected();
}
}
#endregion 委托事件方法
/// <summary>
/// 设置textbox文本
/// </summary>
/// <param name="tb"></param>
/// <param name="text"></param>
private static void SetTextBoxSafe(TextBox tb, string text)
{
if (tb.InvokeRequired)
tb.Invoke(new Action(() => tb.Text = text));
else
tb.Text = text;
}
/// <summary>
/// 客户端关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnNetClose_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.ChargerDisConnect();
}
/// <summary>
/// 充电机网络连接
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnChrg01Connect_Click(object sender, EventArgs e)
{
string strIp = txtChargeIp.Text.Trim();
int iPort = Convert.ToInt32(txtChargePort.Text.Trim());
int destaddr = Convert.ToInt32(txtDestAddr.Text.Trim());
CmnChargerParam._CHR00TCPCLIENT.ConnectedStatusChanged += ChargerMgrTool_ConnectedStatusChanged;
CmnChargerParam._CHR00TCPCLIENT.ChargerConnect(strIp, iPort, destaddr);
CmnChargerParam._CHR00TCPCLIENT.DataSended += ChargerMgrTool_DataSended;
CmnChargerParam._CHR00TCPCLIENT.DataReceived += ChargerMgrTool_DataReceived;
}
/// <summary>
/// 充电机断开连接
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnCloseConnect_Click(object sender, EventArgs e)
{
if (CmnChargerParam._CHR00TCPCLIENT != null)
{
if (CmnChargerParam._CHR00TCPCLIENT.F_NetConnected)
{
CmnChargerParam._CHR00TCPCLIENT.ChargerDisConnect();
}
}
}
/// <summary>
/// 数据接收解析
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ChargerMgrTool_DataReceived(object sender, DataRecvedEventArgs e)
{
string result = "";
byte[] data = e.Data;
if (data != null)
{
result += "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "]" + "RECV HEX:";
result += BytesToHexStr(data);
lstRecvFrameInfo.Invoke(RTxtRecvFramesInfoCallBack, result);
}
}
/// <summary>
/// 数据发送
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ChargerMgrTool_DataSended(object sender, DataSendedEventArgs e)
{
string result = "";
byte[] data = e.Data;
if (data != null)
{
result += "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "]" + "SEND HEX:";
result += BytesToHexStr(data);
lstSendFrameInfo.Invoke(RTxtSendFramesInfoCallBack, result);
}
}
/// <summary>
/// 连接状态改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ChargerMgrTool_ConnectedStatusChanged(object sender, LogEventArgs e)
{
lstBoxConnect.Invoke(MsgConnectLogCallBack, e.IsContent);
}
private void FrmChargeResult_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 获取充电机尖峰平谷对象值
/// </summary>
/// <returns></returns>
private SharpPeakTimeRangeIde GetSharpPeakTimeRange()
{
SharpPeakTimeRangeIde timeRng = new SharpPeakTimeRangeIde();
timeRng.RecordType = 47;
timeRng.NumTimePeriods = 24;
timeRng.StartTimePeriod1 = "00:00";
timeRng.TimePeriodPeakIden1 = 4;
timeRng.StartTimePeriod2 = "08:00";
timeRng.TimePeriodPeakIden2 = 3;
timeRng.StartTimePeriod3 = "15:00";
timeRng.TimePeriodPeakIden3 = 2;
timeRng.StartTimePeriod4 = "19:00";
timeRng.TimePeriodPeakIden4 = 1;
timeRng.StartTimePeriod5 = "22:00";
timeRng.TimePeriodPeakIden5 = 2;
timeRng.StartTimePeriod6 = "23:00";
timeRng.TimePeriodPeakIden6 = 3;
timeRng.StartTimePeriod7 = "00:00";
timeRng.TimePeriodPeakIden7 = 4;
timeRng.StartTimePeriod8 = "00:00";
timeRng.TimePeriodPeakIden8 = 3;
timeRng.StartTimePeriod9 = "00:00";
timeRng.TimePeriodPeakIden9 = 2;
timeRng.StartTimePeriod10 = "00:00";
timeRng.TimePeriodPeakIden10 = 1;
timeRng.StartTimePeriod11 = "00:00";
timeRng.TimePeriodPeakIden11 = 2;
timeRng.StartTimePeriod12 = "00:00";
timeRng.TimePeriodPeakIden12 = 3;
timeRng.StartTimePeriod13 = "00:00";
timeRng.TimePeriodPeakIden13 = 4;
timeRng.StartTimePeriod14 = "00:00";
timeRng.TimePeriodPeakIden14 = 3;
timeRng.StartTimePeriod15 = "00:00";
timeRng.TimePeriodPeakIden15 = 2;
timeRng.StartTimePeriod16 = "00:00";
timeRng.TimePeriodPeakIden16 = 1;
timeRng.StartTimePeriod17 = "00:00";
timeRng.TimePeriodPeakIden17 = 2;
timeRng.StartTimePeriod18 = "00:00";
timeRng.TimePeriodPeakIden18 = 3;
timeRng.StartTimePeriod19 = "00:00";
timeRng.TimePeriodPeakIden19 = 4;
timeRng.StartTimePeriod20 = "00:00";
timeRng.TimePeriodPeakIden20 = 3;
timeRng.StartTimePeriod21 = "00:00";
timeRng.TimePeriodPeakIden21 = 2;
timeRng.StartTimePeriod22 = "00:00";
timeRng.TimePeriodPeakIden22 = 1;
timeRng.StartTimePeriod23 = "00:00";
timeRng.TimePeriodPeakIden23 = 2;
timeRng.StartTimePeriod24 = "00:00";
timeRng.TimePeriodPeakIden24 = 3;
return timeRng;
}
/// <summary>
/// 设置充电机尖峰平谷
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnChrg01SharpPeak_Click(object sender, EventArgs e)
{
SharpPeakTimeRangeIde timeRng = GetSharpPeakTimeRange();
CmnChargerParam._CHR00TCPCLIENT.SendPeakTimePeriod(timeRng);
}
/// <summary>
/// 开启充电
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnChrg01Start_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendRemoteStartCharing(100, 1, 3600, 0);
}
/// <summary>
/// 充电机停止充电
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnChrg01Stop_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.F_StopReason = 0;
CmnChargerParam._CHR00TCPCLIENT.F_IsCanSendStopCmd = true;
CmnChargerParam._CHR00TCPCLIENT.SendRemoteStopCmdThread();
}
/// <summary>
/// 充电机鉴权
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnChrg01SignIn_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendCharingSignIn();
}
/// <summary>
/// 监控平台应答充电启动完成帧
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendStartChargingFinishedRes(0, 0);
}
/// <summary>
/// 监控平台应答充电停止完成帧
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendStopChargingFinishedRes(0);
}
/// <summary>
/// 监控平台应答充电设备登录签到报文
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendCharingLoginRes();
}
/// <summary>
/// 发送功率调节指令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button6_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendPowerRegulate(30);
}
/// <summary>
/// 下发辅源控制指令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button7_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendAuxiliaryPowerControl(0);
}
/// <summary>
/// 下发掉线停止充电
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button8_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendDisconnectStopCharge(1, 0);
}
/// <summary>
/// 下发站外允许充电SOC
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button9_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendOutsideAllowChargeSOC(1);
}
/// <summary>
/// 监控平台下发版本号查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button5_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendVersionNumber();
}
/// <summary>
/// 主动上送充电记录响应
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button10_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendRecordChargResp(0, 0);
}
/// <summary>
/// 监控平台心跳应答
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button11_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendCharingHeartRes();
}
/// <summary>
/// 站控查询监控网关尖峰平谷设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button13_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendQueryPeakTime(0);
}
/// <summary>
/// 站控响应充放电机上报模块状态
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.SendUpModelStationResp(0);
}
#region 协议格式
/// <summary>
/// (CMD=1)后台服务器下发充电桩整形工作参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button14_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send1();
}
/// <summary>
/// (CMD=3)后台服务器下发充电桩字符型参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button15_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send3();
}
/// <summary>
/// (CMD=5)后台服务器下发充电桩控制命令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button16_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send5();
}
/// <summary>
/// (CMD=7)后台服务器下发充电桩开启充电控制命令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button17_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send7();
}
/// <summary>
/// (CMD=9)后台服务器应答桩上传命令请求(预留)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button18_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send9();
}
#endregion
#region 充电桩主动上传数据
/// <summary>
/// (CMD=101)服务器应答心跳包信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button20_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send101();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button21_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send103();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button19_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send105();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button22_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send107();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button23_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send109();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button24_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send111();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button26_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send113();
}
#endregion
#region 充电信息数据
private void button27_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send201();
}
private void button12_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send203();
}
private void button28_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send205();
}
private void button29_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send207();
}
private void button30_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send209();
}
#endregion
#region 直流充电桩 BMS 信息数据(预留)
#endregion
#region 历史记录
#endregion
#region 升级命令
#endregion
#region 与计费策略相关的指令
#endregion
#region 白名单报文
#endregion
#region FTP 远程升级和 FTP 方式日志上传
#endregion
#region 协议方式日志上传
#endregion
}
}