三.开始编写串口通信的类
1.首先定义我们的设备的输入按钮,方便后面判断输入调用
public enum KeyType { 圆形按钮 方形按钮 前 后 左 右 }//按钮
public KeyType keyType;
2.定义我们的串口属性变量,建议串口属性使用配置文件来管理方便适配不同的串口设备
public string portName =\\\"COM3\\\";
public int baudRate = 9600;
public int dataBits = 8;
public StopBits stopBits = StopBits.None;
public Parity parity = Parity.None;
if (SerialPortManagr.Instance.anyKeyDown())
{
foreach (KeyType type in Enum.GetValues(typeof(KeyType)))
{
if (SerialPortManagr.Instance.InputKeyClickDown(type))
{
print(\\\"点击了\\\" + type);
}
}
}
}