[scilab-Users] Question on using plot in call_scilab module

Mike Page Mike at Page-One.Waitrose.com
Wed Feb 2 10:58:38 CET 2011


Hi Sylvestre,

I am not really an expert in using Call_Scilab.  In fact, this is the only time I have used it.  It does seem to work OK for me, but there are a few things worth improving maybe:

1. The documentation is quite weak in places and sometimes it seems even wrong.  For example the fourth parameter of Start_Scilab is given as int*, when it actually seems to be int.

2. The examples don't always seem to compile and/or work properly.  For example, the code includes stack-c.h, which the build says is deprecated and shouldn't be used.

3. It would be useful to give a list of the required include (.h) and library (.lib, .dll) files , although I guess this could be quite complicated.  The include files are scattered in the various module directories and not easy to collect into a C project.

4. The help information is very Linux specific - some of the sections relating to Windows are just blank.

5. The error return I got from SendScilabJob was usually "999".  This error is not listed in the help.

6. There seems no way to interact with Scilab's more complicated types such as handles, lists, etc.

Hope that's useful.  I can log any of the above in the Bugzilla if you want.

By the way - there is a bug in the example code I provided (below).  All three events should be created in main, otherwise there's a chance the Reply event won't be created by the time the main thread waits on it.

Cheers,
Mike.



-----Original Message-----
From: Sylvestre Ledru [mailto:sylvestre.ledru at scilab.org]
Sent: 26 January 2011 11:59
To: users at lists.scilab.org
Subject: RE: [scilab-Users] Question on using plot in call_scilab module


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
> 


No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.872 / Virus Database: 271.1.1/3402 - Release Date: 01/25/11 07:34:00





More information about the users mailing list