LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about timeSetEvent

I want to use “timeSetEvent”  (which in winmm.dll) to get a high precise time. As we all known, we can get a defined period of time in RT OS. After looking up in website,I find  “timeSetEvent” can get a  defined period of time,which about 1ms.

With C or VB,some people can finish it. I try it in LabVIEW,but I can not, Because “timeSetEvent”has a callback function. I don’t known how to use it.

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.

  1. MMRESULT timeSetEvent(
  2.   UINT           uDelay,      
  3.   UINT           uResolution, 
  4.   LPTIMECALLBACK lpTimeProc,  
  5.   DWORD_PTR      dwUser,      
  6.   UINT           fuEvent      
  7. );

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.

 

0 Kudos
Message 1 of 30
(6,231 Views)

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

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 30
(6,224 Views)

I want to use timeSetEvent in windows XP ,with  LabVIEW2009.

NOT IN RT OS

0 Kudos
Message 3 of 30
(6,216 Views)

With C or VB,some people can finish timeSetEvent. I try it in LabVIEW,but I can not, Because “timeSetEvent”has a callback function. I don’t known how to use it.

So anyone can give me some advice?How can I use timeSetEvent( which in winmm.dll) with LabVIEW?

0 Kudos
Message 4 of 30
(6,215 Views)

Happy new year

0 Kudos
Message 5 of 30
(6,184 Views)

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. 

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 6 of 30
(6,170 Views)

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.

 

timer.png

0 Kudos
Message 7 of 30
(6,159 Views)

    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?

0 Kudos
Message 8 of 30
(6,149 Views)

    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.

0 Kudos
Message 9 of 30
(6,131 Views)

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

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 10 of 30
(6,116 Views)