I have an external device that I send a command via the uart and need to capture its response. I initially used hyperterminal to communicate with the device and view the response.
Now I need to do this with a PIC18F452. Here is a segment of the code that does not capture the response.
char response[100];
int i;
// send my command and wait on the response with the following code:
Could someone explain what is wrong with this code or if there is a better way to accomplish the task of capturing a long response of characters.
Thank you,
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Mon Dec 10, 2007 5:16 pm
There are several things wrong with it.
One major problem is that your array is only 100 bytes, but then
your loops expect the array to be 200 or 256 bytes long. That's
not going to work. If you write past the end of your array, you
will destroy the contents of other variables that are allocated in
those memory locations.
I suggest that you use the get_string() function to get the input.
It allows you to set the maximum number of characters that
you are willing to accept. This means you prevent your code
from writing past the end of your input array. The get_string()
function is in the Input.c file, which is in this directory:
Quote:
c:\Program Files\picc\Drivers\Input.c
Guest
Posted: Tue Dec 11, 2007 2:49 pm
Thank you for the feedback. I will look at input.c.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum