Page 1 of 1

while(Serial.available()<=0);

Posted: 16 Aug 2018 20:51
by MastrUsr
while(Serial.available()<=0);

Why does this not work on the Z-Uno? It hangs and can't be accessed unless I plug it in while holding the service button. Is this because of the Z-Wave-part being processed? I remember reading something about that...

Re: while(Serial.available()<=0);

Posted: 18 Aug 2018 19:53
by PoltoS
Check our example like http://z-uno.z-wave.me/projects/control ... e-network/

You should use
while (Serial1.available()) {

Re: while(Serial.available()<=0);

Posted: 18 Aug 2018 19:56
by PoltoS
If you want to wait until there is something, you should add a delay(10) inside. Delay still allows radio and Z-Wave part to execute

Re: while(Serial.available()<=0);

Posted: 18 Aug 2018 23:45
by MastrUsr
I'm sorry, I was using Serial1, i failed to copy from the right Sketch :/

So this is the code:

Code: Select all

//Function:wait data packet send finish
unsigned char WaitFpData(void)
{
    int i;
    unsigned char rBuf_p = 0;
    
    while(Serial1.available()<= 0);
    
    for(i=200; i>0; i--)//wait response info
    {
        delay(20);
        rBuf[rBuf_p++] = Serial1.read();
        
        if(Serial1.available() == 0)
        {
            g_ucUartRxEnd = 1;
            g_ucUartRxLen = rBuf_p;
            break;
        }
    }
    
    if(rBuf_p == 0) return 0x00;
    else return 0x01;
}


It's for a fingerprint reader and it wait until there is data send with the while loop... When the Z-Uno get to this part

Code: Select all

while(Serial1.available()<= 0);
it hangs (the LED stop blinking). Can i implement it in any other way?

Re: while(Serial.available()<=0);

Posted: 19 Aug 2018 01:52
by PoltoS
Use:

Code: Select all

while(Serial1.available()<= 0) delay(10);

Re: while(Serial.available()<=0);

Posted: 22 Aug 2018 10:30
by MastrUsr
I'm sorry for being so slow :) This worked well and I am now up and running my FPC1020 on the Z-Uno. I'm ironing out some other bugs and will later post my project.. Thanks a lot :)