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

How to check if RS232 Stream is defined

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



Joined: 15 Dec 2009
Posts: 3

View user's profile Send private message

How to check if RS232 Stream is defined
PostPosted: Thu Mar 25, 2010 1:52 pm     Reply with quote

Hey there,

This is possible:

Code:

#define FOO 1
#ifdef FOO
//Code
#endif


I'm trying to do the something similar with rs232 streams. Ideally:
Code:

#use rs232(... STREAM=COM_A)
#use rs232(... STREAM=COM_B)

//Code

#ifdef COM_A
#ifdef COM_B

// Code that only compiles when two streams are defined

#endif
#endif


#ifdef obviously doesn't work in this case. Is there something similar I could do? It would be especially helpful if users of my lib wouldn't have to change their application code, so I'd like to not have to require them to #define other variables if they are using two streams, but I guess I could last resort.

Thanks as always for the help, and I apologize if this solution was posted elsewhere. I did a quick search and came up empty.

Chris
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 25, 2010 10:15 pm     Reply with quote

Quote:

#ifdef obviously doesn't work in this case. Is there something similar I could do?

The #if defined() syntax works with vs. 4.105. It can detect if a stream
is defined or not. Use it instead of #ifdef. Example:
Code:

#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=COM_A)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B2, ERRORS, stream=COM_B)

//======================================
void main()
{
int8 c;

#if defined(COM_A)
c = 0x55;
#else
c = 0xAA;
#endif

while(1);
}
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