PDA

View Full Version : Calling thinBasic from other App.



Adie
13-05-2007, 14:01
Hi

I am porting my systems from xBase++ to C++ (BDS2006) but urgently require a repacement for the Clipper code blocks.

I need to process dynamic IF statements in a loop. (dynamically intepet the IF and execute the THEN

The current xBase++ code look like this

DO WHILE oDlg:lMixing .OR. oDlg:lBin2Run
FOR nP = 1 TO LEN( oDlg:aProcess )
IF EVAL( oDlg:aProcess[nP,1] )
EVAL( oDlg:aProcess[nP,,2] )
ENDIF
NEXT
Update_Screen( oDlg ) // ** Update Screen **
Update_Ports( oDlg ) // ** Update Valves **
ENDDO
***** end code ****
oDlg:aProcess[nP,1] is an array that were created during runtime with the list of 'criteria' from a data table.
Sample: "AgrA < AgrT and PSEQ() = 1"

oDlg:aProcess[nP,2] is the array of 'actions' to be executed.
"POPEN( oAGR ), PSEQ('N')" // comma seperated list of functions

In short I need to INTERPET the two EVAL functions.

I assume this would be simple if thinBasic could be loaded as a DLL. The interpeter will then parse the string and 'execute' the code.

The thinBasic script would be generated from the data table on startup to save processing time.

The c++ code would then look like this
while(true)
{
for(n = 0....)
{
thinEVAL( n );
}
Update_Screen( oDlg );
Sleep(50);
}

The thinBasic side can noe intrepet the script line based on the parameter.
Maybe the whole for loop could be the thinBasic script. ???

So after the long description I would like to know the following.
1. Can thinBasic be compiled as a DLL to be called from another App.
2. What will the overhead (cpu cycles) be on the system.

For the curious ones, I automate machines with a PC instead of PLC.

Regards

Adie

Petr Schreiber
13-05-2007, 14:27
Hi Adie,

better to wait for official statement from Eros or Roberto ( authors of thinBASIC internals ), I can try to give you few tips.
Could you tell us also hardware/software config of machine you want to use for the task ?
I remember just few things from school regarding automation like 10ms response is necessary for real time processing by standard ( 100 FPS in gamers words ).
This was no problem to achieve and in quite complex scripts.

thinBASIC is now not designed to work as embedabble script engine, but I think it is planned.
Eros did something like that, it was called BINT32, and I think it is available by direct request to him.

BINT32 is very nice, but thinBASIC is even better!

For example the C/C++ loop you mentioned is perfectly realizable in thinBASIC.
thinBASIC has EVAL module to interpret data from string at run time, so that is what you call thinEval probably.

Could you tell us also hardware/software config of machine you want to use for the task ?
Maybe little bit more info could help to understand your problem better.


Bye,
Petr

Michael Hartlef
13-05-2007, 21:20
Hello and welcome on the board. Right now Thinbasic is standalone. There are plans for a DLL version but from what I know it will be a commercial product plus I don't know when it will be available.

ErosOlmi
14-05-2007, 07:51
Hi Adie,


So after the long description I would like to know the following.
1. Can thinBasic be compiled as a DLL to be called from another App.
2. What will the overhead (cpu cycles) be on the system.

1. thinBasic is a dll. All main engine is inside a single dll called thinCore.dll but I'm sorry thinBasic cannot be used as 3rd party Dll to be embedded into application. This is a project for the future.
2. I'm not able to reply in terms of cpu cycles here. thinBasic is a parsing interpreter so its speed is very related to the speed of the computer used. If your script is very easy and requires thousands of loops per seconds, thinBasic can do that. If your script is very complex (I mean many hundred script functions to be executed per seconds) maybe it will be not efficient. After installation of thinBasic you will found some speed tests script in sample scripts directory. Just to give you an idea, 100000 loops that solve a math equation with 6/8 variables can take about 250ms on a Intel Core Duo 2Gh

Back to your specific problem, thinBasic can do the work you need to do. Eval module is not able to eval script variable using it but you can link script variables to Eval variables inside the loops and than evaluating their contents. Maybe some difficulties to eval POPEN and PSEQ because thay seem to be specific language functions. Under thinBasic Eval module does not know thinBasic functions so we need to add this functionality.

So, I'm sorry not to be able to help you on that.
In any case your request gave me some new idea on Eval module that maybe will be able to help someone else.

Let me know if I can do some work to help you in any way.

Ciao
Eros