Wie kann man bitte die Netzwerkverbindung abfragen ?
Im unteren Programm funktioniert es nicht.
Das Programm stürzt ab und wird bei Nichtverbindung nicht abgefangen.
Habe die neueste Purebasicversion.
-------------------------
If InitNetwork() = 0
MessageRequester("Error", "Kein Netzwerk !", 0)
End
EndIf
-------------------------
Danke.
Gruss
Code: Alles auswählen
Global buffer.l,TEST.l,itest.l
Global text_e.s, url.s, str_1.s
Global zahl.a
Global pi.f,winkel.f,x1.f,y1.f,wd.f
Enumeration
#Window_0
#Editor_0
#vor
#zur
#links
#rechts
#mitte
#cls
#v0
#v1
#v2
#hlinks
#hrechts
#servo0
#servo1
#sharp
#ton
#canv
EndEnumeration
If InitNetwork() = 0
MessageRequester("Error", "Kein Netzwerk !", 0)
End
EndIf
url= "http://192.168.2.101/?pin=vor"
OpenWindow(#Window_0,500,200,900,550,"esp-webserver-http", #PB_Window_SystemMenu)
CanvasGadget(#canv, 380, 20, 400, 400)
AddWindowTimer(#Window_0, 123, 400)
EditorGadget(#Editor_0, 10, 200, 280,300)
ButtonGadget(#vor, 120,20, 40, 25, "vor")
ButtonGadget(#zur, 120,80, 40, 25, "zurück")
ButtonGadget(#mitte, 120,50, 40, 25, "mitte")
ButtonGadget(#hlinks, 75,50, 40, 25, "hlinks")
ButtonGadget(#links, 30,50, 40, 25, "links")
ButtonGadget(#rechts, 210,50, 40, 25, "rechts")
ButtonGadget(#hrechts, 165,50, 40, 25, "hrechts")
ButtonGadget(#cls, 310,200, 40, 25, "cls")
ButtonGadget(#v0, 310,20, 40, 25, "v0")
ButtonGadget(#v1, 310,50, 40, 25, "v1")
ButtonGadget(#v2, 310,80, 40, 25, "v2")
ButtonGadget(#servo0, 120,140, 40, 25, "servo0")
ButtonGadget(#servo1, 165,140, 40, 25, "servo1")
ButtonGadget(#sharp, 210,140, 40, 25, "sharp")
ButtonGadget(#ton, 255,140, 40, 25, "ton")
pi = ACos(0)*2
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Timer And EventTimer() = 123
SetGadgetText(#Editor_0, text_e)
Buffer = ReceiveHTTPMemory(url)
If buffer
str_1=Str(PeekC(Buffer))
zahl=Val(str_1)
If zahl < 0
zahl=128-zahl
EndIf
str_1=Str(zahl)
text_e + str_1 +Chr(10)
SetGadgetText(#Editor_0, text_e)
FreeMemory(Buffer)
winkel=winkel+wd
If winkel > 180
TEST=0
EndIf
EndIf
URL = SetURLPart(URL, "pin", "leer")
EndIf
If Event = #PB_Event_Gadget
StartDrawing(CanvasOutput(#canv))
If TEST=1
x1 = Sin(winkel/180*pi) * zahl
y1 = Cos(winkel/180*pi) * zahl
LineXY(200,200,200+x1,200+y1,RGB(255,0,0))
EndIf
If TEST=2
x1 = Sin((winkel+180)/180*pi) * zahl
y1 = Cos((winkel+180)/180*pi) * zahl
LineXY(200,200,200+x1,200+y1,RGB(0,255,0))
EndIf
If TEST=3
Box(0,0,399,399,RGB(255,255,255))
EndIf
StopDrawing()
EndIf
Select Event
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #vor
URL = SetURLPart(URL, "pin", "vor")
EndIf
If EventGadget = #zur
URL = SetURLPart(URL, "pin", "zur")
EndIf
If EventGadget = #links
URL = SetURLPart(URL, "pin", "links")
EndIf
If EventGadget = #hlinks
URL = SetURLPart(URL, "pin", "hlinks")
EndIf
If EventGadget = #rechts
URL = SetURLPart(URL, "pin", "rechts")
EndIf
If EventGadget = #hrechts
URL = SetURLPart(URL, "pin", "hrechts")
EndIf
If EventGadget = #mitte
URL = SetURLPart(URL, "pin", "mitte")
EndIf
If EventGadget = #v0
URL = SetURLPart(URL, "pin", "v0")
EndIf
If EventGadget = #v1
URL = SetURLPart(URL, "pin", "v1")
EndIf
If EventGadget = #v2
URL = SetURLPart(URL, "pin", "v2")
EndIf
If EventGadget = #servo0
URL = SetURLPart(URL, "pin", "ser0")
EndIf
If EventGadget = #servo1
URL = SetURLPart(URL, "pin", "ser1")
TEST=1
winkel=0
wd=2
EndIf
If EventGadget = #sharp
URL = SetURLPart(URL, "pin", "sharp")
TEST=2
winkel=0
wd=1.8
EndIf
If EventGadget = #ton
URL = SetURLPart(URL, "pin", "ton")
EndIf
If EventGadget = #cls
text_e=""
SetGadgetText(#Editor_0, text_e)
TEST=3
EndIf
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver