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.

578 lines
18 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 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);
}
#region 协议格式
/// <summary>
/// (CMD=1)后台服务器下发充电桩整形工作参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button14_Click(object sender, EventArgs e)
{
byte type = 0;
uint startAddress = 2;
byte num = 3;
byte[] setData = null;
CmnChargerParam._CHR00TCPCLIENT.Send1(type, startAddress, num, setData);
}
/// <summary>
/// (CMD=3)后台服务器下发充电桩字符型参数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button15_Click(object sender, EventArgs e)
{
byte type = 0;
uint startAddress = 1;
byte[] setData = null;
CmnChargerParam._CHR00TCPCLIENT.Send3(type, startAddress, setData);
}
/// <summary>
/// (CMD=5)后台服务器下发充电桩控制命令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button16_Click(object sender, EventArgs e)
{
byte type = 0;
uint startAddress = 9;
byte num = 10;
byte[] setData = null;
CmnChargerParam._CHR00TCPCLIENT.Send5(type, startAddress, num, setData);
}
#endregion
#region 充电信息数据
/// <summary>
/// 201/221
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button13_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send201();
}
/// <summary>
/// 203
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button25_Click(object sender, EventArgs e)
{
//CmnChargerParam._CHR00TCPCLIENT.Send203();
}
/// <summary>
/// 205
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button11_Click(object sender, EventArgs e)
{
uint value03 = 0; uint value04 = 0;
CmnChargerParam._CHR00TCPCLIENT.Send205(value03, value04);
}
/// <summary>
/// 207
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button31_Click(object sender, EventArgs e)
{
// CmnChargerParam._CHR00TCPCLIENT.Send207();
}
/// <summary>
/// 209
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button32_Click(object sender, EventArgs e)
{
CMD210 CMD210 = new CMD210();
string value05 = ";";
CmnChargerParam._CHR00TCPCLIENT.Send209(CMD210, value05);
}
#endregion
#region 直流充电桩 BMS 信息数据(预留)
/// <summary>
/// 301
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button33_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send301();
}
/// <summary>
/// 303
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button34_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send303();
}
#endregion
#region 历史记录
/// <summary>
/// 401
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button36_Click(object sender, EventArgs e)
{
string chargingSerialNum = ""; uint startIndex = 0;
CmnChargerParam._CHR00TCPCLIENT.Send401(chargingSerialNum, startIndex);
}
#endregion
#region 升级命令
/// <summary>
/// 1001
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button38_Click(object sender, EventArgs e)
{
int instruct = 0;
CmnChargerParam._CHR00TCPCLIENT.Send1001(instruct);
}
/// <summary>
/// 1003
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button39_Click(object sender, EventArgs e)
{
string fileName = "";
CmnChargerParam._CHR00TCPCLIENT.Send1003(fileName);
}
/// <summary>
/// 1005
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button37_Click(object sender, EventArgs e)
{
uint fileLen = 0;
CmnChargerParam._CHR00TCPCLIENT.Send1005(fileLen);
}
/// <summary>
/// 1007
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button40_Click(object sender, EventArgs e)
{
string updata = "";
CmnChargerParam._CHR00TCPCLIENT.Send1007(updata);
}
/// <summary>
/// 1009
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button35_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send1009();
}
/// <summary>
/// 1011
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button41_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send1011();
}
/// <summary>
/// 1021
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button42_Click(object sender, EventArgs e)
{
uint results = 0; string description = "";
CmnChargerParam._CHR00TCPCLIENT.Send1021(results, description);
}
#endregion
#region 与计费策略相关的指令
/// <summary>
/// 1101
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send1101();
}
/// <summary>
/// 1103
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
CMD1103 cMD1103 = new CMD1103();
CmnChargerParam._CHR00TCPCLIENT.Send1103(cMD1103);
}
/// <summary>
/// 1105
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
CMD1105 cMD1105 = new CMD1105();
CmnChargerParam._CHR00TCPCLIENT.Send1105(cMD1105);
}
/// <summary>
/// 1107
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send1107();
}
#endregion
#region 白名单报文
/// <summary>
/// 1301
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button5_Click(object sender, EventArgs e)
{
CMD1301 cMD1301 = new CMD1301();
CmnChargerParam._CHR00TCPCLIENT.Send1301(cMD1301);
}
#endregion
#region FTP 远程升级和 FTP 方式日志上传
/// <summary>
/// 1401
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button6_Click(object sender, EventArgs e)
{
CMD1401 cMD1401 = new CMD1401();
CmnChargerParam._CHR00TCPCLIENT.Send1401(cMD1401);
}
/// <summary>
/// 1406
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button7_Click(object sender, EventArgs e)
{
CMD1406 cMD1406 = new CMD1406();
CmnChargerParam._CHR00TCPCLIENT.Send1406(cMD1406);
}
#endregion
#region 协议方式日志上传
/// <summary>
/// 1502
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button8_Click(object sender, EventArgs e)
{
ushort responseCode = 0;
CmnChargerParam._CHR00TCPCLIENT.Send1502(responseCode);
}
/// <summary>
/// 1504
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button9_Click(object sender, EventArgs e)
{
uint logo = 0;
uint successReservedMessageNum = 0;
CmnChargerParam._CHR00TCPCLIENT.Send1504(logo, successReservedMessageNum);
}
/// <summary>
/// 1506
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button10_Click(object sender, EventArgs e)
{
CmnChargerParam._CHR00TCPCLIENT.Send1506();
}
#endregion
private void button12_Click(object sender, EventArgs e)
{
CMD7 CMD = new CMD7();
CMD.value01 = 0;
CMD.value02 = 0;
CMD.value03 = 1;
CMD.value04 = 2;
CMD.value05 = 3;
CMD.value06 = 4;
CMD.value07 = 5;
CMD.value08 = 6;
CMD.value09 = 7;
CMD.value10 = 8;
CMD.value11 = 9;
CMD.value12 = 10;
CMD.value13 = "12345678";
CMD.value14 = 11;
CMD.value15 = 12;
CMD.value16 = 13;
CmnChargerParam._CHR00TCPCLIENT.Send7(CMD);
}
}
}