08-14-2006 01:12 PM
08-14-2006 04:11 PM - edited 08-14-2006 04:11 PM
The ComRd() statement looks ok to me.
In your OpenComConfig() set the last two values to 512. They are the buffer queue sizes and the values you are using are probably not being accepted. Most likely the OS will bump them up that high anyway.
You probably want to move the OpenComConfig() statement outside of the callback. This way you will not need to open the com port for each execution of the callback. Also I do not see where you are closing the com port, so if the callback executes more than once you are going to have a problem.
After the call to ComRd() check that n =100 before calling PlotY() or change the number of points in the call to PlotY to be "n", this will avoid trying to print data that is not in the buffer.
Since you open the com port and then read it right away, there is a good chance that no data is present in the input queue. You really need the port to have been open for a while before trying to read the data. You can set a timeout period for ComRd() calls, but calling ComRd() with long timeouts can cause your program to act like it is hung while it is waiting for ComRd() to return.
You might want to check the return code for OpenComConfig() to make sure there are no problems there, should be zero if no error occured.
Message Edited by mvr on 08-14-2006 04:12 PM
08-14-2006 04:14 PM
08-14-2006 04:33 PM
08-15-2006 08:13 AM
08-15-2006 08:34 AM
Hallo mvr
Thank you I will post here as the micro is a 8 bit controller and high - low byte order,
I am working on this only in the evenings as I try to learn C and labwindows as a part time study to improve myself.
I removed the unnecessary definition (int Buf) from the code however the error remains telling me that it is a out of bounce pointer before array as shown in the first post,
If you close the com port after the reads do you have to configure it again before the ComRd() is used again.
I appreciate the help very much Thank you very much.
Peter
Switzerland
08-15-2006 09:13 AM
If you close the com port, you have to open it again before using it. You do not have to us OpenComConfig(), you can use OpenCom() but there really is not benefit to doing it that way.
If you are doing a lot of serial I/O leave the port open. You can open and close the port as part of your main() routine. If you only use it once in a while, it is not an issue to open and close it from inside the callback function.
I don't think the problem you are having is in the section of code you posted. It runs fine for me. You can try posting a stripped down version of your program that has the same issue. You might also want to turn up the debugging level in CVI, for this go to Options==>Build Options and make sure everything in the Compiler Warnings and Errors section is checked. Also under Debugging Options set the Debugging Level to Extended. This may help track down the problem.
08-15-2006 09:20 AM
The problem is being caused by the declaration of buf[100] being inside the switch() statement. Move it to the top of the function definition and all will be well.
JR
08-15-2006 09:23 AM
08-15-2006 09:29 AM
I see JR found it. I type so slow. Anyway nice job.
This fragment works
int CVICALLBACK RunCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
{
int n = 0;
char buf[100];
OpenComConfig (1, "COM1", 9600, 0, 8, 1, 512, 512); // Open and configure comport
n =ComRd (1, buf, 100);
PlotY (panel, MAIN_GRAPH, buf, 100, VAL_CHAR, VAL_THIN_LINE,
VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
CloseCom(1);
}
break;
case EVENT_RIGHT_CLICK:
break;
}
return 0;
}
Declaring variables within the local scope of braces {} is something that came from C++. CVI does support some of these things, and declaring variables like this can be pretty useful. The problems with the switch statement is kind of ambiguous, not really sure what the rule would be there, but it is easy to fix.
Good Luck