CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Stream Selection

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
s.jaglowski



Joined: 14 Nov 2005
Posts: 14

View user's profile Send private message

Stream Selection
PostPosted: Thu Sep 14, 2006 2:40 pm     Reply with quote

Hello.

I'm running a programme on an 18F8720. The programme receives input from a port - it doesn't care which as they will be mutually exclusive, but needs to output to the port it received the input from.

I know I can use fprintf(stream,.....); etc. But this means duplicating the fprintf for each response. i.e.
if(commsA)
fprintf(streamA, "output answer");
else
fprintf(streamB, "output answer");

I believe it may be possible to have code which selects the stream thus

if(commsA&&!commsB)
#use rs232(xmit=PIN_C6, rcv=PIN_C7)
;
if(commsB&&!commsA)
#use rs232(xmit=PIN_G1, rcv=PIN_G2,)
;
.
.
.
.
printf("output answer to correct stream");

Assuming it can be done, does anyone know of any problems that might follow from this approach?
Has anyone successfully used this approach or something similar?

Regards,

Steve
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Sep 14, 2006 3:22 pm     Reply with quote

Those are hardware USARTS. I would use streams.
Your second idea looks like your redefining the #use rs232.
But why risk losing data while switching?

I would use the first idea.
Set them once and use IRQ's and 2 sets of buffers.
TX1,RX1,TX2,RX2 buffers.
and have the duplicate printf. But your just moving data to the tx
buffers, so its more like a memcpy.(or like LCD_putc)
I don't think it will be as bad as you think.
s.jaglowski



Joined: 14 Nov 2005
Posts: 14

View user's profile Send private message

PostPosted: Mon Sep 18, 2006 8:44 am     Reply with quote

I have tried my proposed approach and it seems to function well enough.

However, I think your caution is probably wise. If I can simplify the streamed approach (using a little more string pointer passing) and do it using streams I will.

Regards,

Steve Jaglowski
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Sep 18, 2006 9:04 am     Reply with quote

treitmey probably has it right.
1) Use a printf(myfunction,"...");
2) In myfunction ( myfunction is called for each char in the formatted output printf produces so direct the passed chars to the output buffer desired.
Let the Tx interrupt isr transmit the char. Or just select the stream and
write the char out with printf(STREAM,"%c",c) fputc(c,STREAM) etc.
Ttelmah
Guest







PostPosted: Mon Sep 18, 2006 10:17 am     Reply with quote

I'd go slightly further.
'Encapsulate' the putc function, and have a global 'stream' selector.
So:
Code:

my_putc(char c) {
   if (COMMSA) fputc(c,STREAMA);
   else fputc(c,STREAMB);
}

//Then to send data to a selected stream, just use:
   printf(my_putc,"Sending data to currently selected stream/n/r");

The only duplication, is one fputc call, and at any point, for 'putc', just use 'my_putc', and for printf, use it as shown with the output routine.
Personally I would use serial buffers for both input and output as well.

Best Wishes
s.jaglowski



Joined: 14 Nov 2005
Posts: 14

View user's profile Send private message

PostPosted: Mon Sep 18, 2006 12:51 pm     Reply with quote

Excellent proposals.

Thanks.

Regards,

Steve Jag
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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