# C-script vs DLL vs PIL

**URL:** <https://forum.plexim.com/t/c-script-vs-dll-vs-pil/794>\
**Category:** PLECS\
**Tags:** c-script, pil\
**Created:** [July 11, 2020, 2:25am UTC](https://forum.plexim.com/t/c-script-vs-dll-vs-pil/794 "2020-07-11T02:25:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinath](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@srinath](https://forum.plexim.com/u/srinath)\
**Post date:** [July 11, 2020, 2:25am UTC](https://forum.plexim.com/t/c-script-vs-dll-vs-pil/794/1 "2020-07-11T02:25:22Z")

</div>

Hi

I have a reasonably complex C-code written for STM32Fxxx. It’s an implementation for a sensorless FOC observer for position and speed

I would like to interface this with the PMSM model example in PLECS and see the performance with respect to the ‘truth’.

I have used C-Script a couple of times, but i think this approach would be messy, because

1. I have multiple header files included in the C-Code

2. The code is written to use CMSIS ARM\_DSP for matrix operations. (Sure those functions could be rewritten but it’ll be time consuming and messy)

I guess if somehow all the header files (including the suitably modified ARM stuff) were copied into the code declarations (It would be one massive 5K line long code declaration) and the initialization routine was copied to the (start function code), things could work, but it’s an awful lot of work and if a bug is discovered, corrected it in the C-Script and making equivalent changes in the embedded code is again prone to errors.

So i looked at the DLL option..

I don’t use Windows (Only Linux) and the example uses Visual Studio and seems complicated, so i kind of ruled that out.

So i was wondering if the PIL option is best(only option) suited for this problem ?

---

<div class="post-metadata">

**Author:** ![Hannes](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@Hannes](https://forum.plexim.com/u/Hannes)\
**Post date:** [August 21, 2020, 10:12am UTC](https://forum.plexim.com/t/c-script-vs-dll-vs-pil/794/2 "2020-08-21T10:12:52Z")

</div>

I had a similar Problem where DLL didn’t work because im on Linux, C-scripts were complicated and the plecs documentation unreliable.  
I switched to Matlab/Simulink and used plecs Blockset as Matlab is much more flexible with interfaces to other code. Maybe thats something to consider for you aswell.

---

<div class="post-metadata">

**Author:** ![srinath](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@srinath](https://forum.plexim.com/u/srinath)\
**Post date:** [August 21, 2020, 11:31pm UTC](https://forum.plexim.com/t/c-script-vs-dll-vs-pil/794/3 "2020-08-21T23:31:32Z")

</div>

Hi

I got DLL working on Linux with PLECS. It takes a little bit of work, but is the best bet IMO. I have it working for a variety of combinations (Inputs, outputs, parameters, initialization functions, reset routines etc).

You have to link to the .so file if you are using Linux and not a “dll”, but be sure to include the file “Dllheader.h” in your build process.

You may find the attached makefile useful.

Got C-Scripts working too. But that was real easy, just follow the example in the documentation and tweak it slowly from there. Remember that simulationTime is a macro that is available to C-Script.

[makefile](https://forum.plexim.com/uploads/short-url/ypEb4gUl1nAYJozFAIY6cNMbbm7) (875 Bytes)

---

<div class="post-metadata">

**Author:** ![Hannes](https://avatars.discourse-cdn.com/v4/letter/h/f0a364/32.png) [@Hannes](https://forum.plexim.com/u/Hannes)\
**Post date:** [August 23, 2020, 5:56pm UTC](https://forum.plexim.com/t/c-script-vs-dll-vs-pil/794/4 "2020-08-23T17:56:14Z")

</div>

Thanks a lot for this solution and the make file!

---

<div class="post-metadata">

**Author:** ![Kris\_Eberle](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/kris_eberle/32/6_2.png) [@Kris\_Eberle](https://forum.plexim.com/u/Kris_Eberle)\
**Post date:** [August 24, 2020, 2:04pm UTC](https://forum.plexim.com/t/c-script-vs-dll-vs-pil/794/5 "2020-08-24T14:04:44Z")

</div>

Nice work @srinath!
