03-26-2014 10:59 AM
Hello
For a project, I would like to use the python scripting module of dasylab 13. I got it to work for simple functions such as y=f(x), where i have one input and one output.
The next step in order to get to where i want to be with my script is using a single input and generating two outputs.
I defined it in the "predefined settings" that pops up first. The module created looked as it should, having one input and two outputs. However, when I wanted to edit the script (and double clicked the module) the module went back to having one input and one output.
I searched the help and found the section "channel assignment constants". There describe the various constants, which should have been set in predefined settings. In my case it is CR_1_2.
It also states to setup the meta data in the SetupFifo tab.
Now here is my problem: How should i change the SetupFifo tab?
I tried the command:
self.SetChannelRelation(channel_no, Ly.CR_1_2)
Unfotunately this didn't work, which doesn't supprise me, as I made this command up, based on the examples in the help file on the SetupFifo tab. Those are, however, for SetChannelFlags and SetChannelType, which I don't think I need yet...
Has anyone experienced a similar problem? I also installed a trial version on another computer to check if it works there (it doesn't).
Or does someone know a method to find out how to be able to change inputs and outputs the way i want?
Every help will be greatly appreciated.
Sincerely, Jarno
03-27-2014 04:06 AM - edited 03-27-2014 04:09 AM
You do not need to set the channel relation for "simple" channel relation like 1:2, 2:1, etc.
Just set the relation you want in the configration dialog that open when you drop a script module into to worksheet.
The channel relation and their python constants have nothing to do with the amount of inputs and outputs of a script module.
The channel relation tells the "DASYLab core" how to guide meta data (channel names, units, etc) through a module.
In function "DlgInit" you have to tell DASYLab how many inputs and outputs your module should have.
Your module should have 2 outputs for each input: this combination of input and outputs is called a "channel".
Because one channel has 2 outputs, the module can have max. 8 channels only.
The dialog with the channelbar "thinks" in channels, but DASYLab "thinks" in connectors (connectors are inputs/outputs).
So, you are responsible to translate "channels" in "connectors" and vice versa
In DlgInit you can ask DASYLab about the amount of inputs and outputs.
self.NumInChannel <-- amout of connectors on modules left side
self.NumOutChannel <-- amount of connectors on the right side
self.DlgNumChannels <-- amount of activated channels in the dialog (something between 1 and DlgMaxChannels)
Your module's channels have 1 input, 2 outputs each, so you can write either
self.DlgNumChannels = self.NumOutChannel / 2
or
self.DlgNumChannels = self.NumInChannel
If the module has 3 input and 6 outputs, the dialog will get 3 channels.
In DlgOk you need to translate the amount of channels into the correct amount of connectors (inputs/outputs):
For "one channel = 1 input + 2 outputs" this is:
self.SetConnectors( self.DlgNumChannels, self.DlgNumChannels * 2 )
DlgInit self.DlgNumChannels = self.NumInChannel # or: self.DlgNumChannels = self.NumOutChannel / 2 self.DlgMaxChannels = 8 # or Ly.MAX_CHANNELS/2
[...] DlgOk
[...] self.SetConnectors( self.DlgNumChannels, self.DlgNumChannels * 2 )
03-27-2014 11:06 AM
Thank you very much, this worked fine.
On another note, my dasylab version is crashing from time to time, when i have the scripting module open. Has anyone else experienced this problem or knows how to fix it? I lost one hour of coding today because of this...
I'm using DASYlab 13.0 on Windows 7.
03-28-2014 02:26 AM - edited 03-28-2014 02:27 AM
Ja, use the script module's external editor mode.
Save the "embedded" script to a file.
Open this file with Notepad++, IDLE, or something else that supports syntax highlighting.
Edit the file.
When done, load the file into the script module.
If the script is ok, the script is in the module..
If there's an error, it will be announced.
The important part: the script code is left unchanged and is still in the py-file even when the worksheet/module is damaged.
03-28-2014 03:32 AM
Well I guess that does help in not losing any code, but i'm affraid of dasylab crashing during measurements... Has that happened to you as well, or just while writing/compiling? It is very important for my measurements to work stable at all times.
03-28-2014 03:45 AM
Ok, using an external editor is helpful only when you create the module.
I think, that it's virtually impossible for DASYLab to "catch" ever possible error in malfunctioning code in the script module.
What' script causes trouble?
03-28-2014 04:10 AM
I just experienced dasylab to crash completely, when i was trying around with the script module. Now what i want to know is, if it works reliably with working code. And also, what is the reason that dasylab crashes? Mostly it just gives out an error if the code is malfunctioning...
03-28-2014 04:31 AM
I 've made lots of script modules that work like a charm witout crashing a running DASYLab experiment.
During the process of creation - i keep killing my DASYLab constantly. But that's my fault, not DASYLab's. 😉
06-27-2014 07:32 AM
... while creating and debugging a python script it's possible to create situations that are invalid or simply illegal.
Some of those may cause DASYLab to crash. For example, I crashed when trying to call a Python function that was a wrapper around a DLL... it was linked using a different version of python, and so it failed, with annoying results.
I try to always use exception handling now...
try:
blah blah
except:
recover safely.
DASYLab itself is not a Python interpreter, so it can only give rudimentary error messages or give you messages from Python itself.
As with DASYLab, work incrementally, and get bits working before adding onto it. I get the channel handling working first, since that's the most "twiddlely", then the parameters, and then the processing. Save working revisions so that you can always go back if it should fail. I keep getting into scenarios where the bug in the python code won't let DASYLab load the script, so I have to start over or revert to the previous working version.