trisol Posted February 3, 2009 Share Posted February 3, 2009 I am trying to read the counter register of the hardware counter build into the controller that runs DAQ 5.79A. To do that I need to use several external functions. I am having trouble with some of the functions that want a constant to be parsed to it (according to controller manufacturer). From Manufacturers documentation: Prototype: Status = CounterEventStart(LONG handle, USHORT counter, USHORT usCTRGate) with: handle = Assigned by DeviceOpenFunction (done and no problem - Digital in/outputs work with the handle) counter = counter number (use 0 for counter on digital input 1) usCTRGate = Control operation: (1) CFG_CTR_STOP or (2) CFG_CTR_START DAQ: Extern("Driver.dll","long CounterEventStart(LONG, USHORT, USHORT)","DIO_StartCntr","stdcall") (also tried cdecl instead of stdcall) calling the function in DAQ: global string CounterDLL CounterDLL[0] = DIOStartCntr(DIOHandle, 0, "CFG_CTR_START") Unfortunately the counter doesn't start. The hardware manufatcturer provides a sample application where the counter is working fine. I can also use this sample application to start the counter and then in DAQ use an external function (CounterEventRead(....)) to read the counter register no worries. The difference between the functions that work and the ones that don't are the arguments I parse in as a string (i.e. "CFG_CTR_START"). The response to an enquiry to the manufacturer was that these "CFG_CTR_...." are constants declared in the driver (DLL) The manufacturer also provides sample code in C#: errCde = Driver.CounterEventStart(DeviceHandle, currentCounter, Driver.CFG_CTR_START) As you can see they parse CFG_CTR_START not as a string but something else (I guess). How would I have to parse this last argument to the function? If I don't use a string the function returns an error code with meaning "invalid parameter". If I use a string it returns a 0 (for success) but I can use any string, "Please_start" also returns a 0 but the counter doesn't start! Any ideas what else I could try would be much appreciated, Thank You. (I can provide the C# sample code and documentation if it would be of use) Link to comment Share on other sites More sharing options...
AzeoTech Posted February 3, 2009 Share Posted February 3, 2009 Your prototype specifies a USHORT not a string, so you can't put "CFG_CTR_START" in its place. DAQFactory does not know what CFG_CTR_START is, and if it did, it would be without "", because the quotes indicate a string, not a constant. You have two options: 1) look in the header file provided for CFG_CTR_START and find the number assigned to it. If its C it will likely be either: #define CFG_CTR_START xxx or const unsigned short CFG_CTR_START = xxx where xxx is the constant. DAQFactory has an include() function that may be able to parse the header for the constants. Just do: include("c:\mypath to header file\headerfile.h") then all constants should come through as constants in DAQFactory. They'll even appear in the intellisense drop down when you are typing. Then you can do: CounterDLL[0] = DIOStartCntr(DIOHandle, 0, CFG_CTR_START) No guarantees though that the include() will work. We made it so it will handle simple constants, but if your header file has a lot of fancy C, compiler directives and the like it may not do it properly. To find out if it worked, do: ? CFG_CTR_START at the command/alert window after doing the include() Link to comment Share on other sites More sharing options...
trisol Posted February 3, 2009 Author Share Posted February 3, 2009 Thanks heaps! I found the header file and use the integer to parse in as defined in that header file. I don't seem to have to use the include(). Link to comment Share on other sites More sharing options...
AzeoTech Posted February 3, 2009 Share Posted February 3, 2009 Great! I'd only mess with include() if you have a lot of constants you need to import. If you just need one or two, you can either pull the number and use it directly, or create a constant yourself in DAQFactory code using a variable. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.