Tanoda
SampleCustomDelimiter.cs
Go to the documentation of this file.
1
9
using
System.Text;
10
using
UnityEngine
;
11
15
public
class
SampleCustomDelimiter
: MonoBehaviour
16
{
17
#if !UNITY_WEBGL
18
public
SerialControllerCustomDelimiter
serialController
;
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
}
Debug
UnityEngine.Debug Debug
Definition:
TanodaServer.cs:19
SampleCustomDelimiter
Definition:
SampleCustomDelimiter.cs:16
SampleCustomDelimiter.serialController
SerialControllerCustomDelimiter serialController
Definition:
SampleCustomDelimiter.cs:18
SerialControllerCustomDelimiter
Definition:
SerialControllerCustomDelimiter.cs:19
SerialControllerCustomDelimiter.ReadSerialMessage
byte[] ReadSerialMessage()
Definition:
SerialControllerCustomDelimiter.cs:118
SerialControllerCustomDelimiter.SendSerialMessage
void SendSerialMessage(byte[] message)
Definition:
SerialControllerCustomDelimiter.cs:128
UnityEngine
Definition:
HSVPicker/UtilityScripts/BoxSlider.cs:7
Source
Assets
Ardity
Scripts
Samples
SampleCustomDelimiter.cs
Generated by
1.9.3