11-05-2014 01:41 PM
I realize this question has been asked 1000 times before and I've looked through all of the possible solutions but am unable to solve my issue.
I have a DLL that controls a Softlog Systems ICP2 In-Circuit Programmer.
There are no LabVIEW drivers for this instrument and so I am having to use the provided DLL.
Here is the issue I have one of the calls that contains a struct, and with everything I have tried I always have LabVIEW crash with the error:
Exception: Access violation (0xC0000005) at EIP=0x01F04D3D
Here is the call
int DLL_FUNC IcpDllGetInfoSingle(ICP_INFO *aInfo);
Here is the struct definition
#define INFO_ID_SIZE 3 //firmware ID length #define INFO_GANG_QUAN 64 //maximum number of GANG channels
#define SEC_ID_SIZE 16+1
typedef struct //info from one channel of ICP2/ICP2-GANG { int iValid; //1-information in this structure is valid unsigned short iProgType; //programmer type according to PROG_TYPE unsigned short iFirmVer; //firmware version (H.L) unsigned char iIcpId[INFO_ID_SIZE]; //firmware ID (ICP serial number) unsigned short iBootVer; //bootloader version (H.L) unsigned short iIcpOpt; //ICP enabled options according to INFO_ICP_OPTIONS above unsigned short iFirmDevDb; //firmware device database version (H.L.) unsigned short iFirmPrjDb; //firmware project database version (H.L.) unsigned short iDllDevDb; //DLL device database version (H.L.) unsigned short iDllPrjDb; //DLL project database version (H.L.) int iSecMode; //security mode (1-secure environment now) int iEnvStat; //environment status according to enum PRJ_VAL – see 16.2.5 char iEnvHexFileName[SEC_ID_SIZE]; //HEX file name inside the environment unsigned short iEnvHexFileCs; //HEX file checksum char iSecIdName[SEC_ID_SIZE]; //Security ID name int iSecCntValue; //value of non-volatile security counter int iSecCntInteg; //security counter integrity (0-OK) } ICP_INFO;
My cluster that I am using is:
I would include the code, but this DLL accesses the instrument.
The DLL calling convention is stdcall (WINAPI) and the parameter aInfo is set as Adapt to Type and Pointers to Handles.
11-05-2014 01:46 PM
Hold it that looks like you have the headder file as well as the DLL.
Use the import wizard (Tools >> Import >> Shared Library or DLL...)
11-05-2014 02:03 PM
I will try and import it that way.
It was my understanding that when you had a function that needed a "adapt to input" type, you couldn't import it.
I will try though.
11-05-2014 03:44 PM
Can't check the cluster right now but except the actual data type of the integers, which I can't see from the image, it looks almost fine. If this doesn't work as expected your problem is most likely alignment.
In order for the cluster to match a C structure with standard alignment rules you would have to fill in an extra filler byte after
iIcpId
iEnvHexFileName
iSecIdName
11-05-2014 03:52 PM
OK, I have used the DLL import function and I no longer have crashing. There are still a few issues though
LabVIEW interpreted the 17-byte char but in the cluster it made there in not an array, just a single byte. It wouldn't matter if it wasn't the only real data I want from this whole function.
Also, a bit wierd but, labview suspends the running VI and I have to restart it after that specific function is called (no crashing, just have to step through to the end of the calling VI).
11-05-2014 04:51 PM - edited 11-05-2014 04:58 PM
Well,, you mean you made the fixed size arrays actually LabVIEW arrays? !!!!
That can't work!!!!!!!!
A C fixed size array is not a pointer but rather synomyme to a structure with as many elements as the fixed array size. A LabVIEW array is also not a pointer but a handle or more precisely a pointer to a pointer to a LabVIEW specific structure.
Generally you can never replace a C array or string with a LabVIEW string or array handle. The Call Library Node allows to configure a parameter to be passed as C string or array pointer but that is only for the direct data type not for any embedded strings or arrays inside a cluster.
You need to make the three arrays in your cluster into three clusters with 3 , 17 and 17 elements and each of them needs to be appended with an extra byte for the alignment filler.
12-02-2014 02:38 PM
I've been working similar problems - check out the results here: https://decibel.ni.com/content/docs/DOC-40315
I've attempted to take clusters, even those containing arrays and strings, and provide tools and rules (initialize those arrays and strings to fixed sizes!) to get almost anything into correct C Struct form for the LabVIEW CLFN.
I can't test every case so I'm hoping others will break this code and provide feedback to me!
Cheers,
Jolt