3 classvar <>devicePattern, allPorts;
4 var dataptr, semaphore;
10 UI.registerForShutdown({
19 thisProcess.platform.name.switch(
20 \linux, "/dev/tty[A,S,U]*",
27 this.devices.do(_.postln);
41 port = this.devices[port] ?? {
42 Error("invalid port index").throw;
46 ^super.new.initSerialPort(
52 ( even: 1, odd: 2 ).at(parity) ? 0,
57 initSerialPort { | ... args |
58 semaphore = Semaphore(0);
61 allPorts = allPorts.add(this);
62 doneAction = { ("SerialPort"+args[0]+"was closed").postln; };
63 // CmdPeriod.add(this);
73 allPorts.remove(this);
74 // CmdPeriod.remove(this);
86 ports.do(_.primCleanup);
97 while { (byte = this.next).isNil } {
102 // rx errors since last query
108 put { | byte, timeout=0.005 |
109 if ( dataptr.notNil ){
110 while { this.prPut(byte).not } {
112 timeout = timeout * 2;
115 "SerialPort not open".warn;
118 putAll { | bytes, timeout=0.005 |
120 this.put(byte, timeout);
129 // // remove waiting threads
134 prOpen { | ... args | // was: | port, baudRate | but that misses out on all the other args?
136 ^this.primitiveFailed
140 ^this.primitiveFailed
144 ^this.primitiveFailed
149 allPorts.remove(this);
154 ^this.primitiveFailed