<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>&gt; From: prc@CS.Princeton.EDU<br>&gt; Date: Thu, 12 May 2016 13:34:23 -0700<br>&gt; To: chuck-users@lists.cs.princeton.edu<br>&gt; Subject: Re: [chuck-users] Communicate with a C++ programme (Guille Elias        Alonso)<br>&gt; <br>&gt; It’s pretty old-school, but often my solution for this is to pipe text output of ChucK<br>&gt; into stdin of the Cxx program in a terminal.  You need to be sure to send to chout<br>&gt; and not just use the &lt;&lt;&lt; “PRINT THIS” &gt;&gt;&gt;; form, because the latter prints to<br>&gt; stderr, not stdout.  Here’s a simple ChucK program that writes a random number<br>&gt; to stdout every 16 ms.  Below that is a very simple C program to read and report.<br>&gt; You’d need to have your C++ program read from stdin and use the argument(s)<br>&gt; accordingly.  You’d invoke the whole thing like this:<br>&gt; <br>&gt; &gt;     chuck MyChucK.ck | myCProgram<br>&gt; <br>&gt; where myCProgram is your compiled C++ executable.<br>&gt; <br>&gt; // MyChucK.ck     ChucK Program to write random numbers to stdout<br>&gt; while (true)  {<br>&gt;     16::ms =&gt; now;<br>&gt;     chout &lt;= Std.ftoa(Math.random2f(0.0,3.14159),4); // 4 decimal places<br>&gt;     chout &lt;= "\n"; // newline<br>&gt;     chout.flush(); // be sure and do this!!<br>&gt; }<br>&gt; //   END OF CHUCK PROGRAM TO WRITE FLOATS<br>&gt; <br>&gt; // myCProgram.c     a C Program to read single floats from Stdin<br>&gt; #include &lt;stdlib.h&gt;<br>&gt; #include &lt;stdio.h&gt;<br>&gt; #include &lt;string.h&gt;<br>&gt; <br>&gt; int main()  {<br>&gt;     char inString[256];<br>&gt;     float inVal;<br>&gt;     while (1)  {<br>&gt;         fgets(inString,256,stdin);  // read standard input<br>&gt;         inVal = atof(inString);     // peel off float value<br>&gt;         inString[strlen(inString)-1] = 0; // kill the newline<br>&gt;         printf("Got it!! %s, %f\n", inString, inVal); // report!!<br>&gt;     }<br>&gt;     return 1;<br>&gt; }<br>&gt; // END C PROGRAM TO READ FLOATS<br>&gt; <br>&gt; <br>&gt; <br>&gt; &gt; On May 10, 2016, at 2:09 PM, chuck-users-request@lists.cs.princeton.edu wrote:<br>&gt; &gt; <br>&gt; &gt;   1. Communicate with a C++ programme (Guille Elias Alonso)<br>&gt; &gt;   2. Re: Communicate with a C++ programme (Stephen D Beck)<br>&gt; &gt;   3. Re: Communicate with a C++ programme (Guille Elias Alonso)<br>&gt; &gt; <br>&gt; &gt; <br>&gt; &gt; ----------------------------------------------------------------------<br>&gt; &gt; <br>&gt; &gt; Message: 1<br>&gt; &gt; Date: Tue, 10 May 2016 22:53:48 +0200<br>&gt; &gt; From: Guille Elias Alonso &lt;guille_elias_alonso@hotmail.com&gt;<br>&gt; &gt; To: "chuck-users@lists.cs.princeton.edu"<br>&gt; &gt;         &lt;chuck-users@lists.cs.princeton.edu&gt;<br>&gt; &gt; Subject: [chuck-users] Communicate with a C++ programme<br>&gt; &gt; Message-ID: &lt;DUB125-W7866DF5CBF0938708FB36CB3710@phx.gbl&gt;<br>&gt; &gt; Content-Type: text/plain; charset="iso-8859-1"<br>&gt; &gt; <br>&gt; &gt; Hello guys,<br>&gt; &gt; 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>&gt; &gt; 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>&gt; &gt; Thanks,Guillermo                                               <br>&gt; &gt; -------------- next part --------------<br>&gt; &gt; An HTML attachment was scrubbed...<br>&gt; &gt; URL: &lt;http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20160510/cf395d6b/attachment-0001.html&gt;<br>&gt; &gt; <br>&gt; _______________________________________________<br>&gt; chuck-users mailing list<br>&gt; chuck-users@lists.cs.princeton.edu<br>&gt; https://lists.cs.princeton.edu/mailman/listinfo/chuck-users<br></div>                                               </div></body>
</html>