<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>That makes everything much simpler and it's probably faster thanks!<br><br><div>> From: prc@CS.Princeton.EDU<br>> Date: Thu, 12 May 2016 13:34:23 -0700<br>> To: chuck-users@lists.cs.princeton.edu<br>> Subject: Re: [chuck-users] Communicate with a C++ programme (Guille Elias        Alonso)<br>> <br>> It’s pretty old-school, but often my solution for this is to pipe text output of ChucK<br>> into stdin of the Cxx program in a terminal. You need to be sure to send to chout<br>> and not just use the <<< “PRINT THIS” >>>; form, because the latter prints to<br>> stderr, not stdout. Here’s a simple ChucK program that writes a random number<br>> to stdout every 16 ms. Below that is a very simple C program to read and report.<br>> You’d need to have your C++ program read from stdin and use the argument(s)<br>> accordingly. You’d invoke the whole thing like this:<br>> <br>> > chuck MyChucK.ck | myCProgram<br>> <br>> where myCProgram is your compiled C++ executable.<br>> <br>> // MyChucK.ck ChucK Program to write random numbers to stdout<br>> while (true) {<br>> 16::ms => now;<br>> chout <= Std.ftoa(Math.random2f(0.0,3.14159),4); // 4 decimal places<br>> chout <= "\n"; // newline<br>> chout.flush(); // be sure and do this!!<br>> }<br>> // END OF CHUCK PROGRAM TO WRITE FLOATS<br>> <br>> // myCProgram.c a C Program to read single floats from Stdin<br>> #include <stdlib.h><br>> #include <stdio.h><br>> #include <string.h><br>> <br>> int main() {<br>> char inString[256];<br>> float inVal;<br>> while (1) {<br>> fgets(inString,256,stdin); // read standard input<br>> inVal = atof(inString); // peel off float value<br>> inString[strlen(inString)-1] = 0; // kill the newline<br>> printf("Got it!! %s, %f\n", inString, inVal); // report!!<br>> }<br>> return 1;<br>> }<br>> // END C PROGRAM TO READ FLOATS<br>> <br>> <br>> <br>> > On May 10, 2016, at 2:09 PM, chuck-users-request@lists.cs.princeton.edu wrote:<br>> > <br>> > 1. Communicate with a C++ programme (Guille Elias Alonso)<br>> > 2. Re: Communicate with a C++ programme (Stephen D Beck)<br>> > 3. Re: Communicate with a C++ programme (Guille Elias Alonso)<br>> > <br>> > <br>> > ----------------------------------------------------------------------<br>> > <br>> > Message: 1<br>> > Date: Tue, 10 May 2016 22:53:48 +0200<br>> > From: Guille Elias Alonso <guille_elias_alonso@hotmail.com><br>> > To: "chuck-users@lists.cs.princeton.edu"<br>> >         <chuck-users@lists.cs.princeton.edu><br>> > Subject: [chuck-users] Communicate with a C++ programme<br>> > Message-ID: <DUB125-W7866DF5CBF0938708FB36CB3710@phx.gbl><br>> > Content-Type: text/plain; charset="iso-8859-1"<br>> > <br>> > Hello guys,<br>> > I'm writing a programme that analyses the micro input and makes some actions according to the analysis. Everything about the analysis is written in Chuck. The analysis of the micro signal gives a single number every 16 ms, and this number has to be sent to the C++ programme but I don't know how I can connect the two parts. This application is highly time-sensitive so I need a fast way of communicating.<br>> > I had read about these OSC events but it seems it's only for Chuck programmes receiving input from the outside and I want just the opposite. I've also thought about some mechanism of shared memory between the Chuck programme and the C++ programme but I don't see anywhere some way of implementing that with Chuck. Do you have any ideas?<br>> > Thanks,Guillermo                                            <br>> > -------------- next part --------------<br>> > An HTML attachment was scrubbed...<br>> > URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20160510/cf395d6b/attachment-0001.html><br>> > <br>> _______________________________________________<br>> chuck-users mailing list<br>> chuck-users@lists.cs.princeton.edu<br>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users<br></div>                                            </div></body>
</html>