LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Include ACCON-AGLink in CVI17

Solved!
Go to solution

Hello,

 

I found this library https://www.deltalogic.de/products/software/accon-aglink and it seems to be a good alternative to the Siemens Prodave library for the PLC 1500 communication.

I try to include it to my project but i have some build errors.

Has someone already use this library in CVI? How can i include it in CVI?

 

Thank you for any help.

Download All
0 Kudos
Message 1 of 5
(3,560 Views)

Hi Mattia,

I found the only references to the library you mentioned in other NI Community threads: in reverse chronological order

I fear, however, they might not be of much help to include the library in CVI.

Regards,

Alessia

0 Kudos
Message 2 of 5
(3,440 Views)

It would seem that that header file uses some C syntax features that are from recent C standards (C11 and newer). The CVI parser isn’t fully C11 compliant as many other C compilers aren’t either. Even Microsoft Visual C doesn’t yet implement every C11 feature to the letter, although Microsoft did in recent years quite an effort to add features from even newer Cxx standards to their compiler.

Accon most likely only tests their package with Visual C and GCC and leaves the rest to the programmer. Most likely by making the headers conform to C99 or similar instead the problems would go away.

 

You could ask Accon about support for CVI, but there is a good chance that they will ask you: ”LabWindows/CVI? Is that something to smear on your bread?” which considering the industry they work in would be a bit lame of course 😀

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 5
(3,421 Views)
Solution
Accepted by topic author Mattia.G

Your problem stems from the fact that Accon AGLink headers define struct datatypes with inclomplete tagDatatype and then uses these typedefs without the struct keyword. This has been long invalid syntax and only got relaxed for C++. But CVI is a standard C compiler and doesn't allow this abbreviation. Basically in the file OSDefinc.h you should change the declarations for the incomplete struct datatypes agl_systemtime_t and agl_wsabuf_t in a similar way like this:

 

typedef struct agl_systemtime_t
{
  agl_uint16_t  wYear;
  agl_uint16_t  wMonth;
  agl_uint16_t  wDayOfWeek;
  agl_uint16_t  wDay;
  agl_uint16_t  wHour;
  agl_uint16_t  wMinute;
  agl_uint16_t  wSecond;
  agl_uint16_t  wMilliseconds;
} agl_systemtime_t;

 

 

So add the typedef keyword and repeat the tag name after the closing curly braces.

 

This is because in C you have two different namespaces for struct, enum and unions. One is the tag namespace, which is the (optional) identifier before the curly brace, and the other is the ordinary identfier namespace after the curly braces, which is an alias to the typedef.

If you use the tag identifier you have to prepend the actual keyword to the identifier whenever using that identifier anywhere in your code so that is a lot more work to do as you need to touch several headers in many places. If you also define the typedef alias identifier name you can use that one without the keyword. In C++ this syntax difference has been relaxed and it may have been introduced in one of the latest C standards too, but not to sure about that one.

 

Also there is another C++ ism in these headers and that is the repeated use of the enum_t tag identifier throughout the AGL_Types.h and AGL_SymbolicTypes.h. That works in C++ since each struct defines its own namespace just as a class does (which is a glorified struct in terms of how it is implemented) but standard C doesn't know such namespace differences and everything is in a global namespace even when it is declared inside a struct declaration. By removing all the enum_t words in the headers you can then compile your program in LabWindows/CVI. Not sure what limitation that may create when actually using those enum identifiers in your code though. Didn't check that one out. They don't seem to be used in the header anywhere, so I assume they will need to be passed to API parameters that are defined as normal integer types.

 

Basically the AGLink headers are only working with C++ compilers but not with C compilers that don't add C++ ish features that would be actually against the actual C standard. 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 5
(3,414 Views)

With the changes to the header files you suggested it seems work.

I also modified some functions  prototype by passing pointer to int instead enum_t as you said. 

 

Thank you

0 Kudos
Message 5 of 5
(3,400 Views)