Jump to content

Manic DLL calls


Recommended Posts

Hi, I'm currently coding a lighting desk GUI for use with a Velleman USB/DMX interface, it all works and everything, but I find that when I am making a lot of DLL calls (to the interface DLL), my GUI starts to lag horribly...

Is there any way I can optimise this? I've done everything I can think of to reduce the number of DLL calls, like having an array which it checks against to see if the call needs to be made for example.

Func DMXSetData($Channel, $Data)
    If $Data <> $OUTPUT[$Channel] Then
        $result = DLLCall("k8062d.dll", "none", "SetData", "long", $Channel, "long", $Data)
        $OUTPUT[$Channel] = $Data
    EndIf
EndFunc

I'll attach the whole project folder, please note, you don't have to have the actual box to run the app, it doesn't seem to mind if it's not there...

To reproduce the problem, click edit on a channel on the bottom row, then turn on loads of the top 2 rows, click save, and then try moving the slider around of the channel you edited.

Note, that if you disable the DLL call in _DMX.au3 (DMXSetData) then the whole GUI works as expected.

Many thanks!

Edited by psynegy
Link to comment
Share on other sites

On brief testing, I don't see any gui lag in updating the sliders.

It's preferable to use a handle for the dllcalls via Dllopen/Dllclose in _DMX.au3. See if this makes any difference to you.

#include-once

Global $hDll
Global $OUTPUT

Func DMXStartDevice()
    $hDll = DllOpen("k8062d.dll")
    $result = DllCall($hDll, "none", "StartDevice")
    Return
EndFunc   ;==>DMXStartDevice

Func DMXStopDevice()
    $result = DllCall($hDll, "none", "StopDevice")
    DllClose($hDll)
    Return
EndFunc   ;==>DMXStopDevice

Func DMXSetData($Channel, $Data)
    If $Data <> $OUTPUT[$Channel] Then
        $result = DllCall($hDll, "none", "SetData", "long", $Channel, "long", $Data)
        $OUTPUT[$Channel] = $Data
    EndIf
EndFunc   ;==>DMXSetData

Func DMXSetChannelCount($Count)
    $result = DllCall($hDll, "none", "SetChannelCount", "long", $Count)
EndFunc   ;==>DMXSetChannelCount
Link to comment
Share on other sites

On brief testing, I don't see any gui lag in updating the sliders.

It's preferable to use a handle for the dllcalls via Dllopen/Dllclose in _DMX.au3. See if this makes any difference to you.

#include-once

Global $hDll
Global $OUTPUT

Func DMXStartDevice()
    $hDll = DllOpen("k8062d.dll")
    $result = DllCall($hDll, "none", "StartDevice")
    Return
EndFunc   ;==>DMXStartDevice

Func DMXStopDevice()
    $result = DllCall($hDll, "none", "StopDevice")
    DllClose($hDll)
    Return
EndFunc   ;==>DMXStopDevice

Func DMXSetData($Channel, $Data)
    If $Data <> $OUTPUT[$Channel] Then
        $result = DllCall($hDll, "none", "SetData", "long", $Channel, "long", $Data)
        $OUTPUT[$Channel] = $Data
    EndIf
EndFunc   ;==>DMXSetData

Func DMXSetChannelCount($Count)
    $result = DllCall($hDll, "none", "SetChannelCount", "long", $Count)
EndFunc   ;==>DMXSetChannelCount

Thanks so much, you're a star! I was going to have to scrap the whole project if I couldn't fix that...

Awesome, thanks very much!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...