LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

PlotStripChart() causes stack overflow.

Hi,

I am gathering binary data from an RS232 port at 115,200baud and at 1
character every 125us.

I have a com callback installed to handle the data and a global variable
in which to put it.

The data is written to file and plotted on a strip chart.

After about 5 seconds (around 43,000 bits of data), PlotStripChart()
causes a stack overflow.

The code is below, can anyone see why this is happening? The variable
'count' was added for debugging and is always in the order of 43,000
when the stack overflows and the variable 'read' is always exactly 16.

/* Global. */
char data[40000];

/* Com port configured. */
status = OpenComConfig (port, "", 115200, 0, 8, 1, 32767, -1);

/* Callback installed. */
status = InstallComCallback (port, LW
RS_RECEIVE, 100, 0, comCallback,0);

/* This function is called when there is data in the RS232 input queue
to be fetched. */
void CVICALLBACK comCallback (int COMPort, int eventMask, void
*callbackData)
{
/* Variables. */
int len, read;
static int count = 0;

/* Loop while there is data to be fetched. */
while( 0 < (len = GetInQLen (port)) ){
/* Limit the amount fetched to the size of data[] */
if(40000 < len)
len = 40000;

/* Read the data and note how many bytes where actually
read. */
read = ComRd (port, data, len);


/* Write the data to the file. */
fwrite (data, sizeof(char), len, fp);

/* Display the data. */
SetCtrlVal(panelHandle,PANEL_NUMERICMETER,data[read-1]);
PlotStripChart (panelHandle, PANEL_STRIPCHART, data,
read, 0, 0, VAL_CHAR);

count+= read;


/* Keep the UIR updated. */
ProcessSystemEvents();
};


}

--
Regards,

John Cameron.
Type softly, read gently.
0 Kudos
Message 1 of 3
(3,674 Views)
In message <5AOL$SBArbnBFAhV@ob5.co.uk>, John Cameron
writes
>Hi,
>
>I am gathering binary data from an RS232 port at 115,200baud and at 1
>character every 125us.
>
>I have a com callback installed to handle the data and a global variable
>in which to put it.
>
>The data is written to file and plotted on a strip chart.
>
>After about 5 seconds (around 43,000 bits of data), PlotStripChart()
>causes a stack overflow.
Sorry, that should be bytes of data.
>
>The code is below, can anyone see why this is happening? The variable
>'count' was added for debugging and is always in the order of 43,000
>when the stack overflows and the variable 'read' is always exactly 16.
>
>/* Global. */
>char data[40000];
>
>/* Com port configured. */
>status = OpenComConfig (port, "", 115200, 0, 8, 1, 32767, -1);
>
>/* Callback installed. */
>status = InstallComCallback (port, LWRS_RECEIVE, 100, 0, comCallback,0);
>
>/* This function is called when there is data in the RS232 input queue
>to be fetched. */
>void CVICALLBACK comCallback (int COMPort, int eventMask, void
>*callbackData)
>{
> /* Variables. */
> int len, read;
> static int count = 0;
>
> /* Loop while there is data to be fetched. */
> while( 0 < (len = GetInQLen (port)) ){
> /* Limit the amount fetched to the size of data[] */
> if(40000 < len)
> len = 40000;
>
> /* Read the data and note how many bytes where actually
>read. */
> read = ComRd (port, data, len);
>
>
> /* Write the data to the file. */
> fwrite (data, sizeof(char), len, fp);
>
> /* Display the data. */
> SetCtrlVal(panelHandle,PANEL_NUMERICMETER,data[read-1]);
> PlotStripChart (panelHandle, PANEL_STRIPCHART, data,
>read, 0, 0, VAL_CHAR);
>
> count+= read;
>
> /* Keep the UIR updated. */
> ProcessSystemEvents();
> };
>
>
>}
>

--
Regards,

John Cameron.
Type softly, read gently.
0 Kudos
Message 2 of 3
(3,674 Views)
John,

Try changing ProcessSystemEvents() to ProcessDrawEvents().

Updating numerics and plotting points on graphs is a relatively slow process. If you have called RunUserInterface() in main() and you are still having to call ProcessSystemEvents() then your callback is not returning or is being called repeatedly.

You should not have to call ProcessSystemEvents() or ProcessDrawEvents() at all.

Jamie
0 Kudos
Message 3 of 3
(3,669 Views)