Joshuatronics Posted March 7, 2009 Report Share Posted March 7, 2009 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 Quote Link to comment
ned Posted March 7, 2009 Report Share Posted March 7, 2009 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. Quote Link to comment
Joshuatronics Posted March 11, 2009 Author Report Share Posted March 11, 2009 :worship: :thumbup: THANK YOU VERY MUCH!!! I tried the thing you told me about and it worked perfectly, now i can write and read data. VERY THANKS!!!!!!!! Quote Link to comment
stevea1973 Posted March 14, 2009 Report Share Posted March 14, 2009 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. Quote Link to comment
Rolf Kalbermatter Posted March 19, 2009 Report Share Posted March 19, 2009 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 Quote Link to comment
Joshuatronics Posted March 27, 2009 Author Report Share Posted March 27, 2009 Certainly i haven't used padding bytes. I've corrected the ID format to u32 though, but it's working. i'll be working on fixing the padding issue and see what changes, you have me now wondering in the solution for that. thanks Quote Link to comment
Joshuatronics Posted March 28, 2009 Author Report Share Posted March 28, 2009 Hi, i introduced the bytes of padding and i solve some issues about transmision, thanx :thumbup: Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.