12-28-2012 02:29 AM
The attachment is winmm.dll and .h files. In “time Set Event.vi” ,I don’t how to set LPTIMECALLBACK lpTimeProc.Can you tell me some advice?
The introrucion abou timeSetEvent refer to : http://technet.microsoft.com/zh-cn/query/ms713423, also see belows:
Windows Multimedia
timeSetEvent
The timeSetEvent function starts a specified timer event. The multimedia timer runs in its own thread. After the event is activated, it calls the specified callback function or sets or pulses the specified event object.
This function is obsolete. New applications should use CreateTimerQueueTimer to create a timer-queue timer.
Parameters
uDelay
Event delay, in milliseconds. If this value is not in the range of the minimum and maximum event delays supported by the timer, the function returns an error.
uResolution
Resolution of the timer event, in milliseconds. The resolution increases with smaller values; a resolution of 0 indicates periodic events should occur with the greatest possible accuracy. To reduce system overhead, however, you should use the maximum value appropriate for your application.
lpTimeProc
Pointer to a callback function that is called once upon expiration of a single event or periodically upon expiration of periodic events. If fuEvent specifies the TIME_CALLBACK_EVENT_SET or TIME_CALLBACK_EVENT_PULSE flag, then the lpTimeProc parameter is interpreted as a handle to an event object. The event will be set or pulsed upon completion of a single event or periodically upon completion of periodic events. For any other value of fuEvent, the lpTimeProc parameter is interpreted as a function pointer with the following signature: void (CALLBACK)(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
dwUser
User-supplied callback data.
fuEvent
Timer event type. This parameter may include one of the following values.
Value |
Meaning |
TIME_ONESHOT |
Event occurs once, after uDelaymilliseconds. |
TIME_PERIODIC |
Event occurs every uDelay milliseconds. |
The fuEvent parameter may also include one of the following values.
Value |
Meaning |
TIME_CALLBACK_FUNCTION |
When the timer expires, Windows calls the function pointed to by thelpTimeProc parameter. This is the default. |
TIME_CALLBACK_EVENT_SET |
When the timer expires, Windows calls the SetEvent function to set the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored. |
TIME_CALLBACK_EVENT_PULSE |
When the timer expires, Windows calls the PulseEvent function to pulse the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored. |
TIME_KILL_SYNCHRONOUS |
Passing this flag prevents an event from occurring after the timeKillEvent() function is called. |
Return Values
Returns an identifier for the timer event if successful or an error otherwise. This function returns NULL if it fails and the timer event was not created. (This identifier is also passed to the callback function.)
Remarks
Each call to timeSetEvent for periodic timer events requires a corresponding call to the timeKillEvent function.
Creating an event with the TIME_KILL_SYNCHRONOUS and the TIME_CALLBACK_FUNCTION flag prevents the event from occurring after the timeKillEvent function is called.
Requirements
Windows XP: Included in Windows XP only.
Header: Declared in Mmsystem.h; include Windows.h.
Library: Use Winmm.lib.
12-28-2012 02:39 AM
Hi fjczd,
- I doubt you can use a WinXP DLL in a RT-OS environment...
- On RT-OS you (usually) can use other timing resources than the standard 1kHz clock...
- Starting with LV2010 (?) you will find the "High resolution relative seconds"-VI in your vi.lib/utility folder...
Please provide information on
- what are your (real) goals
- what environment do you use
- which LV version do you use
- anything else needed to provide help on your task
12-28-2012 04:23 AM
I want to use timeSetEvent in windows XP ,with LabVIEW2009.
NOT IN RT OS
12-28-2012 04:27 AM
So anyone can give me some advice?How can I use timeSetEvent( which in winmm.dll) with LabVIEW?
12-29-2012 08:54 PM
Happy new year
12-30-2012 03:54 AM - edited 12-30-2012 03:58 AM
I don't think you can create a callback for a DLL unfortunately, however there is an example of using .net timers and callbacks if there is a .net equivalent. But what are you trying to achieve? Typically the LabVIEW functions will achieve what Windows can reliably and there may be a better solution.
This may also be shown may the fact that function is now obsolete and its replacement only supports ms.
12-30-2012 05:26 AM - edited 12-30-2012 05:32 AM
Dear fkczd,
to use that function, you need to create the callback function in your MS Visual studio project.
I guess you need something like this:
1. Create a calback function (normal function) that uses LVPostEvent, you need to include extcode.h in your DLL project, this is the same as if you used the LabView function Generate user event.
2. Create a variable that will hold the pointer to this function.
3. call the timeSetEvent with the fuEvent parameter = TIME_CALLBACK_FUNCTION, in user parameters, you need to supply the LabView Event RefNum (create labview event and pass refnum to the dll Call)
This should result in geting the event if the timer expires. You need to register the user event you use in the LabView event structure.
12-30-2012 07:53 AM
Thank you, James_McN.
Does LabVIEW can not use callback function for DLL?
Where is the example of using .net timers and callbacks?Can LabVIEW call timeSetEvent in winmm.dll?
In fact ,I only want to read dafa from some instruments with fixed period.the period uninfluenced by other events,such as mouse click,keyup,keydown.I known in real time system,it can.But in window xp system I have no idea how LabVIEW do it. With VC,VB ,it can read data from some instrument with fixed perion uninfluenced by other events in windows xp.
So can you have any advice on how to achieve it with LabVIEW in Windows XP?
12-30-2012 07:35 PM
Thank you Bublina for illustrated explanation.
I can understand the concept,but how to do ? LVPostEvent is not open for user, I have no idea about how “call the timeSetEvent”. Do other languages,such VB VC, to achieve callback functional in winmm.dll,LabVIEW CAN NOT to do?
I guess,there my be some tricks in LabVIEW which I have not found,or LabVIEW can achieve this aim (read dafa from some instruments with fixed period which uninfluenced by other events,such as mouse click,keyup,keydown) with its special method or structure.
12-31-2012 02:30 AM
Hi fjczd,
In LabVIEW we use the timing VIs inside of loops to achieve the same thing, rather than using callbacks. If you place the wait until multiple ms function (in the programming>>timing palette) down in a loop it will regulate the loop rate to whatever you specify which is in ms. I think this should achieve what you want without having to call external code.
The example for .net callbacks is at https://decibel.ni.com/content/docs/DOC-9161 but as I say I think that we just have a different way of doing this in LabVIEW so this should not be necessary.
Cheers,
James