Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Embedded C
Dear All,
 
I need to forward messages from Serial Port C to Serial Port B and vice versa, whenever port C/D receives any message. I should implement the mulitasking approach to achieve this.
 
Initially, I tried a very simple code to run, forward a msg from C to B, but unluckily the code doesn't proceed exectution after wfd cof_serXread function. Meaning, the function is never done reading.
 
Does my problem makes sense? I hope its clear enough.
Your Help Is Highly Appreciated.
 
void main(){
int n;
static const char msgData[]= {"Hiiii am in serial c"};
 
brdInit();
serCopen(115200);
serBopen(115200);
loopinit();
 
while (1) {
loophead();
costate {
//it stops here and goes back to the while cont. 
wfd n = cof_serCread(msgData, strlen(msgData), 20);
wfd cof_serBwrite(msgData, n);
}
}
 
serCclose();
serBclose();
 
}
Posted 4-Oct-10 22:52pm
shhtk199
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think strlen(msgData) may be running over because msgData has no null
Change to
static const char msgData[]= {"Hiiii am in serial c\0"};
 
also i'm not sure what cof_serCread does with msgData but would have thought it stored data in it, but it can't because this is a const array
 
you may need something like
char msgRead[21];
// it might be a good idea to set the buffer to nulls first
memset(msgRead, 0, sizeof(msgRead));
cof_serCread(msgRead, sizeof(msgRead), 20)
 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thank you for your reply, i tried your suggestion but still it gives me the same problem i faced earlier.
 
Anyways, I removed all the cofunctions because i would like to get a better understanding of sending and recieving msgs to ports.
 
However, I still have a problem! I created a buffer that i store in it my msgData and pass it to port C then B. I get an empty buffer in port B which am sure that i dont pass an empty array.
 
Am new to embedded systems development, and your help is highly appreciated.
 
Please, do have look to the code.
 
while (1)
{
loophead();
costate
{
memcpy(buffer, msgData, msgData(string2));
serCputs(buffer);
memset(buffer, 0x00, sizeof(buffer));
 
// n is 0 when i run the code
n = serBread(buffer, sizeof(buffer),20);
serBputs(buffer);
printf("%s", buffer);
 
}
}
  Permalink  
Comments
ARopo at 7-Oct-10 11:33am
   
Have you got ports C and B connected together then. Are they connected correctly? Do the port settings match?
Perhaps your serBread returns 0 because there is nothing to read.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 275
1 OriginalGriff 230
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 6 Oct 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100