예제 #1
0
파일: rig.cs 프로젝트: JustinB1eber/-
    void OnTriggerEnter(Collider other)
    {
        print("进入");


        char[] ch = new char[] { 's' };
        com.Send(ch);
    }
예제 #2
0
파일: LedDriver1.cs 프로젝트: zgren/dp2
        /// <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);
        }
예제 #3
0
 /// <summary>
 /// send bytes to serial port
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public bool SendDataToCom(Byte[] data)
 {
     return(comModel.Send(data));
 }
예제 #4
0
 /// <summary>
 /// send bytes to serial port
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public bool followSendDataToCom(Byte[] data)
 {
     return(followComModel.Send(data));
 }