I am writing a small, relatively simple, program to interface with an external control board via a DLL. The DLL functions are working perfectly and I have no issue there. My problem is with setting the gadget sates in the GUI in one case. Rather than generating a load of "red herrings", by adding pointless DLL code calls to this post, I have created a working example extracted from the real code. The GUI looks ridiculous, because I have not repositioned the gadgets within the window used for the real program.
The GUI has and number of buttons to trigger functions, in 2 cases one button turns on 8 digital outputs and another turns them off. In the GUI I have used 8 checkboxes that are set and cleared accordingly. There is no problem here, everything works as expected. The issue is that I have another "Test" button, which is meant to call same procedures as the other 2 buttons, separated by a short delay eg. Delay(500) that I cannot get to work. The end objective is add more actions than this simple digital on/of feature to this "Test" button loop. Any thoughts?
Code: Select all
Enumeration
#WINDOW_MAIN
#CHECKBOX_DIG_OUT_1
#CHECKBOX_DIG_OUT_2
#CHECKBOX_DIG_OUT_3
#CHECKBOX_DIG_OUT_4
#CHECKBOX_DIG_OUT_5
#CHECKBOX_DIG_OUT_6
#CHECKBOX_DIG_OUT_7
#CHECKBOX_DIG_OUT_8
#BUTTON_ALL_DIG_ON
#BUTTON_ALL_DIG_OFF
#BUTTON_OUT_TEST
EndEnumeration
Procedure Open_Window_Main()
If OpenWindow(#WINDOW_MAIN, 0, 0, 640, 400, "Interface Demo", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
CheckBoxGadget(#CHECKBOX_DIG_OUT_1, 370, 100, 30, 20, "1")
CheckBoxGadget(#CHECKBOX_DIG_OUT_2, 400, 100, 30, 20, "2")
CheckBoxGadget(#CHECKBOX_DIG_OUT_3, 430, 100, 30, 20, "3")
CheckBoxGadget(#CHECKBOX_DIG_OUT_4, 460, 100, 30, 20, "4")
CheckBoxGadget(#CHECKBOX_DIG_OUT_5, 490, 100, 30, 20, "5")
CheckBoxGadget(#CHECKBOX_DIG_OUT_6, 520, 100, 30, 20, "6")
CheckBoxGadget(#CHECKBOX_DIG_OUT_7, 550, 100, 30, 20, "7")
CheckBoxGadget(#CHECKBOX_DIG_OUT_8, 580, 100, 30, 20, "8")
ButtonGadget(#BUTTON_ALL_DIG_ON, 10, 150, 120, 30, "Set All Digital")
ButtonGadget(#BUTTON_ALL_DIG_OFF, 10, 190, 120, 30, "Clear All Digital")
ButtonGadget(#BUTTON_OUT_TEST, 10, 320, 120, 30, "Output Test")
EndIf
EndProcedure
Procedure DigAllOn()
For i = #CHECKBOX_DIG_OUT_1 To #CHECKBOX_DIG_OUT_8
SetGadgetState(i, #PB_Checkbox_Checked)
Next i
; Here the DLL function is called
EndProcedure
Procedure DigAllOff()
For i = #CHECKBOX_DIG_OUT_1 To #CHECKBOX_DIG_OUT_8
SetGadgetState(i, #PB_Checkbox_Unchecked)
Next i
; Here the DLL function is called
EndProcedure
; In the real program all the previous code is in a pbi file
; The following code is in the pb file
; Obviously the pbi file is included at this point
Open_Window_Main()
Repeat
EventID.l = WaitWindowEvent(100) ; 100Ms is adaquate for this program
If EventID = #PB_Event_Gadget
Select EventGadget()
Case #BUTTON_ALL_DIG_ON
DigAllOn()
Case #BUTTON_ALL_DIG_OFF
DigAllOff()
Case #BUTTON_OUT_TEST
DigAllOn() ; This works WITHOUT the delay, but fails with it.
; Remove the following 3 lines and the above procedure is called
Delay(500) ; PROBLEM! Nothing happens in this Case statement
; Also tried creating a custom delay With ElapsedMilliseconds()
DigAllOff() ; This simply never happens.
EndSelect
ElseIf EventID = #PB_Event_Timer
; Here the board inputs are read and processed
; Without the timer the real program falls apart in many ways
EndIf
Until EventID = #PB_Event_CloseWindow