Hello
I am new to Igor Pro and need to programm a software to control a new self made device with a relay card.
I hope you can help me.I already watched the guide me tour and the tutorial videos.
A major part of my software is to check continuously if the current measured value of an measuring instrument (last value saved in a global variable) matches the value range which I set before.
By problem is to find a way that the software checks this each second. Is there a built. Is there built-in function to repeat a function with a fixed interval?
My next issue is how to control a realy card which is connected by a RS-232 serial port. I am not sure how to approch this and am glad for advide where to read more about it. Because in the manual I only read about data aquisition.
Thank you in advance for your help.
You might want to look into the use of a background task.
The task can be run a defined interval. For example I just wrote one to measure current from a Keithley meter via RS232. I wanted to use a background control so I retained control of the interface to allow the user to stop the measurement.
Andy
If you have not already done it, choose Help->Getting Started and do the guided tour. It is indispensable.
There are two ways to control a serial port in Igor. To learn about them, execute this:
DisplayHelpTopic"VDT2 - Serial Port Support" DisplayHelpTopic"VISA XOP"
VDT2 is simpler. VISA is more flexible.
To learn about background tasks, execute this:
DisplayHelpTopic"Background Tasks"
Before you start with background tasks, you need to create a simple Igor function that can talk to your device, and become comfortable with Igor programming.
To learn about programming, execute:
DisplayHelpTopic"Programming Overview"
You should read the entire Programming help file. It will take some iterations of reading and experimentation before it all sinks in.
There is a demo experiment that shows how to do data acquisition using a background task. Choose File->Example Experiments->Programming->Slow Data Acq. This is overkill for your purposes as it does the acquisition using a pre-emptive thread and uses the background task to transfer data from the thread into the main Igor data hierarchy.
VISA can be called from a pre-emptive thread in Igor Pro 8 or later. VDT2 can not be called from a pre-emptive thread.
I recommend that you NOT mess with pre-emptive threads until you have something that works in the main thread and you are comfortable with Igor programming. Even then, the pre-emptive thread is probably overkill for your task.
Thank you for your replies.
Concerning background tasks, would it be too much for the software if up to 16 background tasks are running?
I need to repeat a function each second, but the function itself just needs to read out minimum and maximum of a set range and check if a global value is within that range.
Hi,
The background task is an advanced topic and is combination of two parts and understanding them may avoid the need for multiple background tasks.
First the task itself defines when a referenced procedure is run and what procedure to run.
The second part is what is the details of the procedure. For your case for example if you need 12 things done every time (say every 1 sec) then you need only one ctrlNamedBackground and the background task would do all 12 things. Such as calculating min, max, ave..... Just be aware that all the actions need to be complete before the task is called again.
From the manual:
Background Task Example #1 In this case the control of the timing is handled by a ctrlNamedBackground called "Test" and it is called every 2 seconds. When it is called it then executes the function TestTask(s). This is where all the details of what you want to happen occurs.
You create and control background tasks using the CtrlNamedBackground operation. The main parameters of CtrlNamedBackground are the background task name, the name of a procedure to be called periodically, and the period.
Andy
Here is a simple example again from the manual:
Function TestTask(s)// This is the function that will be called periodically STRUCT WMBackgroundStruct &s
Function StartTestTask() Variable numTicks = 2*60// Run every two seconds (120 ticks) CtrlNamedBackground Test, period=numTicks, proc=TestTask CtrlNamedBackground Test, start End
Function StopTestTask() CtrlNamedBackground Test, stop End
July 8, 2018 at 06:49 am - Permalink
DisplayHelpTopic "VISA XOP"
July 8, 2018 at 09:54 am - Permalink
July 9, 2018 at 03:15 am - Permalink
STRUCT WMBackgroundStruct &s
Printf "Task %s called, ticks=%d\r", s.name, s.curRunTicks
return 0 // Continue background task
End
Function StartTestTask()
Variable numTicks = 2 * 60 // Run every two seconds (120 ticks)
CtrlNamedBackground Test, period=numTicks, proc=TestTask
CtrlNamedBackground Test, start
End
Function StopTestTask()
CtrlNamedBackground Test, stop
End
July 9, 2018 at 08:30 am - Permalink