Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Scripted Components

3 posters

Go down  Message [Page 1 of 1]

1Scripted Components  Empty Scripted Components Fri Aug 26, 2022 5:15 pm

arcachofo

arcachofo

EDIT:
Here I will add some links to tutorials and other  resources.

- List of functions and other information.

- Video-tutorial part 1.


----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

I did some progress in  this kind of components (Rev 1333).
The idea came from this discussion:
https://simulide.forumotion.com/t543-feature-i2c-spi-master-template-component#2929

Basically is about using the "MCU framework" to create any kind of components.
Components are created in xml files and the "behavior" is implemented in JavaScript.

Right now it is a very basic implementation, still a lot of work to do, but it is already possible to do something.
Communication modules and other peripherals are not usable yet, but in the future it will be possible to add I2C, SPI, Uart, One-wire, Timers, etc.

There are certain limitations, but many kind of components are possible.
For example you can implement existing CPUs, or design your instruction set and create a custom CPU.
Any kind of combinational or sequential Logic, processing analog signals...

I did a short video trying to show how it works with some simple examples.
Sorry for my english and the sound quality...



Last edited by arcachofo on Fri Aug 25, 2023 1:28 pm; edited 7 times in total (Reason for editing : Clarify title)

TimFisch, Sergei, KerimF and Popopo like this post

2Scripted Components  Empty "Custom" Components Tue Aug 30, 2022 10:08 pm

arcachofo

arcachofo

I have been working in this these days and found some problems:

QtScript is already deprecated and should be changed to QJSEngine, so I implemented this in QJSEngine and didn't like it at all.
QtScript is slow, and QJSEngine should be quite faster, But in my test it was even slower, not sure if I was not doing it correctly, but in any case QJSEngine requires Qml, which is a big NO.

So I tested LUA as suggested by dvarkin.
LUA is quite fast, simple and light, but it is not so easy to integrate with C++ and is very limited in many aspects.
Syntax is something like Basic, dynamic types and limited in data structures.
As an example this is the same script used in the last circuit in the video but in LUA:

Code:
-- PinModes: undef_mode=0, input, openCo, output, source

self = 0

InputPin  = -1
outputPin = -1
clockPin  = -1

PC = 0
cycles = 0
amply = 0

function setup( ref )

    print("LUA Signal setup ")
    self = ref;
    
    InputPin  = getPin( self, "In")
    outputPin = getPin( self, "Out")
    clockPin  = getPin( self, "Clk")
end

function reset()

    print("LUA resetting Signal")
    
    setPinMode( self, InputPin, 1 )     -- Input
    setPinMode( self, clockPin, 1 )     -- Intput
    setPinMode( self, outputPin, 3 )    -- Output
    setPinVoltage( self, outputPin, 0 )
    
    PC = 0
    cycles = 1
end

function extClock()
    
    if cycles == 0 then

        cycles = readPGM( self, PC )
        PC = PC+1
        
        if cycles == 0 then PC = 0
        else
            amply = readPGM( self, PC )
            PC = PC+1
        end

    else cycles = cycles-1
    end
    
    local input = getPinVoltage( self, InputPin )
    local output = input*amply/255
    
    setPinVoltage( self, outputPin, output )
end

Then I found AngelScript
This is like C/C++, not only the syntax, it is Object Oriented, Static types, etc.
So it is much more powerful, also very fast but a bit slower than LUA.
And the source code is around double of LUA.

Again the same script in AngelScript:

Code:
// PinModes: undef_mode=0, input, openCo, output, source

int InputPin  = -1;
int outputPin = -1;
int clockPin  = -1;

uint PC = 0;
int cycles = 0;
int ampli = 0;

void setup()
{
    print("AS setup()");
    
    InputPin  = component.getPin("In");
    outputPin = component.getPin("Out");
    clockPin  = component.getPin("Clk");
}

void reset()
{
    print("AS reset()");
    
    component.setPinMode( InputPin, 1 );     // Input
    component.setPinMode( clockPin, 1 );     // Intput
    component.setPinMode( outputPin, 3 );    // Output
    component.setPinVoltage( outputPin, 0 );
    
    PC = 0;
    cycles = 1;
}

void extClock()
{
    if( cycles == 0 )
    {
        cycles = component.readPGM( PC++ );
        
        if( cycles == 0 ) PC = 0;
        else              ampli = component.readPGM( PC++ );
    }
    else cycles--;
    
    double input = component.getPinVoltage( InputPin );
    double output = input*ampli/255;
    
    component.setPinVoltage( outputPin, output );
}

I would like to know your opinions about this: do you prefer LUA or AngelScript?
Or any other option?

3Scripted Components  Empty Re: Scripted Components Thu Sep 08, 2022 7:54 pm

Serg77m



arcachofo wrote:Or any other option?
tcc?
It's very small C compiler to native x86 code.
Can be used as a library and may compile directly in memory.
The code may not be too optimal, but it should be faster than any scripting language.

4Scripted Components  Empty Re: Scripted Components Thu Sep 08, 2022 8:18 pm

arcachofo

arcachofo

tcc?
It's very small C compiler to native x86 code.
Can be used as a library and may compile directly in memory.
The code may not be too optimal, but it should be faster than any scripting language.
That's an interesting option.
Downsides I see:
- It's C, so we should use proxy functions or something to interface with C++ (same limitation than LUA).
- Not sure how to use it, seems than it can create executables ( with main() ), but how to call TCC functions and how TCC can call simulide functions?.

5Scripted Components  Empty Re: Scripted Components Fri Sep 09, 2022 9:06 am

Serg77m



