[scilab-Users] Question on using plot in call_scilab module
Sylvestre Ledru
sylvestre.ledru at scilab.org
Wed Jan 26 12:59:14 CET 2011
Thanks for sharing this.
Managing Scilab graphics and Scilab windows from call_scilab & Javasci
v2 is something I would like to improve in the next releases but I am
still unsure on the right way to implement this...
If you have ideas, I would be happy to hear them.
Sylvestre
Le mercredi 26 janvier 2011 à 11:26 +0000, Mike Page a écrit :
> Hi Norm,
>
> Sorry if this response is too late for you, but it may help somebody else...
>
> I came across your post while looking for help on another issue related to
> plotting with SendScilabJob. Here is some example code that runs the
> plotting in a separate thread under WinXp. It works for me and I think it
> would do what you wanted. Sorry it's a bit short on comments ;-)
>
> To build this, you need to also include the /include directories from:
> SCI/modules/call_scilab
> SCI/modules/api_scilab
> SCI/modules/core
>
> You also need to set the library path to include SCI/bin and include the
> libraries:
> api_scilab.lib
> call_scilab.lib
> MALLOC.lib
> LibScilab.lib
>
> When running, /SCI/bin needs to be in your path so Scilab can find the DLLs.
>
> HTH.
> Mike.
>
> /*--------------------------------------------------------------------------
> */
> #include <windows.h>
> #include <stdio.h>
> #include <process.h>
> #include "call_scilab.h"
> #include "api_scilab.h"
>
>
> HANDLE PlotCmd[2];
> HANDLE Reply;
> double x[100];
> double y[100];
>
>
> /*--------------------------------------------------------------------------
> */
> static void SciPlot (void* Params)
> {
> DWORD Event;
> BOOL Exit = FALSE;
>
> if (StartScilab (NULL, NULL, 0) == FALSE)
> {
> printf ("Error : StartScilab\n");
> }
>
> Reply = CreateEvent (NULL, FALSE, FALSE, NULL);
>
> while (!Exit)
> {
> Event = WaitForMultipleObjects (2, PlotCmd, FALSE, INFINITE);
>
> switch (Event)
> {
> case (WAIT_OBJECT_0 + 0):
> {
> createNamedMatrixOfDouble (pvApiCtx, "x", 1, 100, x);
> createNamedMatrixOfDouble (pvApiCtx, "y", 1, 100, y);
> SendScilabJob ("delete (e);");
> SendScilabJob ("plot2d(x,y);");
> SendScilabJob ("e = gce ();");
> printf ("...Plot started\n");
> SetEvent (Reply);
> break;
> }
> case (WAIT_OBJECT_0 + 1):
> {
> Exit = TRUE;
> break;
> }
> }
> }
>
> if (TerminateScilab (NULL) == FALSE)
> {
> printf ("Error : TerminateScilab\n");
> }
>
> SetEvent (Reply);
> }
>
> /*--------------------------------------------------------------------------
> */
> int main(void)
> {
> int i, j;
>
> printf ("Starting\n");
> PlotCmd[0] = CreateEvent (NULL, FALSE, FALSE, NULL);
> PlotCmd[1] = CreateEvent (NULL, FALSE, FALSE, NULL);
> _beginthread (SciPlot, 0, NULL);
> Sleep (1000);
>
> for (j=1; j<100; j++)
> {
> x[j] = j;
> }
>
> for (i=0; i<10; i++)
> {
> for (j=1; j<100; j++)
> {
> y[j] = (2.0 *(double)rand () / (double)RAND_MAX) - 1.0;
> }
> printf ("Update Plot\n");
> SetEvent (PlotCmd[0]);
> WaitForSingleObject (Reply, INFINITE);
> Sleep (1000);
> }
> printf ("Terminate Plot\n");
> SetEvent (PlotCmd[1]);
> WaitForSingleObject (Reply, INFINITE);
> CloseHandle (PlotCmd[0]);
> CloseHandle (PlotCmd[1]);
> return 0;
> }
> /*--------------------------------------------------------------------------
> */
>
>
>
> -----Original Message-----
> From: Norman Beamish [mailto:norman.beamish at m4s.be]
> Sent: 03 June 2010 11:13
> To: users at lists.scilab.org
> Subject: [scilab-Users] Question on using plot in call_scilab module
>
>
> Hi,
>
> I'm using the call_scilab module to access scilab functions from within
> a C program. I'm using MS Visual C++ 2008 on MS Vista.
>
> Everything that just writes its output to the console works ok. However
> when I use the scilab plot command
> SendScilabJob("plot(x,y, style);")
> I find that the plot window freezes and the plot menu options are
> unavailable unless I run the following loop: -
> while( ScilabHaveAGraph() )
> {
> ScilabDoOneEvent();
> }
> Of course this loop stops my program from doing anything else.
>
> My question:
> I believe this problem arises because everything is operating in a
> single thread. Is there a way to make the plot command start out in a
> separate thread so that it can still monitor for user events such as
> mouse clicks while the rest of my program continues.
>
> thanks,
> Norm
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.829 / Virus Database: 271.1.1/2914 - Release Date: 06/02/10
> 19:25:00
>
More information about the users
mailing list