View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
How to pass stream name of RS232 to a function? |
Posted: Wed Apr 03, 2013 11:29 am |
|
|
Hi! I want to use 2 RS232 USART modules. So I set stream name for each one, but I don`t know how to pass the stream name to function, so I could use a single function for data transfer?
What is the datatype of stream? It`s not string!
I want to do this
Code: |
void RS232Transmition(stream StreamName)
{
if(kbhit(StreamName))
{
incomeData=getc(StreamName);
}
}
|
Thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 03, 2013 12:53 pm |
|
|
Short answer: You can't pass a CCS "stream" identifier as a parameter.
You will have to use "if" statements and check a variable that you
define to hold the desired stream. Then, based on the value of that
variable, your "if" statement will call the desired fputc or fprintf
statement, etc., and use the desired stream. |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Apr 04, 2013 1:43 am |
|
|
PCM programmer wrote: | Short answer: You can't pass a CCS "stream" identifier as a parameter. |
Reason: because getc() and similar IO functions are dealt with at compile time not runtime, so the parameters must be known - fully resolved - at compile time. Therefore you can't pass a variable to them at runtime.
RF Developer |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu Apr 04, 2013 7:20 am |
|
|
and of course 'behind' this is the core difference between writing code on the PIC, and something like a PC. On the latter you have hundreds of KB of 'OS' already loaded to do all these jobs. So simply changing which routine in the OS is called is simple. On the former, there is nothing outside your code, so the compiler has to generate the code to access a port when asked. Due to the lack of space, no more than is needed is loaded.....
Best Wishes |
|
|
|