L'appel à un programme de type console permet à d'autres programmes (graphiques ceux-là, et pas forcément les miens mais des programmes en Perl, PHP, etc) de lancer des commandes VELBUS !
Pour bien comprendre : chaque module a une adresse sur 1 octet. Chaque module peut avoir de 1 à 8 parts (un module relais VMB4RY contient 4 relais).
syntax : velbuscmd port:8080 server:192.168.1.1 blind-up:$35-1 relay-toggle:$47-2;$48-2;$48-3 tempstatus:$D3 etc...
Code : Tout sélectionner
; Velbus Command 1.0 by Golfy (Purebasic 4.61)
; v1.0 -> Server adaptation to a console program able to send Velbus command from human command (02/08/2012)
; Default parameters : COM4 and 8080
version$ = "1.0"
Structure adresse
ModAdd.i
PrtAdd.i
cmd$
EndStructure
Global Srv$ = "192.168.1.1"
Global Port = 8080
Global NewList module.adresse()
OpenConsole()
Procedure Help()
PrintN("HELP : VelbusCmd syntax and Keyword")
PrintN("-----------------------------------")
PrintN("ex: VelbusCmd.exe server:192.168.1.5 port:8000 blind-up:$E4-2;$E8-1")
PrintN(" parameter:number or port")
PrintN("-----------------------------------")
PrintN("blind : blind-up, blind-down, blind-light")
PrintN(" open or close blinds. try to open a little blinds.")
PrintN("")
PrintN("relay : relay-on, relay-off, relay-blink")
PrintN(" active or desactive a relay. Blink make it blinking for 30s")
PrintN("")
PrintN("dimmer: dim-on, dim-off, dim-xx%")
PrintN(" light up, light off and light to xx%")
PrintN("led : led-on, led-off, led-blink")
PrintN(" light up, light off and blink leds")
PrintN("")
End
EndProcedure
Procedure Erreur(a$)
PrintN(a$)
End
EndProcedure
; if parameter are transmit after commandline
; syntax : port:8080 server:192.168.1.1 blind-up:$35 relay-toggle:$47 tempstatus:$D3 etc...
Select UCase(ProgramParameter(0))
Case "H", "/H","-H","HELP","/HELP","-HELP","?","/?","-H"
help()
EndSelect
Resultat = CountProgramParameters()
If Resultat
PrintN(Str(resultat)+" parametres.")
;CallDebugger
For t=0 To Resultat
a$ = UCase(ProgramParameter(t))
k$ = StringField(a$,1,":")
p$ = StringField(a$,2,":")
If FindString(k$,"PORT")
port = Val(p$)
PrintN("PORT:"+Str(port))
EndIf
If FindString(k$,"SERVER")
server$ = p$
EndIf
If FindString(k$,"BLIND")
cpt = CountString(p$,";")
For g = 1 To cpt+1
; Vérification de la présence de paramètres
If Len(StringField(p$,1,"-")) >0 And Len(StringField(p$,2,"-")) > 0
AddElement(module())
c$ = StringField(p$,g,";")
Module()\ModAdd = Val(StringField(c$,1,"-"))
Module()\PrtAdd = Val(StringField(c$,2,"-"))
Module()\cmd$ = k$
If Module()\PrtAdd < 1 Or Module()\PrtAdd > 8
DeleteElement(module(),1)
EndIf
If Module()\ModAdd < 0 Or Module()\ModAdd > 254
DeleteElement(module(),1)
EndIf
Else
erreur("Bad parameters : "+p$)
EndIf
Next g
EndIf
Next t
;
PrintN("---------------")
;ResetList(module())
ForEach module()
PrintN(module()\cmd$+" Adr:$"+Hex(module()\ModAdd)+" part:"+Str(Module()\PrtAdd))
Next
PrintN("---------------")
Else
help()
EndIf