arcachofo wrote:That's an interesting option.
Downsides I see:
- It's C, so we should use proxy functions or something to interface with C++ (same limitation than LUA).
- Not sure how to use it, seems than it can create executables ( with main() ), but how to call TCC functions and how TCC can call simulide functions?.
The sample program is compiled as a library and does not contain main(). The "host" program calls foo() function from the "guest" program. And from the "guest" function foo(), the "host" function add() is called.

6Scripted Components  Empty Re: Scripted Components Fri Sep 09, 2022 8:57 pm

arcachofo

arcachofo

The sample program is compiled as a library and does not contain main(). The "host" program calls foo() function from the "guest" program. And from the "guest" function foo(), the "host" function add() is called.
Thanks, I will have a look.

7Scripted Components  Empty Re: Scripted Components Tue Nov 29, 2022 9:06 pm

arcachofo

arcachofo

One feature missing for this components as well as Subcircuits was a folder in the user space to add custom components.
Now you can add add your components in user folder "addons" (trunk Rev 1417).
To find where this folder is located in your system, go to File Explorer->Settings.
The path to that folder is shown there.

This folder works the same as the "data" folder in simulide, but your components will stay there if you are using a new version/build.

Scripted Components  Addons10

KerimF likes this post

8Scripted Components  Empty Re: Scripted Components Fri Feb 24, 2023 4:45 pm

arcachofo

arcachofo

For convenience now the User Data Folder is configurable from the Settings Dialog.
There you can add your subcircuits, scripted, etc. and always access them if you change simulide version or whatever.
In File Explorer you will find a new bookmark "User Data":

Scripted Components  Addons11


Scripted Components  Addon210

9Scripted Components  Empty Re: Scripted Components Mon Jul 10, 2023 2:01 am

arcachofo

arcachofo

I'm adding some resources at the first post:

- Page with some information.
- Video tutorial creating a basic scripted component.


10Scripted Components  Empty Re: Scripted Components Mon Jul 10, 2023 3:38 pm

KerimF

KerimF

Adding explanations below the video is a very good idea (though it takes you more efforts and time).
For instance, is it possible to gather all these explanations on a text file for download? Now, I try to copy them one by one, just in case I will need to review them (without playing again the video).

On the video, I am at 2m:56s.
By mistake, I closed the configuration dialog of the pin before changing its name. I couldn't find a way to edit the pin. So, I had to delete the pin and the package and restart from step 1 by getting a package and defining its size...

11Scripted Components  Empty Re: Scripted Components Mon Jul 10, 2023 4:00 pm

KerimF

KerimF

Now I am at 3m:39s

May I suggest inserting the name of the package automatically since it has to be the same of its folder 'always'?
But perhaps it is not the case 'always'.

12Scripted Components  Empty Re: Scripted Components Mon Jul 10, 2023 4:46 pm

arcachofo

arcachofo

@KerimF:

I'm adding some information at the page linked in the first post.

The video is about scripted components.
Packages are used in subcircuits, MCUs, MPUs and scripted, so it is not specific to scripted.
Packages are explained in a tutorial about creating subcircuits: https://www.simulide.com/p/new-subcircuits.html
That tutorial is a bit outdated now, but you can get the idea.

For package name there are several options:
In properties you can leave it empty for no name, set a name or set the name to: "Package" to use the name of the component (the default).

BUT... in the revision I just uploaded, package pins have changed and it is easier now:
- Now you don't right-click at the edge of the pin, but in the pin itself.
- You don't need to right-click->Move_Pin, just grab the pin and move it normally.

13Scripted Components  Empty Re: Scripted Components Mon Jul 10, 2023 4:59 pm

KerimF

KerimF

Sorry, do you mean "Creating Scripted Components (Part 1) SimulIDE dev." which I am watching now is outdated?

Fon instance, I am at 6m:17s.
I re-opened simulIDE but there was no sign of the category 'test' (and the component 'Amplifier').

The new 3 files are in:
C:\Users\TOSHIBA\AppData\Local\simulide\addons\test\Amplifier
(Windows 7, 32bit).

I certainly missed something. Soon later, I will try to repeat the steps.

14Scripted Components  Empty Re: Scripted Components Mon Jul 10, 2023 5:08 pm

arcachofo

arcachofo

Sorry, do you mean "Creating Scripted Components (Part 1) SimulIDE dev." which I am watching now is outdated?
No, not the video, this tutorial:
Packages are explained in a tutorial about creating subcircuits: https://www.simulide.com/p/new-subcircuits.html
That tutorial is a bit outdated now, but you can get the idea.

Fon instance, I am at 6m:17s.
I re-open simulIDE but there was no sign of the category 'test' (and the component 'Amplifier').

The new 3 files are in:
C:\Users\TOSHIBA\AppData\Local\simulide\addons\test\Amplifier
(Windows 7, 32bit).

I certainly missed something. Soon later, I will try to repeat the steps.
Use the last revision, I just uploaded it:
https://simulide.forumotion.com/t550-simulide-trunk-tester-builds

15Scripted Components  Empty Re: Scripted Components Mon Jul 10, 2023 5:21 pm

KerimF

KerimF

arcachofo wrote:
Use the last revision, I just uploaded it:
https://simulide.forumotion.com/t550-simulide-trunk-tester-builds

Thank you, I will.

16Scripted Components  Empty Re: Scripted Components Mon Jul 10, 2023 5:42 pm

arcachofo

arcachofo

Fon instance, I am at 6m:17s.
I re-open simulIDE but there was no sign of the category 'test' (and the component 'Amplifier').
I forgot to mention:
The best is to use the last revision, but it should work with the previous one if the user folder is not empty: there is some xml file in it.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum