 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Apr 01, 2010 9:50 am |
|
|
The reason it works in your first example is because you are accessing the data 1 char at a time. You don't care where it is stored you just read it in the same order you wrote it.
But memcpy and strcpy require the data to be contiguous as I said in my last post. It is working, it is just copying the data in a different order than what you wrote it. |
|
 |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Apr 01, 2010 9:54 am |
|
|
| MikeW wrote: | @Ttelmah,
your response seems to go back to the array[bufferno][parse count] definition,
which was my original way, but i was told to change it to
array[parse count][bufferno]
either way, your reply doesnt seem to answer my last post, that the array ends up with 31 00 32 00 33 00 34 00 35 if i do it the "correct way".
Mike |
this was in your first bit of code
| Code: |
for (i=0;i<RS232_Buffer_length;i++)
{
RS232_receive_buffer[i]=RS232_receive_string[i][Buffer_No];
}
|
this shows you doing it the wrong way array[parse count][bufferno] which is what we told you was wrong.
Now you are saying that is how you were doing it to start with ? |
|
 |
MikeW
Joined: 15 Sep 2003 Posts: 185 Location: Warrington UK
|
|
Posted: Thu Apr 01, 2010 10:29 am |
|
|
@Wayne,Ttelmah,
As I said all along, I was dazed and confused.
I have now sorted it, and it works fine.
I thank you both for you help, I feel a bit stupid, but thats life !!
Here is the working code, with the bufferno as the first subscript.
Also, Waynes comment earlier was correct, to perform the memcpy did require the & before the array name.
I wanted to use memcpy so that the resultant series of characters could be examined in the debugger easily, and thus easier to understand, and pluck characters out for crunching.
Mike
Below is working code (I hope)
| Code: |
#define RS232_Buffer_length 50
CHAR RS232_receive_string[2][RS232_Buffer_length];
int1 Command_received_flag=false;
int1 Command_Processed_flag=false;
int8 RS232_receive_string_buffer_no=0;
#define LF 0x0A // LF is ignored
#define CR 0x0D // Carriage return
#define End_Of_Message_Character CR // CR ends the string
#int_rda
void serial_isr()
{
static int8 buffer_count=0;
int8 received_char;
received_char=fgetc(Serial_Port_PIC);
if (Command_Processed_flag==TRUE)
{
buffer_count=0;
Command_received_flag=FALSE;
Command_Processed_flag=FALSE;
}
if (received_char==End_Of_Message_Character) // currently defined as CR
{
Command_received_flag=TRUE;
received_char=0x00; // tell printf its the end of the string
RS232_receive_string_buffer_no++;
RS232_receive_string_buffer_no&=0x01; // only allow 0 or 1
}
if (received_char==LF)
{
RETURN; // ignore linefeeds
}
RS232_receive_string[RS232_receive_string_buffer_no][buffer_count++]=received_char;
if(buffer_count >=RS232_Buffer_length) buffer_count=0; // Buffer full !!
} // end of function
------------------
in the main code is
void Process_RS232_Command ()
{
char RS232_receive_buffer[RS232_Buffer_length];
int8 Buffer_No;
if (Command_received_flag==FALSE) return; // nothing to do
Buffer_No=((~RS232_receive_string_buffer_no) & 0x01);
memcpy(RS232_receive_buffer, &RS232_receive_string[Buffer_No][0], RS232_Buffer_length);
Buzzer_Beep();
GLCD_gotoXY(5,5);
printf(GLCD_print," ");
GLCD_gotoXY(5,5);
printf(GLCD_print,RS232_receive_buffer);
Action_Command_From_PC(RS232_receive_buffer); // go do it
Command_received_flag=FALSE;
Command_Processed_flag=TRUE;
} // end of function
|
|
|
 |
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|