Announcement

Collapse
No announcement yet.

Question about GetComPortEx

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

    Question about GetComPortEx

    I am using GetComPortEx and I am looking for a chr(13) as the terminator.

    e=hs.OpenComPortex(1,"9600,n,8,1",0,"iButtonCb.txt","main",c hr(13))

    The device I am talking to sends a string of 16 characters to Homeseer. I see only the first 8, and then on the next call to the iButtonCb script, it reads the last 8 characters. This shouldnt happen as far as I understand. I am using the line:
    data = hs.GetComPortData(1)
    in my callback script. Is there an 8 character limit? Do I need to define the variable Data to be bigger? Anyone have any insight into this?

    And one more question. The help files say that mode 0 returns each character, and mode 1 returns the whole string, but then it goes on to say that it looks for the chr(13) above, if specified, and waits to call the iButton.txt script until it sees the terminating character. Any insight there ? Does mode not matter if you specify the terminating character?
    A computer's attention span is as long
    as it's powercord.

    #2
    The com port functions will return a character when it is received or will do a little buffering for you and return a line rather than a character. (Mode 0 vs Mode 1). A line is defined as the set of characters terminated by the two consecutive characters Cr and Lf. In your case you need to use Mode 0 because you want the Cr and you do now know if a Lf will follow it or not.

    Data is received by the hardware and placed in a small local buffer which is typically 8 or 16 characters deep. This is done because the OS may be busy the instant the character is received. At the next opportunity the OS will provide HS the event that character(s) are in the buffer. HS will then issue a callback for each character. I'm assuming that it will read all characters available and generate a callback for each in sequence.

    If the hardware buffer is not read before it fills up then characters are dropped. This should not be a problem with today's processors.

    Comment


      #3
      Well, I still cant see anything I'm doing wrong. It seems like it is limited to 8 characters for the incoming buffer, and then it calls the script. Then when the next 8 characters somes in, it sends those. So I get two calls to the script with 1/2 of the data in each time.
      A computer's attention span is as long
      as it's powercord.

      Comment


        #4
        Hi,
        Using mode 0 I would read an ibutton device and used this inside my script to get all the characters
        e=""
        if hs.GetComPortCount(1) > 0 then
        e=e & hs.GetComPortData(1)
        end if
        Then I would strip the data
        select case (left(e,16))
        etc....
        Stuart

        Comment


          #5
          So, did this return the whole 16 characters to you? Or did it just send you one character at a time?
          A computer's attention span is as long
          as it's powercord.

          Comment


            #6
            Well, I tried your code above, and it does read the data like it did before. After 8 characters, it gets sent to the callback script. What I have is a msgbox pop up with the data received. I get two msgboxes with half the data in each one.
            A computer's attention span is as long
            as it's powercord.

            Comment


              #7
              Sdanks,
              Hi, I could send you my ibutton script and see if would help you.
              Stuart

              Comment


                #8
                Have you tried looking at the data using something like Hyperterminal to confirm that you are not receiving the chr(13) after the first 8 characters? Is it possible that the device sends the messages in two 8-character segments - each terminated with a chr(13)?

                If you are using the standard call back with data in the argument (i.e., so that the subroutine starts with "sub main(data)") then you don't need this statement:
                data = hs.GetComPortData(1)
                The variable "data" will automatically have the correct value. In fact, this may be causing your problem. Your call to GetComPortData may be returning the remnants of the buffered information - and overwriting the data that you actually want.

                If your subroutine starts "sub main(data)" then try removing your "data = ..." line and see if it works.

                By the way, there shouldn't be any size limit on the data variable. It should be a variant, which will allow it to be any size string required.

                I use this stuff quite a bit (and look for chr(13) as a terminator) and have not run into problems.
                Last edited by ; November 23, 2004, 09:48 PM.

                Comment


                  #9
                  Hi Smee. Well, I seem to remember using Sub Main(data) and having trouble. So I switched to getting the data myself. But, I wrote a VB app that reads my HA7E. It is a device that reads iButtons. Anyway, i might try the Sub Main(data) again. I should be able to go get the data and make that work. HyperTerm shows the data coming in o.k. But, after receiving it, it doesnt show the <cr> in readable format. So, although it might be there, I doubt it is. I will try the sub thing.
                  A computer's attention span is as long
                  as it's powercord.

                  Comment

                  Working...
                  X