Originally posted by Vodden
View Post
-David
If this is your first visit, be sure to check out the FAQ. You must register before you can post.
IMPORTANT: Your first post will be checked for appropriate content. This may take a bit of time.
http://192.168.0.11/JSON?request=pluginfunction&function=Ext_Send_Command&plugin=drhsIpPlugin&P1=Test%20Serial%20Connection&P2=Test%20Command
Public Const ScriptName = "DAB1_Relay_Cmd" Sub Main(ByVal param as Object) Dim Params() As String = Split(param.ToString, Chr(0)) ' Param(0) is the name of the plugin's connector ' Param(1) is the ip address of the remote end ' Param(2) is the data received hs.WriteLog("DAB1",Param(0)+" " +Param(1)+ " " + Param(2)) Dim datarecieved As String = Param(2) Try hs.WriteLog(ScriptName, "Sending to DAB1 " + datarecieved) hs.PluginFunction("drhsIpPlugin", "", "Ext_Send_Data", New Object(){"DAB1", datarecieved+"\r\n", "C Escaped"}) Catch ex As Exception hs.WriteLog(ScriptName, "Error C: " & ex.Message) End Try End Sub
Public Const ScriptName = "DAB1_Parse_In" Sub Main(ByVal param as Object) hs.WriteLog("DAB1ParseIn","Call one of my sub functions please") Dim Params() As String = Split(param.ToString, Chr(0)) ' Param(0) is the name of the plugin's connector ' Param(1) is the ip address of the remote end ' Param(2) is the data received hs.WriteLog(ScriptName,Param(0)+" " +Param(1)+ " " + Param(2)) Dim datarecieved As String = Param(2) Dim Command As String = datarecieved.Substring(1, 1) Dim Param1 As String = datarecieved.Substring(2, 1) Dim Param2 As String Dim DeviceName As String Dim SetTo As Integer Dim DevRef As Integer hs.WriteLog(ScriptName,"Command " + Command) hs.WriteLog(ScriptName,"Param1 " + Param1) 'datarecieved is the response status from the DAB1 'It has a different format depending upon the second character in the response. 'eg. zone power is +Zxy (Z = Zone Power, x= zone 1-6, y=1 if On, 0 if Off) ' volume is +Vxy (V = Volume, x= zone 1-6, y= Current Volume 0-60) 'Command is the Command part of the string (Z = zone command, V = Volume command etc) 'Param1 is always there but has a different meaning depending upon the command 'Param2 is only used for some commands is Volume status, which return say a zone value and volume. Select Case Command Case "Z" ' Zone On/Off if datarecieved.Length = 3 Then DeviceName = "DAB1 Power" SetTo = Convert.ToInt32(Param1) Else Param2 = datarecieved.Substring(3, datarecieved.Length - 3) DeviceName = "DAB1 Zone " & Param1 & " Power " SetTo = Convert.ToInt32(Param2) End If Case "S" 'Source Param2 = datarecieved.Substring(3, 1) DeviceName="DAB1 Zone " & Param1 & " Source" SetTo= Convert.ToInt32(Param2) Case "R" ' Tuner Memory. Note this can be 0 to 12 Param1 = datarecieved.Substring(2, datarecieved.Length - 2) DeviceName= "DAB1 Tuner" SetTo=Convert.ToInt32(Param1) Case "N" ' Tuner Band DeviceName= "DAB1 Band" SetTo=Convert.ToInt32(Param1) Case "V" 'Volume Param2 = datarecieved.Substring(3, datarecieved.Length - 3) DeviceName = "DAB1 Zone " & Param1 & " Volume" SetTo=Convert.ToInt32(Param2) Case "G" 'Page Volume Param2 = datarecieved.Substring(3, datarecieved.Length - 3) DeviceName="DAB1 Zone " & Param1 & " Page Volume" SetTo=Convert.ToInt32(Param2) Case "M" 'Mute Param2 = datarecieved.Substring(3, 1) DeviceName="DAB1 Zone " & Param1 & " Mute" SetTo=Convert.ToInt32(Param2) Case "B" 'Balance Note: Param 2 can be -10 to +10 Param2 = datarecieved.Substring(3, datarecieved.Length - 3) DeviceName="DAB1 Zone " & Param1 & " Balance" SetTo=Convert.ToInt32(Param2) Case "L" 'Bass Param2 = datarecieved.Substring(3, datarecieved.Length - 3) DeviceName="DAB1 Zone " & Param1 & " Bass" SetTo=Convert.ToInt32(Param2) Case "H" 'Treble Param2 = datarecieved.Substring(3, datarecieved.Length - 3) DeviceName= "DAB1 Zone " & Param1 & " Treble" SetTo=Convert.ToInt32(Param2) Case Else hs.WriteLog(ScriptName, "I don't know what to do with: " & Command) End Select hs.WriteLog(ScriptName,"Command " + Command) hs.WriteLog(ScriptName,"Param1 " + Param1) hs.WriteLog(ScriptName,"Param2 " + Param2) hs.WriteLog(ScriptName,"SetTo " + str(SetTo)) hs.WriteLog(ScriptName,"DeviceName:"+DeviceName) devRef = hs.GetDeviceRefByName(DeviceName) hs.WriteLog(ScriptName,"DevRef:"+str(DevRef)) hs.SetDeviceValueByRef(DevRef, SetTo, True) End Sub
Comment