Exemple #1
0
 private void OnGUI()
 {
     if (GUILayout.Button("读"))
     {
         int readnum = myserial.Read(buffers);
         Debug.Log(readnum);
     }
     if (GUILayout.Button("写"))
     {
         myserial.Write(new byte[] { 1, 2, 3, 4, 5 });
     }
 }
Exemple #2
0
    void ReadMessage()
    {
        if (myserial == null)
        {
            return;
        }
        Debug.LogError("查询按钮状态:");
        myserial.Write(HexStringToBytes("FCAA"));
        buffers = new byte[32];
        int readnum = myserial.Read(buffers);

        if (readnum > 0)
        {
            string str = byteToHexStr(buffers, readnum);
            Debug.LogError(string.Format("串口读取成功: 长度:{0}, 内容:{1}", readnum, str));
            for (int i = 0; i < this.images.Count; i++)
            {
                this.images[i].color = Color.white;
            }
            switch (str)
            {
            case "FD01":
                this.images[0].color = Color.red; AC.bgePlay();
                break;

            case "FD02":
                this.images[1].color = Color.red; AC.bgePlay1();
                break;

            case "FD03":
                this.images[2].color = Color.red; AC.bgePlay2();
                break;

            case "FD04":
                this.images[3].color = Color.red; AC.bgePlay3();
                break;

            case "FD05":
                this.images[4].color = Color.red; AC.bgePlay4();
                break;

            case "FD06":
                this.images[5].color = Color.red;
                break;
            }
        }
    }