Click here to Skip to main content
13,044,766 members (44,692 online)
Rate this:
Please Sign up or sign in to vote.
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"};
while (1) {
costate {
//it stops here and goes back to the while cont. 
wfd n = cof_serCread(msgData, strlen(msgData), 20);
wfd cof_serBwrite(msgData, n);
Posted 4-Oct-10 21:52pm
Rate this: bad
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)
Rate this: bad
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)
memcpy(buffer, msgData, msgData(string2));
memset(buffer, 0x00, sizeof(buffer));
// n is 0 when i run the code
n = serBread(buffer, sizeof(buffer),20);
printf("%s", buffer);
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 6 Oct 2010
Copyright © CodeProject, 1999-2017
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