107 lines
2.6 KiB
C#
107 lines
2.6 KiB
C#
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;
|
|
|
|
namespace CanTool
|
|
{
|
|
public partial class MessageConfigForm : Form
|
|
{
|
|
public Action<UInt32, byte[], int> MessageReturn;
|
|
|
|
public MessageConfigForm()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.MessageReturn = null;
|
|
}
|
|
|
|
public MessageConfigForm(UInt32 id, byte[] data, int len)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.MessageReturn = null;
|
|
|
|
TextBox[] txtBoxTable = new TextBox[]
|
|
{
|
|
txtMessageData0,
|
|
txtMessageData1,
|
|
txtMessageData2,
|
|
txtMessageData3,
|
|
txtMessageData4,
|
|
txtMessageData5,
|
|
txtMessageData6,
|
|
txtMessageData7,
|
|
};
|
|
|
|
txtMessageId.Text = Convert.ToString(id, 16);
|
|
txtMessageLen.Text = Convert.ToString(len);
|
|
|
|
for(int i = 0;i < txtBoxTable.Length;i++)
|
|
{
|
|
txtBoxTable[i].Text = Convert.ToString(data[i], 16);
|
|
}
|
|
}
|
|
|
|
private void formAddMessage_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
{
|
|
UInt32 id;
|
|
int len;
|
|
byte[] data = new byte[8];
|
|
|
|
|
|
|
|
try
|
|
{
|
|
id = Convert.ToUInt32(txtMessageId.Text, 16);
|
|
len = Convert.ToInt32(txtMessageLen.Text);
|
|
|
|
data[0] = Convert.ToByte(txtMessageData0.Text, 16);
|
|
data[1] = Convert.ToByte(txtMessageData1.Text, 16);
|
|
data[2] = Convert.ToByte(txtMessageData2.Text, 16);
|
|
data[3] = Convert.ToByte(txtMessageData3.Text, 16);
|
|
data[4] = Convert.ToByte(txtMessageData4.Text, 16);
|
|
data[5] = Convert.ToByte(txtMessageData5.Text, 16);
|
|
data[6] = Convert.ToByte(txtMessageData6.Text, 16);
|
|
data[7] = Convert.ToByte(txtMessageData7.Text, 16);
|
|
|
|
|
|
}
|
|
catch
|
|
{
|
|
lblInfo.Text = "输入错误";
|
|
return;
|
|
}
|
|
|
|
if (len > 8)
|
|
{
|
|
len = 8;
|
|
}
|
|
|
|
if (this.MessageReturn != null)
|
|
{
|
|
this.MessageReturn(id, data, len);
|
|
}
|
|
|
|
this.Close();
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
|
|
}
|
|
}
|