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

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
MastrUsr
Posts: 15
Joined: 13 Sep 2017 18:54

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

Post 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...
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

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

Post by PoltoS »

Check our example like http://z-uno.z-wave.me/projects/control ... e-network/

You should use
while (Serial1.available()) {
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

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

Post 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
MastrUsr
Posts: 15
Joined: 13 Sep 2017 18:54

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

Post 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?
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

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

Post by PoltoS »

Use:

Code: Select all

while(Serial1.available()<= 0) delay(10);
MastrUsr
Posts: 15
Joined: 13 Sep 2017 18:54

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

Post 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 :)
Post Reply