void OnTriggerEnter(Collider other) { print("进入"); char[] ch = new char[] { 's' }; com.Send(ch); }
/// <summary> /// 发送指令串到led显示屏 /// </summary> /// <param name="portName"></param> /// <param name="msg"></param> /// <param name="error"></param> /// <returns></returns> public static bool sendMsg2Led(string portName, string msg, out string error) { error = ""; ComModel _comModel = new ComModel(); try { // 打开串口 var ret = _comModel.Open(portName, "57600", //baudRate, "8", //dataBits, "One", //stopBits, "None", //parity, "None", //handshake out error); if (ret == false) { return(false); } // 将字符转为二进制 System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312"); byte[] data = encoding.GetBytes(msg); // 给串口发送二进制 bool bRet = _comModel.Send(data, out string strError); if (bRet == false) { error = $"给串口({portName})发送消息失败: {strError}"; return(false); } } catch (Exception ex) { error = ex.Message; return(false); } finally { // 关闭串口 _comModel.Close(); } return(true); }
/// <summary> /// send bytes to serial port /// </summary> /// <param name="data"></param> /// <returns></returns> public bool SendDataToCom(Byte[] data) { return(comModel.Send(data)); }
/// <summary> /// send bytes to serial port /// </summary> /// <param name="data"></param> /// <returns></returns> public bool followSendDataToCom(Byte[] data) { return(followComModel.Send(data)); }