No announcement yet.

OpenComPort... and jump

  • Filter
  • Time
  • Show
Clear All
new posts

    OpenComPort... and jump

    I've read dozens of posts about OpenComPort and handling incoming data but to no avail. Any puzzle solvers out there?

    I'm trying to control a Russound ST2 dual tuner radio via HS scripts. Also, I am still using HS v1.7. Sending data to control the radio is easy. Getting incoming data that I can do anything with isn't. The ST2 communicates in Hex and has a start bit of F0 and an end bit of F7. The second to last bit is a check sum. It sends two streams, one for each tuner.

    I use the following to open the comport (5) with no problem:


    In a text file called datastring.txt I have the following:

    strdata = hs.GetComPortData(5)

    hs.writelog "Com 5 Raw data", strdata

    In looking at Portmon and my hs log I see similar but strange results. Here's the problem.

    First, the incoming data for each tuner is delivered in 5 separate strings each, a total of 10 since there are 2 tuners. I would have expected one long string, or at least 2 long strings, one for each tuner. I've tried using mode 1 in the OpenComPort statement and adding the term parameter for the end bit F7 but keep getting an error message "wrong number of arguments or invalid property assignment"

    Each string is 14 characters long except for the last which is 6. I've listed what is returned in hex, ascii via portmon and what is shown in the hs log. I only used writelog to see what data is being received by HS.

    For Tuner 1:

    string 1 Hex: F0 7D 00 79 00 7D 00 00 02 01 01 02 01 01 - Last Char=49
    string 1 ascii: .}.y.}........
    string 1 hs log: a character I don't recognize, sort of a o with an * over it followed by }

    string 2 Hex: 00 00 01 00 28 00 10 00 00 31 30 33 2E 33 - Last Char=57
    string 2 ascii: ....(....103.3
    string 2 hs log: totally blank (don't know why its blank???)

    string 3 Hex: 20 4D 48 7A 20 46 4D 00 5A 5A 5A 5A 5A 5A - Last Char=65
    string 3 ascii: MHz FM ZZZZZZ
    string 3 hs log: MHz FM

    string 4 Hex: 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A 5A - Last Char=65
    string 4 ascii: ZZZZZZZZZZZZZZ
    string 4 hs log: ZZZZZZZZZZZZZZ

    string 5 Hex: 5A 5A 5A 5A 24 F7 - Last Char=55
    string 5 ascii: ZZZZ'.
    string 5 hs log: ZZZZ* followed by the divided by symbol

    Tuner 2 is the same except it shows what station it is tuned to.

    So, any ideas how I can end up with a variable to show what each tuner's station is set to? Even if I could end up with two 48 bit strings (one for each tuner) I could then parse the data and create variables. Or even if I could somehow create variables for each of the five strings I could parse those.

    I know this is strange but would appreciate any thoughts from the serial gurus.


    I'm not sure how you specified the stop byte F7 in Mode 1, but hopefully it was as chr(247)?

    Try the following ahead of hs.writelog:

    for index = 1 to len(stringdata)
    onebyte = mid(stringdata,index,1)
    if onebyte<>"" then
    checkbyte = asc(onebyte)
    if checkbyte<48 then
    end if
    if checkbyte>127 then
    end if
    end if
    hs.writelog "output in ASCII",stringdata

    That will at least gather all the data into readable format.


    Last edited by Midon; February 2, 2006, 07:03 AM.


      Hi Mitch,

      You were right on with the incorrect stop byte. I now get exactly two results in writelog - perfect. I get data I can parse to my heart's content.

      If I may be so bold... that great code snippet you sent handles each string and executes the writelog sequentially. Since the radio sends two strings on each event (tuner 1 and tuner 2), it writes to the log twice, once with each tuner's data.

      Unfortunately in trying to set variables, the second string always overwrites the first. I've tried using counters and different conditional statements but with no luck. I guess the flow would be: 1) get first string, set variable one 2) get second string, set variable two, 3)end.

      As always, much thanks in advance for any help.



        Hi Rick,

        Save the first string to a external variable maybe?

        CheckifBlank = hs.GetVar("tuner1")
        if CheckifBlank="" then
        hs.SaveVar tuner1,stringdata 'save the first string if not already blank
        hs.SaveVar tuner1,""
        end if

        The idea here is to save the first string to an external variable, wait for the second string, then combine the two.




          Thanks so much for your help. Finally, after 6 months, I have control and response from my Russound ST2!!!!



            Glad to be of help!