Go Down

Topic: Clearing serial buffer solved (Read 131575 times) previous topic - next topic

Delta_G

#30
Jun 10, 2018, 03:38 am Last Edit: Jun 10, 2018, 03:39 am by Delta_G
Yes, print will block if the buffer is full.  cant post the code from print.h right now but it's there. 

This is the reason Serial print from an interrupt is so dangerous.  Nothing leaves the buffer because the interrupts are off and print deadlocks waiting for room in the buffer. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

pepelevamp

Because throwing away serial data without any regard for what is there is generally considered "stupid as f&%k" and the people who wrote the language weren't generally that stupid.  If you're throwing away random amounts of data you should at least be looking for valid packet start markers while you do it.  But really, if you find yourself just blasting through throwing much away then you probably have a seriously flawed program or protocol and you should really fix that first. 
I'm gonna call you on this. You shouldn't be calling scenarios like that stupid, making him feel bad.

I present a simple counter-example:
Random data which made its way through 8N1 encoding when your RX receiver was listening to data on a bus intended for another receiver.

This is the case in my project, and I'm not doing something 'stupid'. I'm using a single wire for both RX and TX, and when in RX, the baud rate is different from the TX baud rate.  Some times you need to send out a command to change TX properties and reinitialize your receiver, clearing prior data you know is junk.

I too was looking for a simple method to clear the input buffer aside from a while loop.
I like to spend a lot of time & money on finding ways to save time & money.

Delta_G

Quote
Random data which made its way through 8N1 encoding when your RX receiver was listening to data on a bus intended for another receiver.
If you are throwing out the whole buffer, how do you know where the random data ends and the good data starts?  I'll say it again, throwing away data without knowing what it is that you are throwing away is foolish.  I'm sure you'll find some corner case where it makes sense to you, but it is still foolish from a design perspective.

If your receiver is picking up random garbage from some other bus that it wasn't supposed to be listening to then you have a design issue, not a need to throw away data. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

multimedia

In my case the lcd screen only holds x number of chars, so all good i wana be able to clear it to then print new input when thats the case but not if no new input comes in.

pepelevamp

If you are throwing out the whole buffer, how do you know where the random data ends and the good data starts?  I'll say it again, throwing away data without knowing what it is that you are throwing away is foolish.  I'm sure you'll find some corner case where it makes sense to you, but it is still foolish from a design perspective.

If your receiver is picking up random garbage from some other bus that it wasn't supposed to be listening to then you have a design issue, not a need to throw away data. 
If the given design dictates that you know its all garbage, then its not foolish from a design perspective. And there's no 'design issue' - theres imposed constraints.

Don't be so righteous - there is a world of scenarios out there you haven't heard of and likely won't. You're not going to win this one - just take it on the nose that you shouldn't tell people they're foolish for their choices when you have no backstory.

There is a million scenarios where you are listening to garbage but you can TX out a command to clear it. Radio encounters jokes like this all the time. Be helpful.

I like to spend a lot of time & money on finding ways to save time & money.

Delta_G

whatever kid. 
It's just like the mailbox.  If you throw away without knowing why it is then how you know it wasn't a big check from Ed McMahon?   

If you know it is garbage then that isn't throwing it away randomly.  But the question becomes how do you know it is garbage?   

And yes, if you're having this problem then show me the design and I can fix it so you don't need to do something like this.  If you do it right you don't have to throw away data you don't know what it is.  If you find yourself with random garbage data then there is a better way to do whatever you are doing. 


If you work for me and come to me with a design where you don't know where signals are coming from and can't control things then you'll probably be in the unemployment line real soon.   And I'll get someone who knows what they're doing to rewrite it so that things are under control and we know where our signals are coming from. 

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

pepelevamp

oh yeah big man the employer.

You've just been caught out beating on a newbie and giving him bad advice. All that matters is that you should be helpful and learn that you're wrong somewhere.

It never occurred to you that there might be a side-channel which indicates when data is garbage or understandable. It never occurred to you that the flow control mechanism might actually make it deterministic so you can infer the entire buffer is garbage.

You just didn't think of these things. You just assumed it must be wrong, and because of some principal you know of, it MUST be other people's designs - not your rule of thumb yer sticking to.

You need to stop beating your chest and allow people to teach you things.

I like to spend a lot of time & money on finding ways to save time & money.

Delta_G

If you've got a side channel that tells you the data is garbage then why are you putting it in the buffer?  Why aren't you tossing that data as it arrives?   You're wasting resources.  I'll get someone competent to write this.  Better luck next time. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

multimedia

Ok its for an lcd display using i2c and i dont wish to use any sd card with that in mind heres the code...


https://forum.arduino.cc/index.php?topic=494077.0

is the link to my question please post as reply there or here, up to you.

Delta_G

#39
Nov 23, 2018, 10:25 pm Last Edit: Nov 23, 2018, 10:25 pm by Delta_G
Your problems there have nothing to do with this thread.  That thread is old as hell.  You didn't post your code right.  Your errors are about really simple stuff like undefined functions.  If that's your level of coding then you really have absolutely no place trying to school me on anything. 

If you still need help on that thread then bump it, add some code tags, and wait for someone you haven't spent the last few posts trying to insult. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

pepelevamp

If you've got a side channel that tells you the data is garbage then why are you putting it in the buffer?  Why aren't you tossing that data as it arrives?   You're wasting resources.  I'll get someone competent to write this.  Better luck next time.  
Do you know what the problem is here being solved? Or are you telling someone how to solve the problem. You're acting a mix of both. Which is very poor form. 'Wasting resources' aye. Now you're attributing worth to things without any justification because you don't understand the problem/scenario/constraints.

Look at how much work you gotta to do save face now. Much easier to just learn stuff & be kind aint it?
I like to spend a lot of time & money on finding ways to save time & money.

Go Up