Announcement

Collapse
No announcement yet.

Need Help with a Simple Relay Script

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

    Need Help with a Simple Relay Script

    Hello everyone, I'm new to HS Script.
    I have recently purchased a relay switch, it requires 9 Bytes Hex Command to control "ON" and "OFF"


    Here is my script, however it does not trigger relay actions.
    What would be the correct way to write this?
    Thanks for all your help.


    PHP Code:
    Const ComPort 1
    Const ComConfig "9600,N,8,1"
    Const ComMode 0
    Const ComScript ""
    Const ComFunct ""
    Sub Main()
      
    Dim sRetVal
    ' Open the com port
       sRetVal = hs.OpenComPortEx(ComPort, ComConfig, ComMode, ComScript, ComFunct)
       if sRetVal <> "" then
          hs.CloseComPort ComPort
          sRetVal = hs.OpenComPortEx(ComPort, ComConfig, ComMode, ComScript, ComFunct)
       end if
    Send the requested Hex "Relay On" to the Relay
       hs
    .SendToComPort ComPort,"00 5A 55 00 01 01 00 00 B1"
    ' Wait for the response
       InData = hs.GetComPortData(ComPort)
       msgbox InData
       hs.CloseComPort(ComPort)
    end sub 

    #2
    Take a look at this post: http://board.homeseer.com/showthread.php?t=133573
    Jon

    Comment


      #3
      Originally posted by umpcfans View Post
      Hello everyone, I'm new to HS Script.
      I have recently purchased a relay switch, it requires 9 Bytes Hex Command to control "ON" and "OFF"....
      Can you post a link to the product website or, better yet, a link to the manual?
      Best regards,
      -Mark-

      If you're not out on the edge, you're taking up too much room!
      Interested in 3D maps? Check out my company site: Solid Terrain Modeling

      Comment


        #4
        Thanks for your help Jon00, I will try it out tonight.

        Originally posted by mfisher View Post
        Can you post a link to the product website or, better yet, a link to the manual?

        Hi, it was a customized order from Shenzhen China. Industrial grade at Resonable price and pretty reliab le. However, it does not come with the case.
        The website have not got much technical data, it's an online store like ebay, the development softwares and source code were came with a CD. The price is about $39 for 16-way serial relay. this store have many other boards with serial command capable. For example SMS modem, Switch Sensors etc.

        Here is a link for reference, however, no english. sorry.

        http://item.taobao.com/item.htm?id=4963067518
        Last edited by umpcfans; December 4, 2010, 11:09 PM.

        Comment


          #5
          Thanks Jon00, I'm quite new to scripting, I have managed the script into the following arrangement
          However, I got this error, Could you help with a complete script? Your help is very apprecited.


          2011-1-4 11:53:36 - Error - Script compile error: Method arguments must be enclosed in parentheses.on line 28

          2011-1-4 11:53:36 - SCR - Option Strict Offimports Schedulerimports SystemPublic Module scriptcode3#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin <System.ContextStaticAttribute()> Public WithEvents hs As Scheduler.hsapplication <System.ContextStaticAttribute()> Public WithEvents hsp As scheduler.hsp <System.ContextStaticAttribute()> Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End RegionSub Main(ByVal Parm As Object) Dim MyHexString As String MyHexString="00 5A 55 00 01 01 00 00 B1" SendHex(MyHexString) end subSub SendHex(ByVal MyHexString As String) Dim HexS() As String Dim ComPort As Integer = 1 Dim I As Integer Dim sRetVal sRetVal = hs.OpenComPortEx(ComPort,"9600,N,8,1",0,"","") if sRetVal <> "" then hs.CloseComPort ComPort sRetVal = hs.OpenComPortEx(ComPort,"9600,N,8,1",0,"","") end ifHexS = MyHexString.Split(" ") Dim data(HexS.length) As byte For I = 0 To HexS.length-1 data(I)=CLng("&h" & HexS(I)) hs.sendtocomport (Comport,Chr(Data(I))) Nextend subEnd Module



          PHP Code:

          Sub Main
          (ByVal Parm As Object
              
          Dim MyHexString As String 
              MyHexString
          ="00 5A 55 00 01 01 00 00 B1" 
              
          SendHex(MyHexString
          end sub

          Sub SendHex
          (ByVal MyHexString As String

          Dim HexS() As String 
          Dim ComPort 
          As Integer 
          Dim I 
          As Integer 
          Dim sRetVal
             sRetVal 
          hs.OpenComPortEx(ComPort,"9600,N,8,1",0,"","")
             if 
          sRetVal <> "" then
                hs
          .CloseComPort ComPort
                sRetVal 
          hs.OpenComPortEx(ComPort,"9600,N,8,1",0,"","")
             
          end if

          HexS MyHexString.Split(" "
          Dim data(HexS.length) As byte 
          For 0 To HexS.length-
              data
          (I)=CLng("&h" HexS(I)) 
              
          hs.sendtocomport (Comport,Chr(Data(I))) 
          Next
          end sub 

          Comment


            #6
            Originally posted by umpcfans View Post
            Thanks for your help Jon00, I will try it out tonight.




            Hi, it was a customized order from Shenzhen China. Industrial grade at Resonable price and pretty reliab le. However, it does not come with the case.
            The website have not got much technical data, it's an online store like ebay, the development softwares and source code were came with a CD. The price is about $39 for 16-way serial relay. this store have many other boards with serial command capable. For example SMS modem, Switch Sensors etc.

            Here is a link for reference, however, no english. sorry.

            http://item.taobao.com/item.htm?id=4963067518
            Just de-railing this thread slightly sorry, i'm quite interested in some of those boards - the one which looks like a 12 input 12 relay output especially - can I ask are they happy with an order of just one board and are all of the manuals english?

            Comment


              #7
              The error is caused by the lack of brackets around the close comport command i.e.

              hs.CloseComPort (ComPort)

              BTW, did the alternative uptime script work for you?
              Jon

              Comment


                #8
                Thanks Jon00, Finally, The script is running. Great Work.
                I have replied the post previously on UPTIME Script. Sorry for the delay.
                It looks like the command has been sent succesfully to the relay, RX LED on the relay was flashing while HEX was sending. But, there was no actual trigger to the relay. I have used serial command tools to send hex command like "00 5A 55 00 04 00 00 00 B3" with no problem. Is there anything else I should to pay attention on this script?

                I have obtained the control Source code of the relay in VB.NET , But got so confused. Attached source code to this post if that may help something.
                Attached Files
                Last edited by umpcfans; December 6, 2010, 04:50 AM.

                Comment


                  #9
                  Originally posted by mrhappy View Post
                  Just de-railing this thread slightly sorry, i'm quite interested in some of those boards - the one which looks like a 12 input 12 relay output especially - can I ask are they happy with an order of just one board and are all of the manuals english?
                  Can you provide specific links to those products that you are interested in?
                  I'm pretty sure they will offer one unit sample order. They'll provide C++, VB, VB.NET source code as well, even with the compiled .exe program. I don't think they have any english manual support, if you are able to read all the source script, it should help you through everything. The board itself will label details.They have a diagram in chinese, I can help to translate if you need.
                  Last edited by umpcfans; December 6, 2010, 04:55 AM.

                  Comment


                    #10
                    Originally posted by umpcfans View Post
                    Thanks Jon00, Finally, The script is running. Great Work.
                    I have replied the post previously on UPTIME Script. Sorry for the delay.
                    It looks like the command has been sent succesfully to the relay, RX LED on the relay was flashing while HEX was sending. But, there was no actual trigger to the relay. I have used serial command tools to send hex command like "00 5A 55 00 04 00 00 00 B3" with no problem. Is there anything else I should to pay attention on this script?

                    I have obtained the control Source code of the relay in VB.NET , But got so confused. Attached source code to this post if that may help something.
                    I see no reason why this should not work. These things are difficult to diagnose unless you can see what is sent from the serial port. Do you have another spare port on your PC? If so, link the data out on the first port to the data in on the second port. Then use a terminal program to monitor this second port. Compare the strings sent by your serial command tool Vs Homeseer.
                    Jon

                    Comment


                      #11
                      Originally posted by umpcfans View Post
                      Can you provide specific links to those products that you are interested in?
                      I'm pretty sure they will offer one unit sample order. They'll provide C++, VB, VB.NET source code as well, even with the compiled .exe program. I don't think they have any english manual support, if you are able to read all the source script, it should help you through everything. The board itself will label details.They have a diagram in chinese, I can help to translate if you need.
                      This one I was interested in http://translate.google.com/translat...d%3D2484293734 (not that google is that good at the translation) but for a 12 input 12 output (considering they are opto isolated inputs and relay outputs) board that does seem like a good price - depending on how easy it is to actually interface with that is, and the fact they supply vb.net examples is a good start.

                      I might order one and just see if they will send me one, if they take my card that is.

                      Comment


                        #12
                        Sorry everyone, I was on an urgent mission without internet from last week, i will be back home on sunday.

                        Comment

                        Working...
                        X