master
CZ 8 months ago
commit e481a55c83

@ -116,6 +116,25 @@ namespace BatCharging.Service
return bytesResult; return bytesResult;
} }
/// <summary>
/// 32进制数高地位对调
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static byte[] Int32ToByteArray(Int32 value) //16进制数高地位对调
{
byte[] bytesResult = new byte[4];
byte[] temp = new byte[4];
BitConverter.GetBytes(Convert.ToInt32(value)).CopyTo(temp, 0);
bytesResult[0] = temp[3];
bytesResult[1] = temp[2];
bytesResult[2] = temp[1];
bytesResult[3] = temp[0];
return bytesResult;
}
/// <summary> /// <summary>
/// 获取16进制字符串的字节数组 /// 获取16进制字符串的字节数组

@ -10,7 +10,7 @@ namespace BatCharging.Service
public class ChargerSendCMD public class ChargerSendCMD
{ {
#region 协议格式 #region 协议格式
public byte[] SendRCMD1(out APDUModel APDUModel, CMD1 t) public byte[] SendRCMD1(out APDUModel APDUModel, CMD1 CMD)
{ {
byte[] result = null; byte[] result = null;
@ -24,7 +24,7 @@ namespace BatCharging.Service
model.checksumDomain = 0x01; model.checksumDomain = 0x01;
model.dataDomain = GetRCMD1DataInfo(t); //数据域 model.dataDomain = GetRCMD1DataInfo(CMD); //数据域
model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度 model.LengthDomain = Convert.ToUInt16(9 + model.dataDomain.Length); //报文长度
List<byte> lstResult = new List<byte>(); List<byte> lstResult = new List<byte>();
@ -47,15 +47,15 @@ namespace BatCharging.Service
{ {
List<byte> lstContent = new List<byte>(); List<byte> lstContent = new List<byte>();
lstContent.AddRange(BitConverter.GetBytes(CMD1.value1)); lstContent.AddRange(ByteUtils.Int16ToByteArray((short)CMD1.value1));
lstContent.AddRange(BitConverter.GetBytes(CMD1.value2)); lstContent.AddRange(ByteUtils.Int16ToByteArray((short)CMD1.value2));
lstContent.Add(CMD1.value3); lstContent.Add(CMD1.value3);
lstContent.AddRange(BitConverter.GetBytes(CMD1.value4)); lstContent.AddRange(ByteUtils.Int32ToByteArray((int)CMD1.value4));
if (CMD1.value3 == 1) if (CMD1.value3 == 1)
{ {
lstContent.Add(CMD1.value5); lstContent.Add(CMD1.value5);
lstContent.AddRange(BitConverter.GetBytes(CMD1.value6)); lstContent.AddRange(ByteUtils.Int16ToByteArray((short)CMD1.value6));
lstContent.AddRange(CMD1.value7); lstContent.AddRange(CMD1.value7);
} }
else else
@ -104,13 +104,13 @@ namespace BatCharging.Service
{ {
List<byte> lstContent = new List<byte>(); List<byte> lstContent = new List<byte>();
lstContent.AddRange(BitConverter.GetBytes(CMD.value1)); lstContent.AddRange(ByteUtils.Int16ToByteArray((short)CMD.value1));
lstContent.AddRange(BitConverter.GetBytes(CMD.value2)); lstContent.AddRange(ByteUtils.Int16ToByteArray((short)CMD.value2));
lstContent.Add(CMD.value3); lstContent.Add(CMD.value3);
lstContent.AddRange(BitConverter.GetBytes(CMD.value4)); lstContent.AddRange(ByteUtils.Int32ToByteArray((int)CMD.value4));
if (CMD.value3 == 1) if (CMD.value3 == 1)
{ {
lstContent.AddRange(BitConverter.GetBytes(CMD.value5)); lstContent.AddRange(ByteUtils.Int16ToByteArray((short)CMD.value5));
lstContent.AddRange(CMD.value6); lstContent.AddRange(CMD.value6);
} }
else else

@ -224,10 +224,18 @@ namespace Monitor.ChargeTest
/// <param name="e"></param> /// <param name="e"></param>
private void button14_Click(object sender, EventArgs e) private void button14_Click(object sender, EventArgs e)
{ {
byte type = 0; byte type = 1;//类型 0-查询/1-设置
uint startAddress = 2; uint startAddress = 2;//设置/查询参数起始地址
byte num = 3; byte num = 3;//设置/查询个数
byte[] setData = null; byte[] setData = new byte[8];//设置数据
setData[0] = 0;
setData[1] = 1;
setData[2] = 2;
setData[3] = 3;
setData[4] = 4;
setData[5] = 5;
setData[6] = 6;
setData[7] = 7;
CmnChargerParam._CHR00TCPCLIENT.Send1(type, startAddress, num, setData); CmnChargerParam._CHR00TCPCLIENT.Send1(type, startAddress, num, setData);
} }
/// <summary> /// <summary>
@ -237,9 +245,17 @@ namespace Monitor.ChargeTest
/// <param name="e"></param> /// <param name="e"></param>
private void button15_Click(object sender, EventArgs e) private void button15_Click(object sender, EventArgs e)
{ {
byte type = 0; byte type = 0;//0-查询 1-设置
uint startAddress = 1; uint startAddress = 1;//设置/查询参数启始地址
byte[] setData = null; byte[] setData = new byte[8];//设置数据
setData[0] = 0;
setData[1] = 1;
setData[2] = 2;
setData[3] = 3;
setData[4] = 4;
setData[5] = 5;
setData[6] = 6;
setData[7] = 7;
CmnChargerParam._CHR00TCPCLIENT.Send3(type, startAddress, setData); CmnChargerParam._CHR00TCPCLIENT.Send3(type, startAddress, setData);
} }
/// <summary> /// <summary>

Loading…
Cancel
Save