日期:2014-05-17 浏览次数:21088 次
private void TestCom_DataSend(string cmd) //发送串口指令
{
if (ComDevice.IsOpen == true)
{
byte[] SendBytes = null;
string SendData = cmd;//指令
//16进制发送
try
{
//剔除所有空格
SendData = SendData.Replace(" ", "");
if (SendData.Length % 2 == 1)
{//奇数个字符
SendData = SendData.Remove(SendData.Length - 1, 1);//去除末位字符
}
List<string> SendDataList = new List<string>();
for (int i = 0; i < SendData.Length; i = i + 2)
{
SendDataList.Add(SendData.Substring(i, 2));
}
SendBytes = new byte[SendDataList.Count];