Announcement

Collapse
No announcement yet.

Read from com port

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

    Read from com port

    I have looked but I'm not coming up with an answer for my issue. I would like to trigger an event or display the data by receiving ASCII from a com port. First how do I read a com port? Once I read the data how do I break it down from what may or may not be a string and use the data to trigger an event or display it?

    For instance here is the break down of a command I my receive from my Xantech MRC88.

    #6ZS PR1 SS4 VO8 MU0 TR7 BS7 BA32 LS0 PS0+


    This line tells us the following info about Zone 6:









    Most of this info will be needed to run my audio system.Here is one example. I will need to display the volume and manage the volume control on HSTouch based on the data I have received and what will be coming in.

    If someone can answer my questions or point me in the right direction I would be very grateful.

    Craig

    #2
    You can send data and retrieve data from a com port using scripts. Take a look at OpenComPort and GetComPortData in the Users Guide.
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Once you open a com port in HS using the hs.opencomport command then everytime data arrives on the port a specified script & function is called. The data it receives on the COM port is passed into this script as a parameter, it is then a case of reading this parameter and performing whatever string manipulation you need.

      There are many different ways of getting the data you need, one method might be once you get this string to split it into an array based on the space character so you end up with an array full of the data for you to then update device strings/values with that could end up in HSTouch.

      Comment


        #4
        OK I'm following someones script example from a while back(see below). I'm sending a request for the data, now that I've sent it how do I know If ist's been sent and how do I receive it to ether trigger something or display it on HSTouch? Will it need to become a device and if it is how?

        sub main()
        Dim PortNumber
        PortNumber=4
        hs.OpenComPort PortNumber,"9600,N,8,1",1,"zone1 statas.txt","main"
        hs.SendToComPort PortNumber,"?1ZS+" & vbcr
        hs.waitsecs 1
        hs.closeComPort(PortNumber)
        end sub
        sub main(data)
        hs.writelog "Test","zone1 statas=" & data
        end sub

        Comment


          #5
          I can't see any glaring errors in those scripts, if you are getting no data from the COM port printed in the HS log then there must be something wrong with either the opening of the port or the string you are sending it.

          Before you go onto worry about devices and getting the data anywhere like HSTouch reach a point when you can get it printed in the log.

          You can combine the two scripts together like this if it makes it easier (if this was called sertest.txt);

          Code:
          sub main() 
          Dim PortNumber 
          PortNumber=4 
          hs.OpenComPort PortNumber, "9600,N,8,1", 1, "sertest.txt", "receive" 
          hs.SendToComPort PortNumber, "?1ZS+" & vbcr 
          hs.waitsecs 1 
          hs.closeComPort(PortNumber) 
          end sub 
          
          sub receive(data)
          hs.writelog "Test", "zone1 statas=" & data 
          end sub
          Couple of thoughts;

          1) have you verified these commands work in something like Hyperterminal or are the sample strings you posted earlier from the manual?
          2) do you have any other applications running that are using the port at the minute?
          3) the hs.OpenComPort command returns a string which shows if there were any issues with opening the port (port does not exist/already open etc). It might be worth testing the reply you get so your script would look like this;

          Code:
          sub main() 
          Dim PortNumber 
          Dim RespStr
          PortNumber=4 
          RespStr = hs.OpenComPort PortNumber, "9600,N,8,1", 1, "sertest.txt", "receive" 
          hs.writelog "SerOpen", RespStr
          hs.SendToComPort PortNumber, "?1ZS+" & vbcr 
          hs.waitsecs 1 
          hs.closeComPort(PortNumber) 
          end sub
          4) Possibly consider a second wait command after you open the port before you send the data (perhaps another second), might not be absolutely needed but gives the port a chance to open.

          Comment


            #6
            1) have you verified these commands work in something like Hyperterminal or are the sample strings you posted earlier from the manual?
            Yes it is responding to that and other commands.

            2) do you have any other applications running that are using the port at the minute?
            No, that port is deadacated to the MRC88.

            3) the hs.OpenComPort command returns a string which shows if there were any issues with opening the port (port does not exist/already open etc). It might be worth testing the reply you get so your script would look like this;
            I tried that script and I got this error.

            12/23/2011 3:44:08 PM - Error - Running script, script run or compile error in file: get zone1 statas.txt1025:Expected end of statement in line 5 More info: Expected end of statement

            I'm not sure of my next step?

            Craig

            Comment


              #7
              OK I'm taking a step back and trying something a little more simple.

              Below is a sample script I'm trying. This is being done with my HAI Omin Pro. I an having HAI send a message from com2 to com1 on HS.(away, night, disarm) I run the script and see that the port has opened. Then I arm the system I an getting in the log. Once a port is opened it stays opened, right?

              sub main()
              dim e
              e=hs.OpenComPort(1,"9600,n,8,1",1,"com_event.txt","main")
              if e <> "" then
              hs.writelog "Error opening com port",e
              end if

              ' if you need to send data to the com port when the port is open, it can be done here
              hs.SendToComPort 1,"at"+vbcrlf

              hs.writelog "COM SCRIPT","Script Complete"
              end sub

              Comment


                #8
                Originally posted by stinggray View Post
                OK I'm taking a step back and trying something a little more simple.

                Below is a sample script I'm trying. This is being done with my HAI Omin Pro. I an having HAI send a message from com2 to com1 on HS.(away, night, disarm) I run the script and see that the port has opened. Then I arm the system I an getting in the log. Once a port is opened it stays opened, right?
                Generally yes, unless it is closed by another program or script.

                Not sure if you missed a word in the above post? What do you get in the log? Nothing?

                And in that first string sorry this line should be changed to this;

                RespStr = hs.OpenComPort(PortNumber, "9600,N,8,1", 1, "sertest.txt", "receive")

                Are you getting any errors in the log when you try and open the port?

                Comment

                Working...
                X