12-05-2013 11:44 AM
The help says:
Function niDCPower_SetSequence(vi As ViSession, channelName As ViString, values As ViReal64, sourceDelays As ViReal64, size As ViUInt32) As ViStatus
Member of niDCPower.Functions_Source
Set Sequence
In above function, the input values (values of the sequence to set) and sourceDelays (delay of each sample of the sequence) should be array or double? I tried both, but neither works. Below is my code:
....
vistat = niDCPower_Abort(session)
vistat = niDCPower_ConfigureSourceMode(session, NIDCPOWER_VAL_SEQUENCE)
vistat = niDCPower_ConfigureOutputFunction(session, chan, NIDCPOWER_VAL_DC_VOLTAGE)
vistat = niDCPower_ConfigureSense(session, chan, NIDCPOWER_VAL_LOCAL)
vistat = niDCPower_ConfigureVoltageLevelRange(session, chan, 10#)
vistat = niDCPower_ConfigureCurrentLimit(session, chan, NIDCPOWER_VAL_CURRENT_REGULATE, 2)
Dim x(), dt(), Vout() As Double
ReDim x(nStep - 1)
ReDim dt(nStep - 1)
For i = 0 To nStep - 1
x(i) = x0 + CDbl(i) * dx
dt(i) = dt0
Next
vistat = niDCPower_SetSequence(session, chan, x(), dt(), nStep)
vistat = niDCPower_Initiate(session)
...
I know... it is VB6... But we have to use it for now for some reasons. The program sequence is a direct tranlate from NI's example code in C#.
I also tried putting SetSequence into for loop and load double(x) and double(dt) every run. Still not working.
12-05-2013 12:30 PM
here is error message when i use array in
12-05-2013 01:09 PM
SetSequence expects an array of doubles. If you call it a second time, the previous values will be overwritten.
What do you mean by "it doesn't work"? Are you getting an error? Are you not seeing the output you are expecting?
It's been a while since I've used VB6 so my syntax is a bit rusty, but what you have appears correct to me without trying it.
12-05-2013 03:46 PM - edited 12-05-2013 03:53 PM
Thanks! I uploaded the error window in an earlier reply. Actually the program can be compiled. But when the program run into vistat = SetSequence(session, chan, x(), dt, nStep), the error window pops up and x() is higlighted. Looks to me it is very likely the interface between main prgram and dll is wrong.
BTW, I tried SetSequence(session, chan, x, dt, nStep) instead of x(). (Here x is still an array of double) Same thing.
12-05-2013 04:00 PM
So, one thing to try, if you could.
I believe that you are declaring x() as variant because you're not specifying it's type (or of dt()) - only the type of Vout().
Try
Dim x() As Double, dt() As Double, Vout() As Double
12-05-2013 04:07 PM
Nope... Same thing. But it is good to know there is a difference. Thanks!
12-06-2013 12:43 PM
hxu,
Have you tried declaring the Values and sourceDelays arrays in the ViReal64 datatype instead of Doubles? I don't have a system set up that can run VB6 at the moment to try it out myself, but I am curious if this would solve the issue for you.
12-06-2013 07:25 PM
Yes, I tried decalring the array to be VIReal64, still not working. Only if I set values and delays to a non-array value, will no error pops up. But this definitely won't "set a sequence", right?
12-10-2013 02:46 PM
Hi hxu,
Which of our examples did you base this code on?
Thanks!
12-10-2013 04:35 PM
Never mind, We found the solution ourselves:
In calling this function, one need put in first element of the array to set. In my case (see the first post), the change is:
vistat = niDCPower_SetSequence(session, chan, x(0), dt(0), nStep)
I guess the inside dll function is looking for a pointer.