defragster
Senior Member+
That looks pretty much wonderful/good - using the now current updated github\cores - at least to above sketch - updated below. So the change updates the count on each 512 packet - which moves above sketch along its test for three unique reports. Then when in the while(read) it gets all those and more. That is the .available() only goes up 512 per loop() - but when running the read it gets them all - though before while (Serial.available()) {read()} .available() is still 1536 when 11,200 are read - assuming those were held up behind the three buffers and arrived during read?
Works well on trivial stuff under 512 in groups - and upwards.
Here are smaller working cases - removed the force read on large size.
Also added [diff] numbers to show the math of incoming bytes difference between the three steps it checks for:
Thought I saw an anomoly on the 11,200 byte file - but doesn't repro now - maybe user error.
Works to read as noted below files of : 2800 Bytes and 5600 and 11,200 byte file ( as sent by TyCommander ).
In case it is useful - or starting point for another test here is the current code that made the above:
Works well on trivial stuff under 512 in groups - and upwards.
Here are smaller working cases - removed the force read on large size.
Also added [diff] numbers to show the math of incoming bytes difference between the three steps it checks for:
Code:
T:\tCode\T4\SerAvailTest\SerAvailTest.ino Dec 1 2019 01:13:07
Waiting for three incoming Avail update counts
Update to incoming Avail counts 145[145] : 0[0] : 0
Update to incoming Avail counts 290[145] : 145[145] : 0
Got three incoming Avail update counts 435[145] : 290[145] : 145 Bytes read 435
Update to incoming Avail counts 289[289] : 0[0] : 0
Update to incoming Avail counts 578[289] : 289[289] : 0
Got three incoming Avail update counts 867[289] : 578[289] : 289 Bytes read 867
Update to incoming Avail counts 289[289] : 0[0] : 0
Update to incoming Avail counts 578[289] : 289[289] : 0
Got three incoming Avail update counts 867[289] : 578[289] : 289 Bytes read 867
Update to incoming Avail counts 433[433] : 0[0] : 0
Update to incoming Avail counts 866[433] : 433[433] : 0
Got three incoming Avail update counts 1299[433] : 866[433] : 433 Bytes read 1299
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 577[65] : 512[512] : 0
Got three incoming Avail update counts 1089[512] : 577[65] : 512 Bytes read 1154
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 577[65] : 512[512] : 0
Got three incoming Avail update counts 1089[512] : 577[65] : 512 Bytes read 1154
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 577[65] : 512[512] : 0
Waiting for three incoming Avail update counts 577 : 577 : 512
Got three incoming Avail update counts 578[1] : 577[65] : 512 Bytes read 578
Update to incoming Avail counts 4[4] : 0[0] : 0
Update to incoming Avail counts 11[7] : 4[4] : 0
Got three incoming Avail update counts 21[10] : 11[7] : 4 Bytes read 21
Thought I saw an anomoly on the 11,200 byte file - but doesn't repro now - maybe user error.
Works to read as noted below files of : 2800 Bytes and 5600 and 11,200 byte file ( as sent by TyCommander ).
Code:
Update to incoming Avail counts 1[1] : 0[0] : 0
Update to incoming Avail counts 2[1] : 1[1] : 0
Got three incoming Avail update counts 3[1] : 2[1] : 1 Bytes read 3
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 1024[512] : 512[512] : 0
Got three incoming Avail update counts 1536[512] : 1024[512] : 512 Bytes read 11200
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 1024[512] : 512[512] : 0
Got three incoming Avail update counts 1536[512] : 1024[512] : 512 Bytes read 11200
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 1024[512] : 512[512] : 0
Got three incoming Avail update counts 1536[512] : 1024[512] : 512 Bytes read 11200
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 1024[512] : 512[512] : 0
Got three incoming Avail update counts 1536[512] : 1024[512] : 512 Bytes read 11200
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 1024[512] : 512[512] : 0
Got three incoming Avail update counts 1536[512] : 1024[512] : 512 Bytes read 2800
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 1024[512] : 512[512] : 0
Got three incoming Avail update counts 1536[512] : 1024[512] : 512 Bytes read 5600
Update to incoming Avail counts 512[512] : 0[0] : 0
Update to incoming Avail counts 1024[512] : 512[512] : 0
Got three incoming Avail update counts 1536[512] : 1024[512] : 512 Bytes read 11200
In case it is useful - or starting point for another test here is the current code that made the above:
Code:
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial && millis() < 4000 );
Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
Serial.printf( "\nWaiting for three incoming Avail update counts \n\n" );
}
int lastAvail = 0;
int lastAvail2 = 0;
elapsedMillis someWait;
void loop() {
int myAvail = Serial.available();
if ( (myAvail != lastAvail && lastAvail != lastAvail2 && 0 != lastAvail2 ) )
{
int ii = 0;
Serial.printf( "\tGot three incoming Avail update counts %u[%u] : %u[%u] : %u", myAvail, myAvail-lastAvail, lastAvail, lastAvail-lastAvail2, lastAvail2 );
while (Serial.available())
{
Serial.read();
ii++;
}
Serial.printf( "\t\tBytes read %u\n", ii);
lastAvail2 = lastAvail = 0;
}
else if ( myAvail != lastAvail )
{
someWait = 0;
Serial.printf( "Update to incoming Avail counts %u[%u] : %u[%u] : %u\n", myAvail, myAvail-lastAvail, lastAvail, lastAvail-lastAvail2, lastAvail2 );
lastAvail2 = lastAvail;
lastAvail = myAvail;
}
else if ( someWait > 10000 ) {
if ( myAvail ) {
someWait = 0;
Serial.printf( "Waiting for three incoming Avail update counts %u : %u : %u\n", myAvail, lastAvail, lastAvail2 );
}
}
}