03-29-2007 03:59 PM
03-30-2007 07:14 AM
03-30-2007 10:42 AM
03-30-2007 11:16 AM
Thanks for the responses.
Dave, Whenever it has crashed i have checked the t value and it is within range. So I dont think that is the problem.
Mert, Here is how I declare the buffers, I should have included it the first time:
unsigned char t_serial_buffer [50000];
char temp_compare_buffer [100];
AS you can see I am coding scared- I have increased their values in order to avoid the problems i am still having. I dont have to do a malloc or anything for these i dont think right? Your suggestion of only transferring the exact number of bytes that I want, is what i thought i was doing with the temp_compare_buffer. I used to have the code say:
if(t_serial_buffer==query_request[t])
Also i think i was avoiding your other suggestion by doing the ViRead inside of the "if (t_bytes_ready == 48)" statement.
Thanks for the responses.
03-30-2007 01:14 PM
03-30-2007 01:17 PM
Ok, you may have just not shown your exact code block but from what you wrote above you have an issue with strncmp() executing before you have filled the buffer.
if (t_bytes_ready == 48) //(TRUE)
viRead (handle_serial[t], t_serial_buffer, t_bytes_ready, &t_bytes_transferred);
Only the section above is part of the (t_bytes==48) if statement. The rest of this will then execute even if the call to viRead has not happened yet:
temp_compare_buffer[0]=t_serial_buffer[0];//this is a
temp_compare_buffer[1]=t_serial_buffer[1];//workaround
temp_compare_buffer[2]=t_serial_buffer[2];//putting buffer in
temp_compare_buffer[3]=t_serial_buffer[3];//strncmp brings
temp_compare_buffer[4]=t_serial_buffer[4];//gpf faults.
temp_compare_buffer[5]=t_serial_buffer[5];
temp_compare_buffer[6]=t_serial_buffer[6];
temp_compare_buffer[7]=t_serial_buffer[7];
temp_compare_buffer[8]=t_serial_buffer[8];
temp_compare_buffer[9]=0;
//if(temp_compare_buffer==query_request[t])
if (strncmp (temp_compare_buffer, query_request[t], 9)==0)
{//then i do other stuff with the other buffer characters...
When you get to strncmp() you will be executing on an unintialized array which could give you unexpected results.
03-30-2007 01:21 PM
03-30-2007 01:24 PM
03-30-2007 02:42 PM
03-30-2007 03:58 PM
Sorry for being unclear. All of the code is within the { }. Here is a bigger sample of my code:
viGetAttribute (handle_serial[t], VI_ATTR_ASRL_AVAIL_NUM, &t_bytes_ready);
if (t_bytes_ready > 48) {
MessagePopup ("Timer Error Message", "over 50 bytes/Will flush");
viFlush (handle_serial[t], VI_READ_BUF_DISCARD);
}
if (t_bytes_ready == 48) //(TRUE)
{
Assert(t_bytes_ready < 50);
if (t_bytes_ready =! t_bytes_transferred)
MessagePopup("warning message", "ready is not same as transferred");
temp_compare_buffer[0]=t_serial_buffer[0];//this is a
temp_compare_buffer[1]=t_serial_buffer[1];//workaround
temp_compare_buffer[2]=t_serial_buffer[2];//putting buffer in
temp_compare_buffer[3]=t_serial_buffer[3];//strncmp brings
temp_compare_buffer[4]=t_serial_buffer[4];//gpf faults.
temp_compare_buffer[5]=t_serial_buffer[5];
temp_compare_buffer[6]=t_serial_buffer[6];
temp_compare_buffer[7]=t_serial_buffer[7];
temp_compare_buffer[8]=t_serial_buffer[8];
temp_compare_buffer[9]=0;
//if(temp_compare_buffer==query_request[t])
if (strncmp (temp_compare_buffer, query_request[t], 9)==0)
{
//then do stuff with t_serial_buffer bytes 9 through 48..
}//end strncmp
} //end if (t_bytes_ready == 48)