There are lots of ways to communicate between Simul8 and other applications. We make a DLL interface available for customers who want to use this method, but there are many easier methods to use. Calling an external dll requires an understanding of DLL and programming in a high level language. If you don't have this knowledge (and even if you do) you are probably better off using a direct link to Excel or a COM interface.
Assuming, you really do need to use this feature then here is how:
This help file assumes you understand Simul8's Visual Logic (VL).
Here is a practical example. In this case we pass some data in a Simul8 spreadsheet to a custom DLL, apply some algorithm inside the DLL to decided what route to take, then use the returned information (with Label Routing) to send the Work Item to the correct route.
VL SECTION: Activity 1 Work Complete Logic
'Build up a text string with all the information to pass to the DLL
SET Textvar = MySheet[10,5]
'Put commas between the items (because that's what my DLL expects)
SET Textvar = Textvar+","
SET Textvar = Textvar+MySheet[10,6]
'Call my DLL
Call Custom DLL Textvar
'Now we are back TextVar will contain information returned by the DLL
'- in my case some text telling the Work Item where to go
IF Textvar = "Use Express Route"
SET My Route Label = 1
ELSE IF Textvar = "Use Cheap Route"
SET My Route Label = 2
ELSE
'Something wrong
Display Message "The DLL Returned this: "+Textvar
This is because your VL has successfully called and returned from a DLL, but it is the dummy DLL provided by Simul8 Corporation.
In your chosen external language:
Write your DLL in the language of your choice. Refer to the following example.
Rules (easily understood and implemented by DLL programmers):
If Windows will not let you rename, replace or recompile s8extra.dll this is likely caused by s8extra.dll being in memory. Make sure you have closed all copies of Simul8. If necessary restart Windows.
library s8extra;
uses
SysUtils,
Classes,
system;
{$R *.res}
procedure s8external(TextInfo:pchar;MaxTextInfo:integer); export;
//this is the one procedure that MUST be supplied
var
myreturnstring,inputstring:string;
commapos,ierror:integer;
totalscore,newvalue:double;
begin
inputstring := strpas(TextInfo);
totalscore := 0;
commapos := pos(‘,’,inputstring);//find a comma
//for each parameter
while commapos> 0 do
begin
val(copy(inputstring,1, commapos-1),newvalue,ierror);//convert to number
if ierror <> 0 then newvalue := 0;
//add them up
totalscore := totalscore + newvalue;
delete(inputstring,1,commapos);//remove uses parameter
commapos := pos(‘,’,inputstring);//find another comma
end;
//get the last parameter
val(copy(inputstring,1, commapos-1),newvalue,ierror);
if ierror <> 0 then newvalue := 0;
totalscore := totalscore + newvalue;
//make route decision
if totalscore> 123 then
begin
myreturnstring := ‘Use Express Route’;
end
else
begin
myreturnstring := ‘Use Cheap Route’;
end;
//return the result provided it fits in the available space
if length(myreturnstring) <MaxTextInfo then strpcopy(TextInfo,myreturnstring);
end;
exports
s8external index 1;
begin
end.To see more details, download Call_DLL_example.S8.