SimulIDE Knowledge Base
– SCRIPTED COMPONENTS –
(This feature is not available in version 1.0.0)
Scripted components are a type of Modular Components, with an extra file containing a script to define the behaviour of the device.
Creating an Scripted component involves these steps:
- Creating Package File.
- Creating Definition file.
- Creating Script file.
- Creating component folder with all files.
- Add to component list.
Creating Definition file.
This are xml files describing which kind of component it is and the parts or modules it contains.
Root element:
The principal characteristics are defined in the root element.
The tag name can be anything you want, typical names are: “mcu” for microcontrollers or “iou” meaning Input/Output Unit.
Possible fields in the root element are the same for all Modular Components
<iou name="comp_name" core="scripted" script="file.as" >
</iou>
We can see that core is set to “scripted” , so this is an Scripted component, and the script is in “file.as” .
These are some modules and features you can add to a Scripted Component:
Properties:
You can add properties to configure some settings in your component.
<iou name="comp_name" core="scripted" script="file.as" >
<propertygroup name="group name">
<property name="Prop1" type="double" />
<property name="Prop2" type="uint" />
</propertygroup>
</iou>
We can see that there is a property group with 2 properties.
The property group has a field name, this is the name shown in the property dialog.
Each property has 2 fields:
- name: property name.
- type: data type ( bool, double, int, uint, string ).
The script must implement property getters and setters:
void setProp1( double val )
double getProp1()
void setProp2( uint val )
uint getProp2()
These getters and setters are called from the Properties dialog in the GUI.
Typically the script has a variable to hold the property value.
When the setter is called, the script can apply any constrains to the value (like maximum or minimum value) and store it in that variable.
When the getter is called, the script typically returns the value of that variable.
IO Ports:
Definition file:
<iou name="comp_name" core="scripted" script="file.as" >
<ioport name="PORTA" pins="A,B,C,D,E,F" />
</iou>
Each port has 2 fields:
- name: property name.
- pins: list of pin names separated by commas.
Communications:
You can add some modules for communications.
UART:
<iou name="comp_name" core="scripted" script="file.as" >
<uart/>
</iou>
SPI:
<iou name="comp_name" core="scripted" script="file.as" >
<spi/>
</iou>
TWI:
<iou name="comp_name" core="scripted" script="file.as" >
<twi/>
</iou>
Display:
Console:
Creating Script file.
This is a program written in The script language describing the behavior of the component.
Script files must have extension .as and use the name defined in the definition file.
Script functions called from C++.
These are functions you can implement in the script.
void setup()
void reset()
void voltChanged()
void updateStep()
void runEvent()
void extClock( bool clkState )
int getCpuReg( string name )
string getStrReg( string name )void command( string c )
void setLinkedValue( int val, int i )
void setLinkedString( string str, int i )
void INTERRUPT( uint vector )
Available C++ functions to call from the script.
Debug messages:
void print( string &msg )
Component:
IoPort@ getPort( string port )
IoPin@ getPin( string pin )
McuPort@ getMcuPort( string port )
McuPin@ getMcuPin( string pin )
void addCpuReg( string name, string type )
void addCpuVar( string name, string type )
void toConsole( string msg ) // To Delete
void showValue( string val )
void addEvent( uint time_ps )
void cancelEvents()
uint64 circTime()
int readPGM( uint addr )
void writePGM( uint addr, int val )
int readRAM( uint addr )
void writeRAM( uint addr, int val )
int readROM( uint addr )
void writeROM( uint addr, int val )
void INTERRUPT( uint vector )
// For linked Components:
// index: index on Linked component in the list
int index, string name )
string getPropStr( void setLinkedValue( int index, int val, int i )
void setLinkedString( int index, string val, int i )
IoPort@
void setPinMode( uint mode )
uint getInpState()void scheduleState( uint32 state, uint64 time )
void setOutState( uint state )
void changeCallBack( eElement@ e, bool en )
void addSequence( array<array<uint64>>@ t )
void trigger( uint n ) // Trgger sequence
IoPin@.
void setPinMode( uint mode )
void setOutState( bool state )
void scheduleState( bool state, uint64 time )
void setStateZ( bool z )
bool getInpState()
double getVoltage()
void setVoltage( double volt )
void setOutHighV( double volt )
void setImpedance( double imp )
void changeCallBack( eElement@ e, bool en )
bool isConnected()
McuPort@.
void controlPort( bool outCtrl, bool dirCtrl )
void setDirection( uint dir )
uint getInpState()void setOutState( uint state )
McuPin@.
void setDirection( bool dir )
void setPortState( bool state )
void controlPin( bool outCtrl, bool dirCtrl )
void setExtInt( uint mode )
void setPinMode( uint mode )
bool getInpState()
void setOutState( bool state )
double getVoltage()
void setVoltage( double volt )
void changeCallBack( eElement@ e, bool en )
Resources:
- Forum discussion,
- Video (english): Creating Scripted Components Part I
- Video (spanish): Creando componentes script en SimulIDE
- Scripted Dev.
#tutorial