Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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)
 
Share this answer
 
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);

}
}
 
Share this answer
 
Comments
ARopo 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900