三.開始編寫串口通信的類
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);
}
}
}
}