| ??? 04/01/10 14:46 Read: times |
#174750 - nothing impossible Responding to: ???'s previous message |
Baptiste Pomechicot said:
It's impossible to send chars in background because I usually need to send more than one string to the serial port
Exemple : buffer's length = 255 foo() { nbrToSend = sprintf(buffer, [string of 255 chars]); flush(); nbrToSend = sprintf(buffer, [string of 255 chars]); flush(); } if the function flush don't block in infinity loop while all chars are sent, I'll have a problem when I'll call the second sprintf which will rewrite the buffer with new chars. I said to return to your main loop and only send new data when the buffer is empty. Example: main()
{
while(1)
{
foo(); //call foo
bar(); //have a drink while waiting
wd(); //feed dog
}
}
foo()
{
static char state = 0;
switch (state)
{
case 0:
nbrToSend = sprintf(buffer, [string of 255 chars]);
state++;'
case 1:
if (flush()) //returns true when flushed
state++;
case 2:
nbrToSend = sprintf(buffer, [string of 255 chars]);
state++;'
case 3:
if (flush()) //returns true when flushed
state++;
default:
state = 0;
}
}
And if you use a ring buffer large enough you could even use the original code without waiting. |



