Help on the General DLL Block in PSIM
Powersim Inc.
October 2004
Unlike the simple DLL blocks with fixed number of inputs and outputs (such as the DLL Block with 3 inputs and 3 outputs), the general DLL block provides more flexibility and capability in interfacing PSIM with custom DLL files. This file describes the convention and basis of the general DLL block.
The general DLL block allows urs to write code in C or C++, compile it as a Windows DLL, and link to PSIM. There are four exported functions. PSIM simulation engine us three of them, and one is ud by the ur interface.
The three simulation functions are: RUNSIMUSER, OPENSIMUSER and CLOSESIMUSER. The ur interface function is: REQUESTUSERDATA. They are described as below.
RUNSIMUSER:
void RUNSIMUSER(
double t,
double delt,
double *in,
double *out,
void ** ptrUrData,
int *pnError,
char * szErrorMsg)
This function is the only function in the DLL routine that is mandatory. All other functions are optional. This function is called by PSIM at each time step.
The DLL routine receives values from PSIM as inputs, performs the calculation, and nds results back to PSIM. The node assignments are: the input nodes are on the left, and the output nodes are on the right. The quence is from the top to the bottom.
Each parameter is explained as follow.
double t :
(Read only) Time in conds
double delt :
(Read only) Time step in conds
double * in :
(Read only) Array of input values. If the DLL block has three inputs, they are accesd by
in[0], in[1], and in[2]
double *out :四百字日记
(Write only) Array of output values. After calculations are performed, outputs should be
written to this array. If the DLL block has four outputs, they would be accesd by out[0],
out[1], out[2], and out[3]
void ** ptrUrData:
(Read, Write) Pointer of the ur-defined data. For more information, refer to the function
OPENSIMUSER.
int *pnError:
(Write only) On successful return, t pnError to 0. On error, t it to 1.
Example: *pnError = 0; //success
char * szErrorMsg:
(Write only) If there is an error, copy the error message to this string.
Example: strcpy(szErrorMsg, "input 2 can not exceed 50V");
OPENSIMUSER:
void OPENSIMUSER(
const char *szId,
const char * szNetlist,
void ** ptrUrData,
int *pnError,
LPSTR szErrorMsg,
void * pPsimParams)
This function is optional. It is called only once at the beginning of the simulation. It receives information from the DLL routine, and allows the DLL routine to allocate memory for its own u. The parameters are explained as below.
const char *szId:
(Read only) string ID of the DLL block
六大解放const char * szNetlist:
(Read only) Netlist string of the DLL block. The netlist can be viewed from PSIM by
choosing Simulate -> Generate Netlist file -> View Netlist File. The netlist string is a
ries of parameters parated by space. The netlist format for the general DLL block is as
follows:
DLL_EXT
Element name
Number of input nodes
Number of output nodes
Node names of the input nodes
Node names of the output nodes
Full path and file name of the DLL file for this DLL block
Parameters defined and t in the ur interface (if exist)
Full path and file name of Input data file (if exist)
The following is an example of the DLL block netlist string with the name as ”DLL1” and
two input nodes and two output nodes.
DLL_EXT DLL1 2 2 1 2 3 4 C:\psim\pfc_vi_dll.dll
The following is another example of the DLL block netlist string with the name as “DLL2”
and two input nodes, three output nodes, three extra parameters, and an input data file.
DLL_EXT DLL2 2 3 5 6 7 8 9 C:\PSIM\TestBlock.dll 1000 10 90 "C:\"
void ** ptrUrData :
(Read, Write) This is a pointer to the ur-defined data. The memory must be allocated in the
function OPENSIMUSER and freed in CLOSESIMUSER. It is pasd to RUNSIMUSER
on every call. It allows the DLL to manage its own data during the simulation.
Note: This pointer is not the same as the ur- defined pointer in the function
REQUESTUSERDATA. It is not possible to pass a pointer from REQUESTUSERDATA to
any of the simulation functions. They communicate via Netlist line only.
int *pnError:
(Write only) On successful return, t pnError to 0. On error, t it to 1.
属鸡人Example: *pnError = 0; //success
char * szErrorMsg:
(Write only) If there is an error, copy the error message to this string.
Example: strcpy(szErrorMsg, “Input 2 can not exceed 50V");
void * pPsimParams:
(Read only) A pointer to the following structure:
struct EXT_FUNC_PSIM_INFO
{
m_szPsimDir[260];
char
m_szSchDir[260];
char
m_szSchFileName[260];
char
网购团购网};
where each structure member is defined as follows:
char m_szPsimDir[260] : PSIM folder
char m_szSchDir[260] : Folder containing the schematic file (*.sch)
char m_szSchFileName[260] : Full path and file name of the schematic file CLOSESIMUSER:
void CLOSESIMUSER(
const char *szId,
void ** ptrUrData)
This function is optional. It is called only once at the end of the simulation. Its main purpo is to allow DLL to free any memory or resources that it has allocated.
const char *szId :
(Read only) String ID of the DLL block
void ** ptrUrData:
(Read, Write) Pointer to the ur-defined data. For more information, refer to the function
OPENSIMUSER.
REQUESTUSERDATA
void REQUESTUSERDATA(
int nRequestReason,
int nRequestCode,
int nRequestParam,
void ** ptrUrData,
int * pnParam1,
int * pnParam2,
char * szParam1,
char * szParam2)
This function is optional. It handles the ur interface with PSIM. It is called by PSIM when the general DLL block element is created, or its properties are modified in the property box. The parameters are described as follows.
int nRequestReason :
It describes the ur action when this function is called. The possible values are:
ACTION_DLL_SELECTED A new DLL block is placed on the schematic
and this DLL is lected.
ACTION_ELEMENT_LOAD A schematic file with DLL blocks is being
loaded, or being pasted as part of the
copy/paste operation.
ACTION_ELEMENT_SAVE A schematic file with DLL blocks is being
saved or a buffer (Copy/paste operation) ACTION_INPUTFILE_CHANGED A new input file is lected.
ACTION_PARAMETERS_CHANGED Parameters are changed in the property dialog
box.
ACTION_ELEMENT_DELETE An element is being deleted or a file is being
clod.
Example: When a ur places a DLL block from the library on to a schematic, after the DLL file name is defined for this block, the function REQUESTUSERDATA will be called and the parameter nRequestReason will be t to ACTION_DLL_SELECTED.
int nRequestCode :
怎么调整行距
It describes the information that is being requested from DLL. The possible values are:
REQUEST_BEGIN:
A new request is initiated. The values of pnParam1, pnParam2, szParam1, and
szParam2 depend on the value of nRequestReason.
REQUEST_END:
Request is finished.
pnParam1: Ignored
pnParam2: Ignored
szParam1: Ignored
szParam2: Ignored
REQUEST_PARAM_COUNT:
Request the number of parameters that will be displayed on the right side of the
property box, between 0 and 10.
pnParam1(Read, Write): Number of parameters.
pnParam2(Read, Write): If an input data file is required, t it to 1, otherwi t it
to 0.
szParam1(Read, Write): File open dialog filter for the input data file. It must
conform to the file open dialog filter format. The following is a properly
背山formatted filter string:"All Files|*.*|Image files|*.jpg;*.bmp;*.gif|Text
Files|*.txt||". The default value for the filter is: "All Files|*.*||"
szParam2(Read only): String ID associated with the element.
Example: The following code is a possible respon to this request. It asks for three
parameters and the input file with extension “aaa”.
*pnParam1 = 3; // 3 parameters
*pnParam2 = 1; // Input Data File is required
strcpy(szParam1, "MyProgram Files|*.aaa|All Files|*.*||"); //File Filter REQUEST_DATAFILE_INFO:
Request information of the input data file.
pnParam1(Read, Write): If t to 1, a check box will be displayed in the property box. When the check box is checked, the file path will be displayed in the
schematic.
pnParam2: Ignored
szParam1(Read, Write): Label that is displayed in the property box. The length is
20 characters maximum. The default value is "Input Data File".
szParam2(Read Only): Full path and file name of the lected file.
Example: The following code changes the label from the default value of "Input
Data File" to "MyProgram data File", and requests a check box for the data file.
strcpy(szParam1, "MyProgram data File");
*pnParam1 = 1; // Show Display check box
REQUEST_PARAM_INFO:
Request information on each parameter.
nRequestParam(Read only): Zero bad parameter index
pnParam1: If t to 1, a check box will be displayed in the property box. When the check box is checked, the parameter value will be displayed in the
schematic.
pnParam2 : ignored
szParam1(Read, Write): Label that is displayed in the property box. The length is 20 characters maximum.
szParam2(Read, Write): The parameter value. The length is 50 characters maximum.
Example: The following code ts the labels of 3 parameters and ensures that
Parameter 1 is an integer between 3 and 10.
switch(nRequestParam)
{ //Three Parameters expected
ca 0:
strcpy(szParam1, "Moving Avg. Samples");
*pnParam1 = 1; // Show Display check box
//verify the value
nVal = atoi(szParam2);
if( nVal < 3 )
{
nVal = 3;
}
if( nVal > 10 )
{
nVal = 10;
}
itoa( nVal, szParam2, 10);
break;
ca 1:
strcpy(szParam1, "Multiplier");
*pnParam1 = 1; // Show Display check box
if( strlen(szParam2) == 0 )
{
strcpy(szParam2, "3.14");
}
break;
ca 2:
strcpy(szParam1, "Title");
*pnParam1 = 0; // Do not Show Display check box
break;
default://Only expecting three parameters
break;
}
REQUEST_IN_OUT_NODES:
Get and t the number of input and output nodes
pnParam1(Read, Write): Number of input nodes.
pnParam2(Read, Write): Number of output nodes.
szParam1: Ignored
szParam2: Ignored
The values can be modified at any time and the changes will be reflected
immediately in the schematic window.
Example: The following code ts the number of input nodes to 1 and the number of output nodes to 2:
*pnParam1 = 1; // one input node
*pnParam2 = 2; // two output nodes
REQUEST_INPUT_NODE_INFO:
Request information on each input node.
nRequestParam: Zero bad node index
pnParam1: Ignored.
pnParam2: Ignored.
szParam1(Read, Write): Node label. The length is 20 characters maximum.
szParam2: Ignored
Example: The following code ts the label of the first input node.
switch(nRequestParam)
{
/
/One input node
ca 0:
strcpy(szParam1, "in1");
break;
风水学书籍default:交通安全黑板报
break;
}
REQUEST_OUTPUT_NODE_INFO
Request information on each output node.
nRequestParam: Zero bad node index
pnParam1: Ignored.
pnParam2: Ignored.
szParam1(Read, Write): Node label. The length is 20 characters maximum.
szParam2: Ignored
For each output node you may change its label at any time.