hj212
This commit is contained in:
@@ -59,8 +59,9 @@ namespace Modbus.Net.HJ212
|
||||
formatMessage += "CN=" + r_message.CN + ";";
|
||||
formatMessage += "PW=" + r_message.PW + ";";
|
||||
formatMessage += "MN=" + r_message.MN + ";";
|
||||
formatMessage += "Flag=5;";
|
||||
formatMessage += "CP=&&";
|
||||
formatMessage += "DateTime=" + r_message.Datetime.ToString("yyyyMMddHHmmss") + ";";
|
||||
formatMessage += "DataTime=" + r_message.Datatime + ";";
|
||||
foreach (var record in r_message.CP)
|
||||
{
|
||||
foreach (var data in record)
|
||||
@@ -93,15 +94,16 @@ namespace Modbus.Net.HJ212
|
||||
{
|
||||
public WriteRequestHJ212InputStruct(string st, string cn, string pw, string mn, List<Dictionary<string, string>> cp, DateTime datetime)
|
||||
{
|
||||
QN = datetime.ToString("yyyyMMddHHmmssffff");
|
||||
ST = st;
|
||||
CN = cn;
|
||||
PW = pw;
|
||||
MN = mn;
|
||||
CP = cp;
|
||||
Datetime = datetime;
|
||||
Datatime = datetime.ToString("yyyyMMddHHmmss");
|
||||
}
|
||||
|
||||
public string QN => "20170101000926706";
|
||||
public string QN { get; }
|
||||
|
||||
public string ST { get; }
|
||||
|
||||
@@ -113,7 +115,7 @@ namespace Modbus.Net.HJ212
|
||||
|
||||
public List<Dictionary<string, string>> CP { get; }
|
||||
|
||||
public DateTime Datetime { get; }
|
||||
public string Datatime { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace Modbus.Net.HJ212
|
||||
/// <returns>扩展后的协议内容</returns>
|
||||
public byte[] BytesExtend(byte[] content)
|
||||
{
|
||||
var newFormat = new byte[content.Length + 12];
|
||||
var newFormat = new byte[content.Length + 14];
|
||||
Array.Copy(content, 0, newFormat, 6, content.Length);
|
||||
//表头长度扩张
|
||||
var length = content.Length;
|
||||
var length = content.Length + 2;
|
||||
string lengthString = length.ToString("0000");
|
||||
lengthString = "##" + lengthString;
|
||||
var lengthCalc = Encoding.ASCII.GetBytes(lengthString);
|
||||
@@ -27,9 +27,9 @@ namespace Modbus.Net.HJ212
|
||||
var crc = new byte[2];
|
||||
Crc16.GetInstance().GetCRC(content, ref crc);
|
||||
string crcString = BitConverter.ToString(crc).Replace("-", string.Empty);
|
||||
crcString = "&&" + crcString;
|
||||
crcString = "&&" + crcString + "\r\n";
|
||||
var crcCalc = Encoding.ASCII.GetBytes(crcString);
|
||||
Array.Copy(crcCalc, 0, newFormat, newFormat.Length - 6, 6);
|
||||
Array.Copy(crcCalc, 0, newFormat, newFormat.Length - 8, 8);
|
||||
return newFormat;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,8 @@ namespace Modbus.Net
|
||||
pipeline.AddLast("handler", this);
|
||||
}));
|
||||
|
||||
Channel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(_host), _port));
|
||||
var isIp = IPAddress.TryParse(_host, out _);
|
||||
Channel = await bootstrap.ConnectAsync(isIp ? new IPEndPoint(IPAddress.Parse(_host), _port) : new DnsEndPoint(_host, _port));
|
||||
|
||||
if (Channel.Open)
|
||||
{
|
||||
|
||||
@@ -180,7 +180,8 @@ namespace Modbus.Net
|
||||
logger.LogDebug($"Udp client {ConnectionToken} send: {string.Concat(datagram.Select(p => " " + p.ToString("X2")))}");
|
||||
IByteBuffer buffer = Unpooled.Buffer();
|
||||
buffer.WriteBytes(datagram);
|
||||
var packet = new DatagramPacket((IByteBuffer)buffer.Retain(), new IPEndPoint(IPAddress.Parse(_host), _port));
|
||||
var isIp = IPAddress.TryParse(_host, out _);
|
||||
var packet = new DatagramPacket((IByteBuffer)buffer.Retain(), isIp ? new IPEndPoint(IPAddress.Parse(_host), _port) : new DnsEndPoint(_host, _port));
|
||||
await Channel.WriteAndFlushAsync(packet);
|
||||
}
|
||||
catch (Exception err)
|
||||
|
||||
Reference in New Issue
Block a user