LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Handler to a function in LabVIEW 6.1

Hi,
I would like to create a handler to a function writen in a C source file. The function prototype is the following:

void MyFunc(word AxisID, word Address, long value);

I was thinking in using the CIN option of LabVIEW, but I don't know how to use it to have at one output of the CIN block the handler to MyFunc function which further must be passed as input parameter to another VI.

If someone can answer to this please do so as the project depending on this.

Thank you very much.
Catalin


Best regards,
Catalin BILAN
0 Kudos
Message 1 of 10
(3,641 Views)
Hi Catalin,
      Please forgive me for asking, but... are you sure you mean CIN (Code Interface Node)?  Have you studied the "Call Library Function Node"?  (It's for calling into DLLs.)
 
Cheers  
 
When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 2 of 10
(3,613 Views)
Hi,
Yeah, indeed.
The thing is like this: I have some functions in a dll file that are used to register a handler(callback function), to monitorize the serial port and to call the handler when a message on the serial port is received from a drive.
This functions are:
 
- void RegisterHandler(Function handler) - that register the callback function
- void CheckForMessages() - that check the serial channel and call the callback function when a new message is arrived.
and they have the following prototype:
 
void TML_EXPORT RegisterHandler(pfnCallbackRecvMsg handler);
/*******************************************************************************************
 Function: Register application's handler for messages.
 Input arguments:
 pfnCallbackRecvDriveMsg:  pointer to handler
 Output arguments:
*******************************************************************************************/
BOOL TML_EXPORT CheckForMessages();
/*******************************************************************************************
 Function: Check if there are new messages and call handler for every message received.
 Input arguments:
 Output arguments:
 return:  TRUE if no error; FALSE if error
*******************************************************************************************/
 
Now, the callback function must comply with a special prototype: void (*pfnCallbackRecvDriveMsg)(WORD var1, WORD var2, long Value); The body of this function is made by user.
 
I agree with you that the functions RegisterHandler and CheckForMessages must be called with Call Library Function Node. This is what I do, but what I realy don't know is how to made the callback function to be register by the RegisterHandler.VI for the CheckForMessages.VI. I thought that using the CIN I can make a C source code in which the callback function is made and when is called the CIN return a pointer to the callback function.
I made an example in Visual C++ 6.0 and is looking like this:
 
void __stdcall MyCallbackFunction(WORD var1, WORD var2, long Value)
{
 if(var1 == 1 && var2 == 0x090E)
 {
  printf("The value is : %ld [long]\n", Value);
 }
}
void main()
{
 
TS_RegisterHandler( &MyCallbackFunction );
 while(1)
 {
  TS_CheckForMessages();
 }
 return 0;
}
 
If you have some ideas pelase help me....Smiley Sad
Best regards,
Catalin BILAN
0 Kudos
Message 3 of 10
(3,607 Views)
Hello,
 
I would go one step further and suggest that you may be able to eliminate external code, at least for handling the monitoring of serial events.  You could use the NI-VISA API (there is an events portion of the API so you need not poll if that is a concern) to monitor the serial port, and then take whatever action you need thereafter.  Perhaps those actions would be dll function calls, but this would likely simplify the the architecture of your code, since LabVIEW would be the heart, and only the processing (which may already be wrapped into dll functions) could be done externally.
 
I hope this helps!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
Message 4 of 10
(3,596 Views)

Hi JLS,

      This subject is way "cool", there's currently a thread related to registering for "Dynamic" events (in an Event Structure.)  Does what you've said, related to the NI-VISA API, mean that one could build an "Event Structure" with cases fired by NI-VISA events?  Are there any "driver" VIs already available that wrap a CallLibFunc bound to said API?  How does one locate the right DLLs, need be?  Sorry if this is the wrong place to ask.  (Dunno how to message privately.) 

Cheers!

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 5 of 10
(3,585 Views)
I haven't used the VISA events (try looking in the VISA>>Advanced>>Events palette), but you can't use them with an event structure. You can register user events and fire them only when you get a VISA event, which will trigger the event structure.

___________________
Try to take over the world!
Message 6 of 10
(3,583 Views)

Hi tst,

      I don't know why I never looked at these VISA events - Nice! - but I wonder - is this what you meant by "VISA API", JLS?  If so, can Catalin use them - it sounds like he may _have_to_ assemble messages (TCP packets?) on the C side, and then get them into LabVIEW efficiently.

... and still, it would be "slick" to register/handle [VISA] IO events, with the Event Structure directly...

cheers

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 7 of 10
(3,568 Views)
Hello,
 
Yes, I was considering the VISA events part of the VISA API.  From the previous post, it seemed as though part of the task was to monitor the serial port, and subsequently call a function to handle the received data.  I was suggesting that VISA Events could be used to monitor the serial port, and when data was received (see the serial char event 0x3FFF2035 and/or the serial termchar event 0x3FFF2024 - the context help documentation will link you to a list of available events if you hover over the VISA Enable Event function) one of the following could take place:
 
- full parsing and processing of received data in labview directly
- preliminary parsing of data to determine what action (provided by a dll function) should be taken
- send data directly to a dll function for processing
 
The VISA Events would provide a way to have an event driven mechanism for monitoring the serial port, as opposed to polling.  Further, one could call by reference a VI that itself would have the call library function node in it - this way you can instruct LabVIEW even to load the dll into memory at the time of your choosing (it will happen when the Open VI Reference is executed, and will be unloaded from memory when the Close Reference is executed).  The attached example illustrates this - you'll need a third party tool (google for it) to monitor dlls loaded by program to actually prove that labview is doing this.  One you may try is called processexplorerNT, but I won't post it here because the readme mentions to contact the owner for distribution rights.
 
Best Regards,
 
JLS
 
 
Best,
JLS
Sixclear
Message 8 of 10
(3,558 Views)
Hi JLS,


Yes, I was considering the VISA events part of the VISA API.

Darn, was hoping you meant some [other] API provided through, say, some DLL(s) (... like GlobMgr.dll)


Further, one could call by reference a VI that itself would have the call library function node in it - this way you can instruct LabVIEW even to load the dll into memory at the time of your choosing

          Hmm, why this call-by-reference as opposed to putting VI w/CLF in VISA event-handler?

Cheers

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 9 of 10
(3,548 Views)
Hello,
 
No special reason to use a call by reference node, unless you care to control when LabVIEW loads the dll into memory (and the VI as well).  If you have a subVI on the block diagram, and it contains a call library function node, the corresponding dll will be loaded into memory when the VI is loaded into memory, which would be when the top level VI is being loaded into memory (since it loads subVIs then as well).
 
I was only illustrating a way to more closely manage memory in LabVIEW - in this case managing when dll's are loaded into memory, offering a way to do it at run-time at a time of your choosing using an Open VI Reference. 
 
Best Regards,
 
JLS
 
 
Best,
JLS
Sixclear
0 Kudos
Message 10 of 10
(3,524 Views)