Jump to content

Error when calling dll with data structure.


Recommended Posts

Hi,

I want to ask if anyone can check if what i am doing is correct. I'm calling an external dll and i have doubts about the data type in the function.

DWORD HiCOCANWrite( BYTE Can, psPCCanMsg msg, DWORD Timeout )

  • Can: Number of the node which is to transmit the message.
  • Msg: Pointer to message data
  • Timeout: Specifies the time HiCOCANWrite is waiting for a free entry in the transmit queue when the transmit queue is full.

the problem in the functionis the psPCCanMsg, that is a structure defined as,

typedef struct

{

BYTE ff; /* frame format: 0 = basic CAN, 1 = extended CAN */

BYTE rtr; /* 0 = normal frame, 1 = remote frame */

BYTE dlc; /* data length 0..8 */

DWORD id; /* telegram ID */

BYTE data[8]; /* data */

sTS timestamp; /* time stamp*/

}sPCCanMsg, *psPCCanMsg;

and the structure sTs is defined as,

typedef struct

{

WORD day;

BYTE hour;

BYTE min;

BYTE sec;

WORD ms;

WORD us; /* micro seconds; max. resolution 10μs */

}sTS, *psTS;

I used clusters for structures. i attach images of my labview code and the configuration in call libray.

The point is that the code is not working or does nothing. I'm using LabVIEW 7.1.

Please if anyone can help me I would appreciate it.

Thanks

Link to comment

You're close, but a LabVIEW array inside a cluster isn't quite like a C array inside a struct. To get a fixed-size array you need to use a cluster, not an array. Try using bundle instead of build array to build up the data component, or insert array to cluster with a fixed size of 8 cluster elements.

Link to comment

QUOTE (Joshuatronics @ Mar 7 2009, 02:08 AM)

the problem in the functionis the psPCCanMsg, that is a structure defined as,

typedef struct

{

BYTE ff; /* frame format: 0 = basic CAN, 1 = extended CAN */

BYTE rtr; /* 0 = normal frame, 1 = remote frame */

BYTE dlc; /* data length 0..8 */

DWORD id; /* telegram ID */

BYTE data[8]; /* data */

sTS timestamp; /* time stamp*/

}sPCCanMsg, *psPCCanMsg;

and the structure sTs is defined as,

typedef struct

{

WORD day;

BYTE hour;

BYTE min;

BYTE sec;

[ BYTE OF PADDING ]

WORD ms;

WORD us; /* micro seconds; max. resolution 10μs */

}sTS, *psTS;

Here's a question and also partly an answer to your query.

Your structure will almost certainly be:

typedef struct

{

BYTE ff; /* frame format: 0 = basic CAN, 1 = extended CAN */

BYTE rtr; /* 0 = normal frame, 1 = remote frame */

BYTE dlc; /* data length 0..8 */

[bYTE OF PADDING]

DWORD id; /* telegram ID */

BYTE data[8]; /* data */

[3 BYTES OF PADDING]

sTS timestamp; /* time stamp*/

}sPCCanMsg, *psPCCanMsg;

Now in your diagram you don't have the padding, but you also don't define id as U32.

Bearing in mind this, I can't see how it will now be working (unless you have fixed this), unless the structure is packed in the header file.

Does labview do automatic guessing of padding (since you can byte align or pack depending on choice) and how can you control this.

Link to comment

QUOTE (stevea1973 @ Mar 13 2009, 03:53 AM)

Does labview do automatic guessing of padding (since you can byte align or pack depending on choice) and how can you control this.

No! LabVIEW has no way of guessing the padding of data structures and consequently it does not try to do that at all. LabVIEW itself always uses fully packed data (with possibly one exception on the VxWorks PPC real time targets but I haven't verified that for sure since I don't have the hardware handy and haven't really run into an issue with that yet).

Another explanation why it does work without those padding bytes might be a #pragma pack(1) statement in the relevant header file before declaration of the data structures (and an according #pragma pack() after that, I would hope).

Rolf Kalbermatter

Link to comment
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.