[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] how to write to serial port from pattern?
I am creating a piece in which I would like to send values to the serial port
from a supercollider pattern.
Since I do not have a serial port available on the system I'm developing on
at the moment, I first create a serial port in a console to test my code:
socat -d -d pty,raw,echo=0 pty,raw,echo=0
This returns:
2016/12/31 20:33:25 socat[9456] N PTY is /dev/pts/4
2016/12/31 20:33:25 socat[9456] N PTY is /dev/pts/5
2016/12/31 20:33:25 socat[9456] N starting data transfer loop with FDs [5,5]
and [7,7]
I then use the first device as a serial device (/dev/pts/4). In a (failed)
attempt to be smart, I wrote a synthdef like (the following code is
simplified from the actual code) and I used that as an \instrument in a
pattern:
(
p = SerialPort(
"/dev/pts/4",
baudrate: 9600,
crtscts: true);
d = SynthDef (\serialSynth, {
| freq = 200|
var msbSpeed = (freq.round(1) & 16rFF00) >> 8;
var lsbSpeed = (freq.round(1) & 16r00FF);
p.putAll(Int8Array[lsbSpeed, msbSpeed]);
});
q = Pdef(\a, Pbind(\instrument, \serialSynth, \degrees, Pseq([0],inf)));
q.play;
)
But this this throws errors (attached below). How could I still accomplish
my goal?
Maybe it's possible to send an OSC message with the frequency from the
server to the language and handle things there somehow (I still need to find
out how to do that though), or perhaps there's a better/easier/more
convenient/more elegant solution?
portName /dev/pts/4
ERROR: Primitive '_ArrayAdd' failed.
Wrong type.
RECEIVER:
Instance of Int8Array { (0x515ec98, gc=50, fmt=06, flg=00, set=02)
indexed slots [0]
}
PATH: /home/supercollider/testproblem.scd
PROTECTED CALL STACK:
Meta_MethodError:new 0x2871fc0
arg this = PrimitiveFailedError
arg what = Wrong type.
arg receiver = Int8Array[ ]
Meta_PrimitiveFailedError:new 0x2878580
arg this = PrimitiveFailedError
arg receiver = Int8Array[ ]
Object:primitiveFailed 0x206c900
arg this = Int8Array[ ]
a FunctionDef 0x4cca1c8
sourceCode = "{
| freq = 200|
var msbSpeed = (freq.round(1) & 16rFF00) >> 8;
var lsbSpeed = (freq.round(1) & 16r00FF);
p.putAll(Int8Array[lsbSpeed, msbSpeed]);
}"
arg freq = an OutputProxy
var msbSpeed = a BinaryOpUGen
var lsbSpeed = a BinaryOpUGen
SynthDef:buildUgenGraph 0x40a8640
arg this = SynthDef:serialSynth
arg func = a Function
arg rates = nil
arg prependArgs = [ ]
var result = nil
var saveControlNames = nil
a FunctionDef 0x40a6c80
sourceCode = "<an open Function>"
Function:prTry 0x2b543c0
arg this = a Function
var result = nil
var thread = a Thread
var next = nil
var wasInProtectedFunc = false
CALL STACK:
MethodError:reportError 0x5475d28
arg this = <instance of PrimitiveFailedError>
Nil:handleError 0x639c618
arg this = nil
arg error = <instance of PrimitiveFailedError>
Thread:handleError 0x644cab8
arg this = <instance of Thread>
arg error = <instance of PrimitiveFailedError>
Object:throw 0x235ded8
arg this = <instance of PrimitiveFailedError>
Function:protect 0x49651f8
arg this = <instance of Function>
arg handler = <instance of Function>
var result = <instance of PrimitiveFailedError>
SynthDef:build 0x7fcde040bab8
arg this = <instance of SynthDef>
arg ugenGraphFunc = <instance of Function>
arg rates = nil
arg prependArgs = nil
< closed FunctionDef > (no arguments or variables)
Interpreter:interpretPrintCmdLine 0x7fcde02814e8
arg this = <instance of Interpreter>
var res = nil
var func = <instance of Function>
var code = "(
p = SerialPort(
"/dev/pts..."
var doc = nil
var ideClass = <instance of Meta_ScIDE>
Process:interpretPrintCmdLine 0x44ce458
arg this = <instance of Main>
^^ The preceding error dump is for ERROR: Primitive '_ArrayAdd' failed.
Wrong type.
RECEIVER: Int8Array[ ]
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/how-to-write-to-serial-port-from-pattern-tp7629867.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/