关于C#的串口通信问题
菜鸟由于工作需要要写个上位机软件。现在我想通过串口将textBox的数据发送到我的单片机中,textBox中的每两个字节我当成一个十六进制的数据发送出去,请问下大哥们怎么将textBox的数据读回来转换成十六进制发送出去。给个代码提示下
程序代码: /// <summary>
/// 字符串转16进制字节数组
/// </summary>
/// <param name="hexString"></param>
/// <returns></returns>
public static byte[] strToHexByte(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}







