Hi,
I want to get bytes, "more than 1byte, (examp.10 bytes)" from HserReceive... when programme come to HserReceive command waiting for another data... but I don't know how can I get more bytes in one time of HserReceive command...
and also I need to know if it is possible to get bits with same methode...
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
mmotte thanks for your kindly interest and answer...
in the other hand, why i am asking bits?
mean is that, if you have a data with even parity after 4 or 9 bits then you can not seperate them correctly bit by bit... maybe solution should be different but i wanted to ask about getting bit by bit as easy way, if it is possible in gcbasic...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Serial Communication is always fun (or troublesome). It depends on how much you know about the incoming data. Do you know? one char at a time without formatting, a packet of data always the same length, packet of data ending with a particular char, a command with a peripheral address on the first byte, just a one char command? Another thing is do you have time to wait for a byte(blocking) or do you want it to happen in the background as an interrupt when HSER buffer bit flag says it has a byte available.
Here is a little sub that will put a comma separated string into a string buffer. Strings are just like arrays except the first value Buf(0) contains the length.
subget_Hser_stringHSerReceivetempstrL=0Dountiltemp=0x2c'check if another comma which says the end of datastrL=strL+1' Get the LatitudeDataStr(strL)=temp' store data in string variable 1HSerReceivetempLoopDataStr(0)=strL'Set the length of the stringEndsub
This could be a command string ended with a CR and then you would check for the CR instead of a comma.
On the previous post i cited Henry's example.
Henry's example is a classic ring buffer (queue) with an array (80 char) , a head pointer and a tail pointer. When the head and tail are equal , then there is no data available from the buffer. But when they are not equal then the next piece of data is pointed to by the head, (queue(head)) and the last stored data is in the buffer at the tail position.(queue(tail) And the next HSER input byte is stored in tail+1 until your reach 80 then it resets tail to 0.(that is why it is called ring buffer).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
HSER is hardware serial and you don't look at the bits until it gives you the result.
What you are asking about would be a software serial routine? Which there are in GCB. But it sounds like you want to write your own with special checking software serial routine. Again with enough fortitude that is possible too.
GL
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I want to get bytes, "more than 1byte, (examp.10 bytes)" from HserReceive... when programme come to HserReceive command waiting for another data... but I don't know how can I get more bytes in one time of HserReceive command...
and also I need to know if it is possible to get bits with same methode...
Thanks.
There is a very good example of input buffering by Thomas Henry in the contributors forum. It says MIDI on the title but it is HSER input buffering.
http://sourceforge.net/p/gcbasic/discussion/629990/thread/b8141e3b/
I don't know what you mean about bits. Wouldn't you receive a byte and then look at the bit your interested in?
mmotte thanks for your kindly interest and answer...
in the other hand, why i am asking bits?
mean is that, if you have a data with even parity after 4 or 9 bits then you can not seperate them correctly bit by bit... maybe solution should be different but i wanted to ask about getting bit by bit as easy way, if it is possible in gcbasic...
Last edit: Ufuk Urcan 2015-04-21
Serial Communication is always fun (or troublesome). It depends on how much you know about the incoming data. Do you know? one char at a time without formatting, a packet of data always the same length, packet of data ending with a particular char, a command with a peripheral address on the first byte, just a one char command? Another thing is do you have time to wait for a byte(blocking) or do you want it to happen in the background as an interrupt when HSER buffer bit flag says it has a byte available.
Here is a little sub that will put a comma separated string into a string buffer. Strings are just like arrays except the first value Buf(0) contains the length.
This could be a command string ended with a CR and then you would check for the CR instead of a comma.
On the previous post i cited Henry's example.
Henry's example is a classic ring buffer (queue) with an array (80 char) , a head pointer and a tail pointer. When the head and tail are equal , then there is no data available from the buffer. But when they are not equal then the next piece of data is pointed to by the head, (queue(head)) and the last stored data is in the buffer at the tail position.(queue(tail) And the next HSER input byte is stored in tail+1 until your reach 80 then it resets tail to 0.(that is why it is called ring buffer).
HSER is hardware serial and you don't look at the bits until it gives you the result.
What you are asking about would be a software serial routine? Which there are in GCB. But it sounds like you want to write your own with special checking software serial routine. Again with enough fortitude that is possible too.
GL