Jump to content

Hartger

Members
  • Posts

    1
  • Joined

  • Last visited

About Hartger

  • Birthday 01/03/1972

Profile Information

  • Location
    RIEL

Hartger's Achievements

Seeker

Seeker (1/7)

1

Reputation

  1. Hi guys, just bought is today to test its qualities... tried te recreate the demo inlcuded on the CD you get with the interface. It'll show you teh possibilities, it's just a quick post. CODE;===========================================; inlcudes ;=========================================== #include <k8055.au3> #include <GUIConstants.au3> ;=========================================== ; gui ;=========================================== Opt("GUIOnEventMode", 1) $Form_1 = GUICreate("Velleman 8055-1 kit demo", 467, 246, 326, 253) GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose") $do8 = GUICtrlCreateCheckbox("do8", 416, 144, 17, 17) GUICtrlSetOnEvent(-1, "do8Click") $do7 = GUICtrlCreateCheckbox("do7", 392, 144, 17, 17) GUICtrlSetOnEvent(-1, "do7Click") $do6 = GUICtrlCreateCheckbox("do6", 368, 144, 17, 17) GUICtrlSetOnEvent(-1, "do6Click") $do5 = GUICtrlCreateCheckbox("do5", 344, 144, 17, 17) GUICtrlSetOnEvent(-1, "do5Click") $do4 = GUICtrlCreateCheckbox("do4", 320, 144, 17, 17) GUICtrlSetOnEvent(-1, "do4Click") $do3 = GUICtrlCreateCheckbox("do3", 296, 144, 17, 17) GUICtrlSetOnEvent(-1, "do3Click") $do2 = GUICtrlCreateCheckbox("do2", 272, 144, 17, 17) GUICtrlSetOnEvent(-1, "do2Click") $do1 = GUICtrlCreateCheckbox("do1", 248, 144, 17, 17) GUICtrlSetOnEvent(-1, "do1Click") $ao1 = GUICtrlCreateSlider(280, 32, 153, 25) GUICtrlSetOnEvent(-1, "ao1Change") $ao2 = GUICtrlCreateSlider(280, 64, 153, 25) GUICtrlSetOnEvent(-1, "ao2Change") $Group1 = GUICtrlCreateGroup("Analog out", 232, 16, 217, 81) $Label3 = GUICtrlCreateLabel("Out 1", 248, 40, 30, 17) $Label4 = GUICtrlCreateLabel("Out 2", 248, 64, 30, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("Digital out", 232, 104, 217, 97) $Label2 = GUICtrlCreateLabel("1 2 3 4 5 6 7 8", 248, 128, 181, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group4 = GUICtrlCreateGroup("Analog in", 16, 16, 201, 81) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group5 = GUICtrlCreateGroup("Digital in", 16, 104, 201, 65) $Label5 = GUICtrlCreateLabel("In 1", 32, 132, 22, 17) $Label6 = GUICtrlCreateLabel("In 2", 128, 132, 22, 17) $ai1 = GUICtrlCreateInput("", 56, 128, 57, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY)) $ai2 = GUICtrlCreateInput("", 152, 128, 57, 21, BitOR($ES_AUTOHSCROLL, $ES_READONLY)) GUICtrlCreateGroup("", -99, -99, 1, 1) $di1 = GUICtrlCreateCheckbox("di1", 32, 64, 17, 17) $di2 = GUICtrlCreateCheckbox("di2", 70, 64, 17, 17) $di3 = GUICtrlCreateCheckbox("di3", 108, 64, 17, 17) $di4 = GUICtrlCreateCheckbox("di4", 146, 64, 17, 17) $di5 = GUICtrlCreateCheckbox("di5", 184, 64, 17, 17) $Label1 = GUICtrlCreateLabel(" 1 2 3 4 5", 32, 48, 163, 17) $btn_loop = GUICtrlCreateButton("Loop", 248, 176, 81, 17, 0) GUICtrlSetOnEvent(-1, "btn_loopClick") $btn_random = GUICtrlCreateButton("Random", 352, 176, 81, 17, 0) GUICtrlSetOnEvent(-1, "btn_randomClick") GUISetState(@SW_SHOW) ;=========================================== ; vars ;=========================================== Dim $dostate = "none" Dim $ailevel1 = 0 Dim $ailevel2 = 255 Dim $ledloop = 0 ;=========================================== ; main program ;=========================================== DllOpen("k8055d.dll") USBOpenDevice (0) While 1 $msg = GUIGetMsg() ReadDI() ReadAI() digiout($dostate) If $msg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd USBCloseDevice () ;=========================================== ; functions ;=========================================== Func btn_loopClick() If GUICtrlRead($btn_loop) = "loop" Then $dostate = "loop" $ledloop = 1 GUICtrlSetData($btn_loop, "stop") GUICtrlSetStyle($btn_random, $WS_DISABLED) Else $dostate = "none" GUICtrlSetData($btn_loop, "loop") GUICtrlSetStyle($btn_random, $WS_VISIBLE) EndIf EndFunc ;==>btn_loopClick Func btn_randomClick() If GUICtrlRead($btn_random) = "random" Then $dostate = "random" GUICtrlSetData($btn_random, "stop") GUICtrlSetStyle($btn_loop, $WS_DISABLED) Else $dostate = "none" GUICtrlSetData($btn_random, "random") GUICtrlSetStyle($btn_loop, $WS_VISIBLE) EndIf EndFunc ;==>btn_randomClick Func ReadDI() $di = USBReadAllDigital () ; couldn't think of another way to parse the input bits... If $di >= 16 Then $di = $di - 16 GUICtrlSetState($di5, 1) Else GUICtrlSetState($di5, $GUI_UNCHECKED) EndIf If $di >= 8 Then $di = $di - 8 GUICtrlSetState($di4, 1) Else GUICtrlSetState($di4, $GUI_UNCHECKED) EndIf If $di >= 4 Then $di = $di - 4 GUICtrlSetState($di3, 1) Else GUICtrlSetState($di3, $GUI_UNCHECKED) EndIf If $di >= 2 Then $di = $di - 2 GUICtrlSetState($di2, 1) Else GUICtrlSetState($di2, $GUI_UNCHECKED) EndIf If $di = 1 Then GUICtrlSetState($di1, 1) Else GUICtrlSetState($di1, $GUI_UNCHECKED) EndIf EndFunc ;==>ReadDI Func ReadAI() $ailevel1 = USBReadAnalogChannel (1) $ailevel2 = USBReadAnalogChannel (2) GUICtrlSetData($ai1, $ailevel1) GUICtrlSetData($ai2, $ailevel2) EndFunc ;==>ReadAI Func digiout($state) Switch $state Case "random" USBWriteAllDigital (Random(0, 255)) Case "loop" USBClearDigitalChannel ($ledloop) $ledloop = $ledloop + 1 If $ledloop > 8 Then $ledloop = 1 USBSetDigitalChannel ($ledloop) Case Else EndSwitch EndFunc ;==>digiout ;=========================================== ; msg handlers ;=========================================== Func FormClose() Exit EndFunc ;==>FormClose Func ao1Change() USBOutputAnalogChannel (1, GUICtrlRead($ao1)) EndFunc ;==>ao1Change Func ao2Change() USBOutputAnalogChannel (2, GUICtrlRead($ao2)) EndFunc ;==>ao2Change Func do1Click() If GUICtrlRead($do1) = 1 Then USBSetDigitalChannel (1) Else USBClearDigitalChannel (1) EndIf EndFunc ;==>do1Click Func do2Click() If GUICtrlRead($do2) = 1 Then USBSetDigitalChannel (2) Else USBClearDigitalChannel (2) EndIf EndFunc ;==>do2Click Func do3Click() If GUICtrlRead($do3) = 1 Then USBSetDigitalChannel (3) Else USBClearDigitalChannel (3) EndIf EndFunc ;==>do3Click Func do4Click() If GUICtrlRead($do4) = 1 Then USBSetDigitalChannel (4) Else USBClearDigitalChannel (4) EndIf EndFunc ;==>do4Click Func do5Click() If GUICtrlRead($do5) = 1 Then USBSetDigitalChannel (5) Else USBClearDigitalChannel (5) EndIf EndFunc ;==>do5Click Func do6Click() If GUICtrlRead($do6) = 1 Then USBSetDigitalChannel (6) Else USBClearDigitalChannel (6) EndIf EndFunc ;==>do6Click Func do7Click() If GUICtrlRead($do7) = 1 Then USBSetDigitalChannel (7) Else USBClearDigitalChannel (7) EndIf EndFunc ;==>do7Click Func do8Click() If GUICtrlRead($do8) = 1 Then USBSetDigitalChannel (8) Else USBClearDigitalChannel (8) EndIf EndFunc ;==>do8Click Where you'll have to include the code earlier in this thread ( k8055.au3 ) in your script if you need it... Works nicely! thanks. Hartger
×
×
  • Create New...