Ich bin seit einiger Zeit dabei mit dem Conradbausatz "Serieller A/DWanderl" Daten zu erfassen. Das geht auch soweit. Nun bin ich dabei die gemessenen Daten in einem Fenster als Graph darzustellen darzustellen. Wenn ich nun mit dem Mousezeiger über den Bildschirm fahre sollen ein Koordinatenkreuz angezeit werden und die Koordinaten am Kreuzungspunkt in ein StringGadget eingetragen werden. Auch das geht soweit. Nur was nicht so recht klappt ist "Der Bildschirm flackert! Aber warum! Was mache ich falsch???
Hier mein Code!
Code: Alles auswählen
; MessenCommon.pb--------------
Enumeration
#Window_0
#Window_1
#Window_2
#String_0
EndEnumeration
;--------------------------------------------------------------------
Procedure Open_Window_0()
If OpenWindow(#Window_0,0,0,1024,800,"Temperaturmesung",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
WindowID = WindowID(#Window_0)
If CreateGadgetList(WindowID)
StringGadget(#String_0, 890,450,80,20,"")
EndIf
EndIf
EndProcedure
;--------------------------------------------------------------------
Procedure Open_Window_1()
If OpenWindow(Window_1, 100, 100, 600, 400, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
If CreateGadgetList(WindowID(Window_1))
EndIf
EndIf
EndProcedure
;--------------------------------------------------------------------
Procedure Open_Window_2()
If OpenWindow(Window_2, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
If CreateGadgetList(WindowID)
EndIf
EndIf
EndProcedure
;-------------------------------
; IncludeFile "MessenCommon.pb"
XIncludeFile "IO_DLL_WRAPPER.pb"
;--------------------------------------------------------------------
Global Hcom.l
;--------------------------------------------------------------------
EinteilungX.w = 0
EinteilungY.w = 0
MouseX.w = 0
MouseY.W = 0
MouseXY.s = ""
;--------------------------------------------------------------------
Global Port.s = "com1: baud=19200 parity=n data=8 stop=1"
Global Handshake.l = 3
Global Buffer.l = 1024
;--------------------------------------------------------------------
HCom.l = ComOpen(Port, Handshake,Buffer,Buffer)
;--------------------------------------------------------------------
Procedure Delayus(t.l) ; Rechnerabhängig!
Structure DLong
lowlong.l
hilong.l
EndStructure
DLong=0
hitimefreq.DLong
QueryPerformanceFrequency_(@hitimefreq)
hitimecount1.DLong
hitimecount2.DLong
QueryPerformanceCounter_(@hitimecount1)
Repeat
QueryPerformanceCounter_(@hitimecount2)
Until Int((hitimecount2\lowlong - hitimecount1\lowlong)/(hitimefreq\lowlong/1000000.0))>=t
EndProcedure
;--------------------------------------------------------------------
Procedure TempMessung()
Adr_ClrPortBit.l = 0
Adr_SetPortBit.l = 0
Adr_NotPortBit.l = 0
A_Messwerte.b = 6
i.b = 0
j.b = 0
k.b = 0
B.w = 512
Vout.w = 0
Ref.f = 1023/5
Vin.f
Dim Kanal$(8)
Dim Messwerte.w(8,10)
Kanal$(1) = "100011101111"
Kanal$(2) = "110011101111"
Kanal$(3) = "100111101111"
Kanal$(4) = "110111101111"
Kanal$(5) = "101011101111"
Kanal$(6) = "111011101111"
Kanal$(7) = "101111101111"
Kanal$(8) = "111111101111"
;--------------------------------------------------------------------
Adr_ClrPortBit = GetFunction(1, "ClrPortBit")
Adr_SetPortBit = GetFunction(1, "SetPortBit")
Adr_NotPortBit = GetFunction(1, "NotPortBit")
If Hcom > 0
StartTime = ElapsedMilliseconds()
;--------------------------------------------------------------------
For k = 8 To 8 Step 1
For j = 0 To A_Messwerte Step 1
;--------------------------------------------------------------------
For i = 1 To 12 Step 1
CallFunctionFast(Adr_ClrPortBit,$3F8+4,0)
Delay(1)
;------------------Messkanal setzen----------------------------------
If Mid(Kanal$(k), i,1) = "0"
CallFunctionFast(Adr_ClrPortBit,$3F8+4,1)
Else
CallFunctionFast(Adr_SetPortBit,$3F8+4,1)
EndIf
;------------------Messwert auslesen---------------------------------
CallFunctionFast(Adr_SetPortBit,$3F8+4,0)
Select ComGetCTS(HCom)
Case 1
Vout = Vout + B
Case 0
Vout = Vout
EndSelect
B = B/2
;--------------------------------------------------------------------
Next i
CallFunctionFast(Adr_ClrPortBit,$3F8+4,1)
Delayus(200)
CallFunctionFast(Adr_NotPortBit,$3F8+4,1)
Delayus(200)
If j <> 0
Vin = 5 - Vout/Ref + Vin
EndIf
Vout = 0
B= 512
Next j
Vin = Vin/A_Messwerte
; MessageRequester("Vmess",StrF(Vin,2),2)
Vin = 0
Next k
ElapsedTime = ElapsedMilliseconds()-StartTime
EndIf
EndProcedure
;--------------------------------------------------------------------
;--------------------------------------------------------------------
LibOpen.l = OpenLibrary(1,"io.dll")
If LibOpen = 0
End
EndIf
Delay(1)
;--------------------------------------------------------------------
Open_Window_0()
imgNr=CreateImage(#PB_Any,800,800)
imgHd=ImageID(imgNr)
LoadFont(1, "Arial", 8)
FontID = FontID(1)
StartDrawing( ImageOutput(imgNr) )
DrawingFont(FontID)
Box(0,0, 800,800, RGB(255,255,255) )
LineXY(30,10,30,790,RGB(0,255,255)) ;y-Achse
LineXY(20,640,780,640,RGB(0,255,255)) ;x-Achse
For EinteilungX = 2 To 24 Step 1
LineXY(EinteilungX * 30, 630,EinteilungX * 30, 660,RGB(0,255,255)) ;DeltaX
DrawText(EinteilungX * 30, 650, Str(EinteilungX-1))
Next EinteilungX
DrawText(750, 645,"Zeit(h)")
For EinteilungY = 1 To 18 Step 1
LineXY(20, EinteilungY * 40, 40, EinteilungY*40,RGB(0,255,255)) ;DeltaY
DrawText(10,EinteilungY * 40, Str(10*(16-EinteilungY)))
Next EinteilungY
DrawText(12, 10,"°C)")
StopDrawing()
ExamineDesktops()
;--------------------------Event Schleife----------------------------
Repeat
MouseX = DesktopMouseX()
MouseY = DesktopMouseY()
StartDrawing( WindowOutput(win) )
DrawImage( imgHd,0,0)
If MouseX < 800
LineXY(20, MouseY, 790, MouseY,RGB(5,5,5)) ;X
LineXY(MouseX, 10, MouseX, 800,RGB(5,5,5)) ;Y
EndIf
StopDrawing()
MouseXY = Str(MouseX) + " | " + Str(MouseY)
SetGadgetText(#String_0, MouseXY)
EventID=WaitWindowEvent() ; This line waits until an event is received from Windows
WinID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID= EventGadget()
Select EventID
Case #PB_Event_CloseWindow
Select WinID
;------------------Verwaltung der vorhandenen Windows----------------
Case #Window_0
CloseWindow(#Window_0)
End
Case #Window_1
CloseWindow(#Window_1)
Case #Window_2
CloseWindow(#Window_2)
EndSelect
;-----------------Abfrage vorhandener Button und Checkboxen---------
Case #PB_Event_Gadget
Select GadgetID
; Case #Button_0
; Case #Button_1
; Open_Window_1()
;MessageRequester("eeee","ddd",0)
; Case #CheckBox_0
; If GetGadgetState(#CheckBox_0) = 1
; ;a = Relaisstellung()
; CallFunctionFast(AdrPortOut, PortNum,a) ; write 80h to port 378h
; Else
; ;a = Relaisstellung()
; CallFunctionFast(AdrPortOut, PortNum,a)
; EndIf
; Case #CheckBox_1
; If GetGadgetState(#CheckBox_1) = 1
; ;a = Relaisstellung()
; CallFunctionFast(AdrPortOut, PortNum,a) ; write 80h to port 378h
; Else
; ;a = Relaisstellung()
; CallFunctionFast(AdrPortOut, PortNum,a)
; EndIf
EndSelect
EndSelect
;------------------Aufruf der Funktionen Messen und Schalten---------
;Delay(1)
If EventID = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1