Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5340

TCP Callback on Newline Character

$
0
0

I have a TCP connection to a device that sends its short message (< 100 characters) in chunks.  Unfortunately these chunks seem to be random.  I am having some difficulty tokenizing the data and getting it into five floats.  Is there any way I can make this TCP callback fire only when a newline character is received, or a better method of putting the message together?  I'm going to be dealing with much larger TCP messages for other devices, so it will be good to get this issue resolved on a small scale problem.

 

For whatever reason, my logic is allowing incomplete messages to be tokenized.  The message leads with BARO and ends with \r\n.

 

                    receiveBuf[dataSize] = '\0';
                    if (strstr(receiveBuf,"\n") == NULL)
                        strcpy(Vaisala.Message, receiveBuf);
                    else
                    {
                        if ((strlen(Vaisala.Message) + strlen(receiveBuf) < 100) || (strstr(receiveBuf,"BARO") == NULL))
                        {
                            strcat(Vaisala.Message, receiveBuf);
                            Vaisala.Message[strlen(Vaisala.Message) - 2] = '\0';
                            token = strtok(Vaisala.Message, "\t");
                            token = strtok(NULL, "\t");                              
                            Vaisala.Barometric = atof(token);
                            token = strtok(NULL, "\t");  
                            token = strtok(NULL, "\t");                              
                            Vaisala.DryBulb = atof(token);
                            token = strtok(NULL, "\t");  
                            token = strtok(NULL, "\t");                              
                            Vaisala.WetBulb = atof(token);
                            token = strtok(NULL, "\t");  
                            token = strtok(NULL, "\t");                              
                            Vaisala.Dewpoint = atof(token);
                            token = strtok(NULL, "\t");  
                            token = strtok(NULL, "\t");                              
                            Vaisala.RH = atof(token);
                        }
                        else
                            memset(Vaisala.Message, '\0', 100);


Viewing all articles
Browse latest Browse all 5340

Trending Articles