You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace NDSD_TouchSocket
|
|
|
|
|
{
|
|
|
|
|
public class SendAnalysis
|
|
|
|
|
{
|
|
|
|
|
private string DOperateHead = "01 05 00 ";
|
|
|
|
|
private string DOpenData = " FF 00";
|
|
|
|
|
private string DCloseData = " 00 00";
|
|
|
|
|
|
|
|
|
|
//开启
|
|
|
|
|
public byte[] DOpenDataAnalysis(byte port)
|
|
|
|
|
{
|
|
|
|
|
string CrcData = DOperateHead + port.ToString("X2") + DOpenData; //结合
|
|
|
|
|
return CrcCombine(CrcData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//关闭
|
|
|
|
|
public byte[] DCloseDataAnlysis(byte port)
|
|
|
|
|
{
|
|
|
|
|
string CrcData = DOperateHead + port.ToString("X2") + DCloseData; //结合
|
|
|
|
|
return CrcCombine(CrcData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//结合CRC
|
|
|
|
|
public byte[] CrcCombine(string CrcData)
|
|
|
|
|
{
|
|
|
|
|
byte[] body = CrcData.ToBytesFromHexString(); //byte的校验体
|
|
|
|
|
int crc = CRC16.CalculateCRC(body, body.Length); //int32CRC值
|
|
|
|
|
byte highByte = (byte)(crc >> 8); // 获取高字节
|
|
|
|
|
byte lowByte = (byte)(crc & 0xFF); // 获取低字节
|
|
|
|
|
byte[] crcBytes = { lowByte, highByte };
|
|
|
|
|
return body.Concat(crcBytes).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|