Go Down

Topic: Serial freeze (Read 5929 times) previous topic - next topic

Robin2

#15
Oct 10, 2016, 10:16 am Last Edit: Oct 10, 2016, 10:23 am by Robin2
do you think i should send data in bytes rather than char?
I prefer to send data in human readable form unless that really causes a performance problem. Human readable data makes debugging very much easier.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

schizoping

#16
Oct 10, 2016, 12:20 pm Last Edit: Oct 10, 2016, 02:54 pm by schizoping
I just wanted to ask you some clarification about the serial input buffer, both for arduino and for PC.
I saw there is a define in the arduino source that you can hack for more input buffer... my questions are: is there a limit to this buffer? is there an hardware buffer for the serial port? how can i know the size of both software/hardware serial buffer on windows side? (i'm using mingW c++ with windows API).
Can you link me a good lesson that goes a little in depth about this stuffs?
I don't think i need all this knowledge for the program i'm writing, but it's just to understand better the stuffs i'm using.
Thanks a lot

PaulS

Quote
my questions are: is there a limit to this buffer?
There is a limit on the amount of SRAM available. The buffers (one for incoming, one for outgoing) need to live in SRAM, along with every other variable and string literal (unless efforts are taken to keep them out), and the stack.

Quote
is there an hardware buffer for the serial port?
No, the buffers are in software.

Quote
how can i know the size of both software/hardware serial buffer on windows side?
The sizes are defined by that #define statement you were looking at, for the software side. The hardware doesn't have a buffer; it deals with one character at time.

schizoping

Another question, this time about the pyton example: what's the purpose of the lenght byte you send within the messages since there are the start/stop marks?

Robin2

#19
Oct 10, 2016, 03:29 pm Last Edit: Oct 10, 2016, 03:30 pm by Robin2
I just wanted to ask you some clarification about the serial input buffer, both for arduino and for PC.
I saw there is a define in the arduino source that you can hack for more input buffer..
It would only be necessary to change the buffer size in very special circumstances.

With the code in Serial Input Basics you can receive as many bytes as you have memory space for. Just change the value of the contant numChars to suit your requirement. My code will empty the serial input buffer much faster than serial data can arrive to fill the buffer.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

schizoping

It happens in my program that i have to recieve more than 64 bytes in one message....
Now, for every loop i have a lot analogread() calls (16 in the worst case).
Even if I "unfold" the for cycle in which i read the 16 channel, one analogread takes almost 100us which it's comparable with the trasmission time of one character (~104us at 9600), so I have to prevent in some way the buffer overflow...

Ok, what's wrong in this reasoning? XD

Robin2

If you do 16 analogRead()s so that 16 characters arrive then your code can empty the buffer before the next 16 reads are due. As long as fewer than 64 characters arrive while the Arduino is doing other things you won't have a problem.

This is an unreal discussion when you have not posted your code nor explained what your project is.

...R
 
Two or three hours spent thinking and reading documentation solves most programming problems.

schizoping

ok i'll come back when the code is complete

Robin2

ok i'll come back when the code is complete
Why not now, before you invest too much time in something that may not work?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up