2 summary:: serial port interface
3 categories:: External Control
16 baudrate [4800..230400]
28 hardware flow control (true | false)
31 software flow control (true | false)
34 open the device exclusively (true | false)
37 returns an array of available device.
45 SerialPort.listDevices;
49 change device selection
51 SerialPort.devicePattern = "/dev/ttyUSB*"; // linux usb serial
54 SerialPort.devicePattern = nil;
63 private::initSerialPort, prOpen, prClose, primCleanup, prCleanup, prPut, prDataAvailable, prDoneAction
66 Read a byte from the device. Non-blocking read.
69 Read a byte from the device. Blocking read.
72 Rx errors since last query.
75 Write a byte to the device. Always blocks.
78 Write multiple bytes to the device. Collection may be link::Classes/Int8Array:: or link::Classes/String::.
81 A link::Classes/Function:: which will be evaluated if the port gets closed (maybe unexpectedly so, due to hardware failure or accidental disconnection). This allows you to for example to make a backup solution and activate it (like using fake input data for your algorithm, or trying to reopen the device). By default it will post a message to the post window.
91 "/dev/tty.usbserial-181",
96 // read a byte from the device
98 p.next; // doesn't block
99 fork{p.read.postln}; // may suspend thisThread - should be called within a routine
101 // write a byte to the device
103 fork{p.put(42)}; // may suspend thisThread - should be called within a routine
105 // write multiple bytes to the device
107 p.putAll("whaddayawant");
108 p.putAll(Int8Array[13, 10]);
110 p.doneAction = { "my serial port got closed".postln; }
112 p.close; // close the port
114 SerialPort.closeAll; // close all ports
117 subsection::Arduino write example
119 First load the sketch Examples/Communication/Dimmer. See http://www.arduino.cc/en/Tutorial/Dimmer
122 Always make sure the serial monitor is closed in the Arduino application before opening the port in SuperCollider.
128 "/dev/tty.usbserial-A800crTT", //edit to match your port. SerialPort.listDevices
129 baudrate: 9600, //check that baudrate is the same as in arduino sketch
133 //send serial data - slow pulsating
137 p.put(i.fold(0, 100).linexp(0, 100, 1, 255).asInteger.postln);
147 subsection::Arduino read example
149 First load the sketch Examples/Communication/Graph. See http://www.arduino.cc/en/Tutorial/Graph
152 Always make sure the serial monitor is closed in the Arduino application before opening the port in SuperCollider.
158 "/dev/tty.usbserial-A800crTT", //edit to match your port. SerialPort.listDevices
159 baudrate: 9600, //check that baudrate is the same as in arduino sketch
163 //read 10bit serial data sent from Arduino's Serial.println
170 while({byte = p.read; byte !=13 }, {
171 str= str++byte.asAscii;
174 ("read value:"+res).postln;