Announcement

Collapse
No announcement yet.

Does hs.SendToComPort work or is it only me?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moskus
    replied
    Originally posted by Steve Q View Post
    1 second is way too short. 5-10 seconds is more realistic.
    Hmmm! That might be it! I haven't even thought about that.

    But I scraped that Monoprice HDMI switch a couple of years ago...

    Leave a comment:


  • Steve Q
    replied
    Originally posted by Moskus View Post
    I'm trying to control the HDMI switch (from Monoprice). This is the exact same script as in HS2:



    Code:
    Sub Main(parm as object)
    
    hs.OpenComPort(5,"4800,n,8,1",1,"","")
    
    hs.WaitSecs(1)
    
    hs.sendtocomport(5, parm.tostring & vbCrLf)
    
    hs.WaitSecs(1)
    
    hs.CloseComPort(5)
    
    End Sub
    (for example, calling sub "Main" with parameter "OFF").



    And this worked without problems in HS2. The same methods with the same arguments exist in HS3, but I get no reaction from the switch.



    What gives?


    Your script would probably work if you allowed more time for the com port to open. 1 second is way too short. 5-10 seconds is more realistic. Once the port is open, leave it open. No need to reopen it each time you send a command.

    I use sendtocomport a lot in HS3. I use a one line immediate script.

    Steve Q


    Sent from my iPad using Tapatalk

    Leave a comment:


  • happnatious1
    replied
    Here's a script I used to use in HS3 to control my monoprice amp. (before the plugin) Maybe something useful in it.

    Code:
    'Send Parameters in the form target|command|value ie. z1|volume|20
    'targets: a1,a2,a3, z1,z2,z3,z4,z5,z6,z7,z8,z9,z10,z11,z12,z13,z14,z15,z16,z17,z18.
    'commands: power,volume, mute, dnd(do not disturb),balance, treble, bass, source.
    'value: on, off, volume 00-38, treble/base 00-14, balance 00-20
    'Don't forget to set the com port
    
    Imports System.Threading
    Imports System.IO.Ports
    Imports System.Object
    Imports System.Text
    Public COMPort As New SerialPort()
    
    Public Sub Main(ByVal parm as Object)
    
    Dim tcArray(2) As String
    tcArray = parm.ToString.Split("|")
    Dim target As String = tcArray(0)
    Dim command As String = tcArray(1)
    Dim value As String = tcArray(2)
    
    hs.writelog("Monoprice Amp", "Script called with: "& target & "|" & command & "|" & value)
    
    Dim tcString = "" 'this is what will eventually be sent to the com port
    Dim tcStringBuilder As New StringBuilder("<") 'start building tcString
    
    Select Case target           'Select Target
    Case "a1"
    tcStringBuilder.Append ("10")
    Case "a2"
    tcStringBuilder.Append ("20")
    Case "a3"
    tcStringBuilder.Append ("30")
    Case "z1"
    tcStringBuilder.Append ("11")
    Case "z2"
    tcStringBuilder.Append ("12")
    Case "z3"
    tcStringBuilder.Append ("13")
    Case "z4"
    tcStringBuilder.Append ("14")
    Case "z5"
    tcStringBuilder.Append ("15")
    Case "z6"
    tcStringBuilder.Append ("16")
    Case "z7"
    tcStringBuilder.Append ("21")
    Case "z8"
    tcStringBuilder.Append ("22")
    Case "z9"
    tcStringBuilder.Append ("23")
    Case "z10"
    tcStringBuilder.Append ("24")
    Case "z11"
    tcStringBuilder.Append ("25")
    Case "z12"
    tcStringBuilder.Append ("26")
    Case "z13"
    tcStringBuilder.Append ("31")
    Case "z14"
    tcStringBuilder.Append ("32")
    Case "z15"
    tcStringBuilder.Append ("33")
    Case "z16"
    tcStringBuilder.Append ("34")
    Case "z17"
    tcStringBuilder.Append ("35")
    Case "z18"
    tcStringBuilder.Append ("36")
    
    Case Else
    hs.writelog("Monoprice Amp", "Target not found: " & target)
    End Select
    
    Select Case command
    Case "power"
    tcStringBuilder.Append ("PR")
    Case "mute"
    tcStringBuilder.Append ("MU")
    Case "volume"
    tcStringBuilder.Append ("VO")
    Case "dnd"
    tcStringBuilder.Append ("DT")
    Case "treble"
    tcStringBuilder.Append ("TR")
    Case "bass"
    tcStringBuilder.Append ("BS")
    Case "balance"
    tcStringBuilder.Append ("BL")
    Case "source"
    tcStringBuilder.Append ("CH")
    
    Case Else
    hs.writelog("Monoprice Amp", "Command not found: " & command)
    End Select
    
    Select Case value
    Case "on"
    tcStringBuilder.Append ("01")
    case "off"
    tcStringBuilder.Append ("00")
    
    Case Else
    tcStringBuilder.Append (value)
    End Select
    
    
    tcString = tcStringBuilder.ToString()
    
    Dim Com as Object
    Dim rxBuff as String
    rxBuff = ""
    
    COMPort.PortName = "COM5"
    COMPort.BaudRate = 9600
    COMPort.Parity = System.IO.Ports.Parity.None
    COMPort.DataBits = 8
    COMPort.StopBits = System.IO.Ports.StopBits.One
    Comport.ReadTimeout = 1000
     
    If COMPort.IsOpen = False Then 
     COMPort.Open() 
    End If
     
    Com = tcString & vbCr
     
    hs.writelog("Audio", "Sending: " & Com)
     
    COMPort.Write(Com)
    
    System.Threading.Thread.Sleep(600)
    
    'Reading the com port:
    rxBuff = (COMPort.ReadExisting)
    
    If rxBuff <> "" Then
    hs.writelog("Audio", "Received:" & rxBuff)
    rxBuff = ""
    End If
    
    COMPort.close()
     
    End Sub

    Leave a comment:


  • Moskus
    replied
    No...

    Leave a comment:


  • mlconti
    replied
    Fixed?

    Originally posted by Moskus View Post
    I'm trying to control the HDMI switch (from Monoprice). This is the exact same script as in HS2:

    Code:
    Sub Main(parm as object)
    hs.OpenComPort(5,"4800,n,8,1",1,"","")
    hs.WaitSecs(1)
    hs.sendtocomport(5, parm.tostring & vbCrLf)
    hs.WaitSecs(1)
    hs.CloseComPort(5)
    End Sub
    (for example, calling sub "Main" with parameter "OFF").

    And this worked without problems in HS2. The same methods with the same arguments exist in HS3, but I get no reaction from the switch.

    What gives?
    Did you ever get this figured out?

    Leave a comment:


  • Moskus
    started a topic Does hs.SendToComPort work or is it only me?

    Does hs.SendToComPort work or is it only me?

    I'm trying to control the HDMI switch (from Monoprice). This is the exact same script as in HS2:

    Code:
    Sub Main(parm as object)
    hs.OpenComPort(5,"4800,n,8,1",1,"","")
    hs.WaitSecs(1)
    hs.sendtocomport(5, parm.tostring & vbCrLf)
    hs.WaitSecs(1)
    hs.CloseComPort(5)
    End Sub
    (for example, calling sub "Main" with parameter "OFF").

    And this worked without problems in HS2. The same methods with the same arguments exist in HS3, but I get no reaction from the switch.

    What gives?
Working...
X