read bytes number in Hserin


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2007
    Posts
    33

    Lightbulb read bytes number in Hserin

    dear all,

    i am using the command Hserin with a timeout as follows:

    hserin 3,HD,[str buffer\50]

    after 100ms, the program is resuming to the label "main" having in the array variable "buffer" the data received from the serial pin, but the problem i am facing is how can i know the number of bytes received because the trame's length is not constant.

    is there any internal variable that contains the info i need ??

    Thank you for helping.
    Rony

  2. #2
    Join Date
    Feb 2007
    Posts
    33

    Default

    sorry for writing : hserin ,HD,[str buffer\50]


    suppose it is : hserin 100,main,[str buffer\50]

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default

    Hi Rony,
    I don't think there's an internal counter or anything like that. If the string always ends with a certain character you can use that to end the HSERIN. If not maby you can initial the array with all zeros or something else, then when the HSERIN ends due to timeout you itterate thru the array untill you start you "seeing" zeros etc.

    /Henrik.

  4. #4
    Join Date
    Feb 2007
    Posts
    33

    Default

    thanks Henric,

    there is nothing to end the trame in question, and i am currently using the method you mentioned to know the number of the received bytes, and i am filling the buffer with $FF which is not in use till now, but i will use it soon.. that is why i start searching for an internal counter.

    Rony

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Quote Originally Posted by Rony View Post
    ... but the problem i am facing is how can i know the number of bytes received because the trame's length is not constant.

    is there any internal variable that contains the info i need ??
    There is ...
    The number of bytes to receive (50 in your case) is counted DOWN in the HighByte of R4 (PBP system variable).

    So after a timeout, you can ...
    Code:
    RXcount = 50 - R4.HighByte
    It has to be the very first thing you do after a timeout.
    Executing any other PBP statements before getting the count, may change the R4 value.

    hth,
    DT

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Two questions Darrel.

    Will that also work with SERIN2?

    Where did you get your manual?
    I want one like you have
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Yes, HSERIN, SERIN2 or DEBUGIN.
    They all use the same SERIN2STR routine in the library.

    And there's only one manual that completely covers everything about how PBP works.
    Code:
    pbppic14.mac
    pbppic14.lib
    pbppic18.mac
    pbppic18.lib
    etc.
    P.S. That manual is automatically updated with every upgrade/patch.
        Show me a book that can do that ....
    Last edited by Darrel Taylor; - 12th July 2010 at 05:21. Reason: No books
    DT

  8. #8
    Join Date
    Feb 2007
    Posts
    33

    Default

    Thank you Darrel,
    i'll try today when arriving home.
    Have a nice day.
    Rony

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default

    Now, that's nice to know Darrel, thanks a lot!

    /Henrik.

  10. #10
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185

    Default

    Quote Originally Posted by Darrel Taylor View Post
    There is ...
    The number of bytes to receive (50 in your case) is counted DOWN in the HighByte of R4 (PBP system variable).

    So after a timeout, you can ...
    Code:
    RXcount = 50 - R4.HighByte
    It has to be the very first thing you do after a timeout.
    Executing any other PBP statements before getting the count, may change the R4 value.

    hth,

    Good info indeed.
    Thanks Darrel.


    Do you know how Dolphins meet their need for drinking water?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Quote Originally Posted by sayzer View Post
    Do you know how Dolphins meet their need for drinking water?
    I would assume they do they same thing we do ... drink Beer.
    DT

  12. #12
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I would assume they do they same thing we do ... drink Beer.
    "we" who?

    I don't drink Beer, not even a drop of alcohol also !

    --------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  13. #13
    Join Date
    Feb 2007
    Posts
    33

    Default

    Thank you Darrel
    it is working as i want.

    Rony

  14. #14
    Join Date
    Feb 2007
    Posts
    33

    Default

    Hi Darrel,

    i am facing another problem with the "CountBuffer = 50 - R4.HighByte".
    when using the 16F877A, it works very well but since the program starts exceding 8K, i moved to 18F4620 (32K), in which i am facing a new problem:
    when receiving nothing from the serial port, the countbuffer is not ZERO, i think it is ONE, i'll debug to see what is its value but i think it is one instead of zero.
    ANY HELP ??

    Rony

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts