05-30-2014 09:41 AM
Hello everyone,
I am trying to pass a cluster into a dll, and then read out the data I had written in order to verity that it is working. But, it is not. I am wondering if the memset function has something to do with this? Or does Labview handle this function? I suppose the worst case is that I can create a dll to handle this.
This is the short program I am trying to duplicate (The header file is attached):
#include <fscc.h> /* fscc_* */ int main(void) { fscc_handle h; struct fscc_registers regs; fscc_connect(0, &h); /* Initialize our registers structure */ FSCC_REGISTERS_INIT(regs); /* Change the CCR0 and BGR elements to our desired values */ regs.CCR0 = 0x0011201c; regs.BGR = 10; /* Set the CCR0 and BGR register values */ fscc_set_registers(h, ®s); /* Re-initialize our registers structure */ FSCC_REGISTERS_INIT(regs); /* Mark the CCR0 and CCR1 elements to retrieve values */ regs.CCR1 = FSCC_UPDATE_VALUE; regs.CCR2 = FSCC_UPDATE_VALUE; /* Get the CCR1 and CCR2 register values */ fscc_get_registers(h, ®s); fscc_disconnect(h); return 0; }
05-30-2014 06:00 PM
Why would memset be required here? It's not in the sample code.
Can you post your LabVIEW code? That way we can see what you did, and likely explain how to fix it. You need to create a LabVIEW cluster that matches the struct; after that the rest should be easy. You cannot include a LabVIEW array inside the cluster; instead, you need to match the fixed-size arrays in the struct with nested clusters. That is, inside the cluster that matches the fscc_registers struct, the "reserved1" and "reserved2" elements should be clusters containing 2 elements each.
Alternatively, since every element in the struct is a 64-bit int, you could also pass an initialized array of 24 64-bit elements (you should confirm my count of 24).
05-31-2014 05:16 PM
@nathand wrote:
Why would memset be required here? It's not in the sample code.
The
FSCC_REGISTERS_INIT(regs);
is a macro that clears the regs structure with the memset function.
Creating a cluster with 24 int64 elements that are all set to 0 should have exactly the same effect. On Windows the fscc_handle variable is a pointer sized integer (Important if you ever want to run this in 64 bit LabVIEW with a 64 bit DLL).
For the rest I don't really see anything special with the used functions.
06-04-2014 08:36 AM
I attached the header file in theinital post which shows that memset macro. At first I thought that perhaps it was causing problems but, as it turns out, it only sets the values on the struct to a default value, which is -1.
Here is the definition:
#define FSCC_REGISTERS_INIT(regs) memset(®s, -1, sizeof(regs))
I will have to try the nested clusters, and as you pointed out, and I now suspect that this may be the issue. I have attached the current vi, which still have arrays in the clusters.
Thanks!
06-04-2014 07:10 PM - edited 06-04-2014 07:11 PM
@bry0n wrote:
I attached the header file in theinital post which shows that memset macro. At first I thought that perhaps it was causing problems but, as it turns out, it only sets the values on the struct to a default value, which is -1.
Here is the definition:
#define FSCC_REGISTERS_INIT(regs) memset(®s, -1, sizeof(regs))
I will have to try the nested clusters, and as you pointed out, and I now suspect that this may be the issue. I have attached the current vi, which still have arrays in the clusters.
Thanks!
Yep, arrays definitely won't do the right thing. And I didn't look correct the first time. To match the memset() call you need of course to set all values to -1, which is basically all bits set. Also, on Windows the fscc_handle should be changed to "pointer sized integer" otherwise you get trouble when you ever want to call this library in LabVIEW 64 Bit for Windows. And the control for the handle should be changed to an int64 then.