|
|
View previous topic :: View next topic |
Author |
Message |
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
passing variables in kbhit |
Posted: Tue Dec 16, 2014 9:14 am |
|
|
Hello Board
1. is it possible to pass variables in kbhit instead of stream
2. here is the brief code - correct me plz
Code: |
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, STREAM=sp0, FORCE_SW)
#use rs232(baud=9600, rcv=PIN_D0, STREAM=sp1, FORCE_SW)
#use rs232(baud=9600, rcv=PIN_D1, STREAM=sp2, FORCE_SW)
#use rs232(baud=9600, rcv=PIN_D2, STREAM=sp3, FORCE_SW)
#use rs232(baud=9600, rcv=PIN_D3, STREAM=sp4, FORCE_SW)
|
serial ports forced SW
Code: |
#DEFINE SIZE_COMMAND 5 // Sets the Max command Length including '\0'
#DEFINE TOTAL_STRINGS 5 // Total number of Searchable strings
const char serial_val[TOTAL_STRINGS][SIZE_COMMAND]={
"sp0\0",
"sp1\0",
"sp2\0",
"sp3\0",
"sp4\0",
};
|
above is the variable that im going to use for passing to kbhit
Code: | extract_serial_data(0); |
above is the function im using for calling serial port "0" -> sp0
Code: | extract_serial_data(int val){
fprintf(sp0,"%s\r\n",serial_val[val]);
if(kbhit(serial_val[val])){
|
fprintf works well it shows the good string as "sp0"
but im getting this error while executing this command -> Stream must be a constant in the valid range ::
im using compiler version - 4.078 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Tue Dec 16, 2014 9:45 am |
|
|
The key is the 'constant'. No you can't use a variable. The stream name is a pre-processor directive that tells the command to generate the code for the selected stream.
If you want to have a universal function, you would have to write your own wrapper function 'my_kbhit' for example, which takes a value for the stream (a define, or an enum), and then uses a switch.. case, to select each of the possible streams. This way all five sets of code will be generated in the function, and you just select between them. It is the fact that the stream name specifies the code to be generated, which prevents a variable being used. If a variable was allowed, every serial function would have to contain the code for every stream.... |
|
|
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
Thanks for the reply |
Posted: Tue Dec 16, 2014 10:55 am |
|
|
thanks for your reply and suggestion.. i split my code then.... |
|
|
|
|
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
|