Announcement

Collapse
No announcement yet.

Problems with &asc(")")

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

    Problems with &asc(")")

    Hi all

    I've been playing with a script to handle some serial port data (which is basically an incremental counter) and it works perfectly until it has to process ) ...(the ASCII close bracket, 41 or h29 if you like).

    If I manually try &hs.writelog "Test","ASC " &asc(")") then Hs correctly returns the value 41.

    However in my script :
    Code:
    sub main(Xmitter)
     hs.GetComPortData(comport)
     
     TxDevice=Mid(Xmitter,1,2)
     ID=Mid(Xmitter,3,1)     
    '============================================================== 
     
     b4=asc(Mid(Xmitter,5,1)) 'Picaxe b4
     b3=asc(Mid(Xmitter,6,1)) 'Picaxe b3
     b2=asc(Mid(Xmitter,7,1)) 'Picaxe b2 
     b1=asc(Mid(Xmitter,8,1)) 'Picaxe b1 
     ascii3=(Mid(Xmitter,6,1))
     ascii2=(Mid(Xmitter,7,1))
     ascii1=(Mid(Xmitter,8,1))
     Total=(b4*256)+(b3*25.6)+(b2/10)+(b1/100)
     
     hs.writelog "315Xmitter","Electricity meter ID"&ID &  " Total " &Total
     hs.writelog "315rawdata","EM3 b3=" &b3  &"(" &ascii3 &")" &" b2=" &b2 &"(" &ascii2 &")" &" b1=" &b1  &"(" &ascii1 &")"
     
     
     
    end sub
    whenever the incomming data is ) and has to be processed by b2=asc(Mid(Xmitter,7,1)) or any of the other similar statements to return it's ASCII decimal equivalent, then I just get
    <TABLE cellSpacing=2 cellPadding=0 width="100%" border=0><TBODY><TR><TD class=LOGType0 align=left colSpan=3>Error </TD><TD class=LOGEntry0 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR></TBODY></TABLE>


    In the log you can see the incomming data for b1 incrementing up intil it hits 9, at which point b2 should kick over to 41 or ) ......but I just get plenty of errors......then back to normal once it gets * ( or ascii 42)

    <TABLE cellSpacing=2 cellPadding=0 width="100%" border=0><TBODY><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:11:32 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.05</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:11:32 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=40(() b1=5()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:11:42 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.06</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:11:42 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=40(() b1=6()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:11:52 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.07</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:11:52 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=40(() b1=7()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:12:02 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.08</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:12:02 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=40(() b1=8()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:12:12 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.09</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:12:12 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=40(() b1=9( )</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:12:22 </TD><TD class=LOGType0 align=left colSpan=3>Error </TD><TD class=LOGEntry0 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:12:33 </TD><TD class=LOGType1 align=left colSpan=3>Error </TD><TD class=LOGEntry1 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:12:43 </TD><TD class=LOGType0 align=left colSpan=3>Error </TD><TD class=LOGEntry0 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:12:53 </TD><TD class=LOGType1 align=left colSpan=3>Error </TD><TD class=LOGEntry1 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:13:03 </TD><TD class=LOGType0 align=left colSpan=3>Error </TD><TD class=LOGEntry0 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:13:13 </TD><TD class=LOGType1 align=left colSpan=3>Error </TD><TD class=LOGEntry1 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:13:23 </TD><TD class=LOGType0 align=left colSpan=3>Error </TD><TD class=LOGEntry0 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:13:33 </TD><TD class=LOGType1 align=left colSpan=3>Error </TD><TD class=LOGEntry1 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:13:43 </TD><TD class=LOGType0 align=left colSpan=3>Error </TD><TD class=LOGEntry0 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:13:53 </TD><TD class=LOGType1 align=left colSpan=3>Error </TD><TD class=LOGEntry1 align=left colSpan=8>Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 18 More info: Invalid procedure call or argument: 'asc'</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:14:03 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.2</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:14:03 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=42(*) b1=0()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:14:13 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.21</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:14:13 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=42(*) b1=1()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:14:23 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.22</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:14:23 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=42(*) b1=2()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:14:33 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.23</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:14:33 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=42(*) b1=3()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:14:43 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.24</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:14:43 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=42(*) b1=4()</TD></TR><TR><TD class=LOGDateTime0 noWrap align=left>13/11/2009 16:14:53 </TD><TD class=LOGType0 align=left colSpan=3>315Xmitter </TD><TD class=LOGEntry0 align=left colSpan=8>Electricity meter ID3 Total 4.25</TD></TR><TR><TD class=LOGDateTime1 noWrap align=left>13/11/2009 16:14:53 </TD><TD class=LOGType1 align=left colSpan=3>315rawdata </TD><TD class=LOGEntry1 align=left colSpan=8>EM3 b3=0() b2=42(*) b1=5()</TD></TR></TBODY></TABLE>


    I've checked the incomming data at the port and it's perfect.

    So where am I going wrong? What is it about ),41, because everything else seems to return the correct value in the range 0-255 except ) 41.


    Cheers

    Andy (still on the scripting learning curve)

    #2
    Are you sure that the data ASC is trying to operate on is valid for the command?

    Perhaps do a writelog of your variables to confirm the contents...

    That is a typical cause....

    D
    ---------------------------------------------------http://weather.penicuik.org

    Comment


      #3
      Hi David, and everyone else

      Well I've been playing about with this for a while and I've take it right back to basics.

      Code:
      Comport=7   
      sub main(Xmitter)
       hs.GetComPortData(comport)
       hs.writeLog "Raw data",Xmitter
       
       A1=asc(Mid(Xmitter,1,1)) 
       hs.writelog "Asc result","" &A1
       
      end sub
      It doesn't get any simpler...spit out the asc result of one character, and as you see from the log it still can't do it.

      The results of the characters on either side of " ) " are fine.

      13/11/2009 23:00:46 Raw data &
      13/11/2009 23:00:46 Asc result 38

      13/11/2009 23:01:10 Raw data '
      13/11/2009 23:01:10 Asc result 39

      13/11/2009 23:01:51 Raw data (
      13/11/2009 23:01:51 Asc result 40

      13/11/2009 23:02:04 Raw data
      13/11/2009 23:02:04 Error Running script, script run or compile error in file: 315Script.txt5:Invalid procedure call or argument: 'asc' in line 11 More info: Invalid procedure call or argument: 'asc'

      13/11/2009 23:02:33 Raw data *
      13/11/2009 23:02:33 Asc result 42

      13/11/2009 23:02:59 Raw data +
      13/11/2009 23:02:59 Asc result 43

      13/11/2009 23:03:30 Raw data ,
      13/11/2009 23:03:30 Asc result 44

      As I said in the previous post I can watch the data comming in at the coms port perfectly using a port sniffer.

      I've tried a laptop injecting a single " ) " and a hand held data tester and both give me the same results.


      Any ideas?

      Anybody care to try and stick " ) " into their com port?


      Andy

      Comment


        #4
        Are you sure you are not trying to process a space as that would cause an error.

        Try something like:

        If Mid(Xmitter,1,1) <> " " then A1=asc(Mid(Xmitter,1,1))
        Jon

        Comment


          #5
          Originally posted by jon00 View Post
          Are you sure you are not trying to process a space as that would cause an error.

          Try something like:

          If Mid(Xmitter,1,1) <> " " then A1=asc(Mid(Xmitter,1,1))

          Hi Jon

          Processing a space actually gives the correct value of 32. I tried it with the line above and I still get exactly the same result for " ) " .

          You can see the data it's getting fed with on the screen shot compaired to the log
          Attached Files

          Comment


            #6
            That's weird.

            You can get around the issue with something like:

            If Mid(Xmitter,1,1) = ")" then
            A1=41
            else
            A1=asc(Mid(Xmitter,1,1))
            end if
            Jon

            Comment


              #7
              Originally posted by jon00 View Post
              That's weird.

              You can get around the issue with something like:

              If Mid(Xmitter,1,1) = ")" then
              A1=41
              else
              A1=asc(Mid(Xmitter,1,1))
              end if
              Hi Jon

              Unfortunately that doesn't work either.

              It must be because the data comming in is bad so HS never sees ")" for the statement to make it = 41, therefore it still tries to do the Asc on it.

              I might stick another post on the forum asking if anyone would be kind enough to stick a ")" in through a com port and see what result they get.


              It's a bit of a head scratcher.

              Many thanks

              Andy

              Comment


                #8
                I just thought that I'd post a reply I got from Rick explaining why "Asc )" doesn't work.


                This is because of the way that the data from a script is handled. When you opened the COM port, you told HomeSeer the name of the script that you want run when data arrives. Unfortunately, the way that data is passed to a script is by running the script with parameters enclosed with parenthesis, and so a parenthesis in the data will cause problems with this.

                To fix this at our end, we will have to change how we make the COM port data available to scripts by exposing an object to the scripting interface so that we can run the script without having to pass the data as an argument. Thus, this will take a while to fix.

                Comment

                Working...
                X