Tanoda
SampleCustomDelimiter.cs
Go to the documentation of this file.
1
9using System.Text;
10using UnityEngine;
11
15public class SampleCustomDelimiter : MonoBehaviour
16{
17#if !UNITY_WEBGL
19
20 // Initialization
21 void Start()
22 {
23 serialController = GameObject.Find("SerialController").GetComponent<SerialControllerCustomDelimiter>();
24
25 Debug.Log("Press the SPACEBAR to execute some action");
26 }
27
28 // Executed each frame
29 void Update()
30 {
31 //---------------------------------------------------------------------
32 // Send data
33 //---------------------------------------------------------------------
34
35 // If you press one of these keys send it to the serial device. A
36 // sample serial device that accepts this input is given in the README.
37 if (Input.GetKeyDown(KeyCode.Space))
38 {
39 Debug.Log("Sending some action");
40 // Sends a 65 (ascii for 'A') followed by an space (ascii 32, which
41 // is configured in the controller of our scene as the separator).
42 serialController.SendSerialMessage(new byte[] {65, 32});
43 }
44
45
46 //---------------------------------------------------------------------
47 // Receive data
48 //---------------------------------------------------------------------
49
50 var message = serialController.ReadSerialMessage();
51
52 if (message == null)
53 return;
54
55 var sb = new StringBuilder();
56 foreach (var b in message)
57 sb.AppendFormat("(#{0}={1}) ", b, (char) b);
58 Debug.Log("Received some bytes, printing their ascii codes: " + sb);
59 }
60#endif
61}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
SerialControllerCustomDelimiter serialController