PDA

View Full Version : read bytes number in Hserin



Rony
- 11th July 2010, 18:13
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

Rony
- 11th July 2010, 19:11
sorry for writing : hserin ,HD,[str buffer\50]


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

HenrikOlsson
- 11th July 2010, 19:49
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.

Rony
- 11th July 2010, 20:42
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

Darrel Taylor
- 11th July 2010, 23:40
... 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 ...
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,

mackrackit
- 11th July 2010, 23:55
Two questions Darrel.

Will that also work with SERIN2?

Where did you get your manual?
I want one like you have :)

Darrel Taylor
- 12th July 2010, 01:53
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.


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 ....

Rony
- 12th July 2010, 05:34
Thank you Darrel,
i'll try today when arriving home.
Have a nice day.
Rony

HenrikOlsson
- 12th July 2010, 06:42
Now, that's nice to know Darrel, thanks a lot!

/Henrik.

sayzer
- 12th July 2010, 07:25
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 ...
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?
:)

Darrel Taylor
- 12th July 2010, 22:58
Do you know how Dolphins meet their need for drinking water?
:)
I would assume they do they same thing we do ... drink Beer. :D

sayzer
- 13th July 2010, 09:50
I would assume they do they same thing we do ... drink Beer. :D

"we" who?

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

--------------

Rony
- 13th July 2010, 15:13
Thank you Darrel
it is working as i want.

Rony

Rony
- 13th August 2010, 10:32
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