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

receiving and sending multiple characters

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



Joined: 04 Feb 2004
Posts: 3

View user's profile Send private message

receiving and sending multiple characters
PostPosted: Fri Feb 13, 2004 6:55 am     Reply with quote

i want to sent multiple characters from a computer through a serial cable(example 111or 123 or a2r).
When i received this i want to put it on LCD and back to the computer.
When i look at the screen [/color]on my computer and LCD a only see the first character that i have send.

i use

fgetc(stream) to receive the signal ,

fputc(stream) to send the signal to the computer and

lcd_putc(x) for the LCD.

x=fgetc(stream).

thanks in advance[color=darkred][/color][color=yellow][/color]
Ttelmah
Guest







Re: receiving and sending multiple characters
PostPosted: Fri Feb 13, 2004 8:18 am     Reply with quote

jan_boes wrote:
i want to sent multiple characters from a computer through a serial cable(example 111or 123 or a2r).
When i received this i want to put it on LCD and back to the computer.
When i look at the screen [/color]on my computer and LCD a only see the first character that i have send.

i use

fgetc(stream) to receive the signal ,

fputc(stream) to send the signal to the computer and

lcd_putc(x) for the LCD.

x=fgetc(stream).

thanks in advance


fgetc, gets one character.
So to deal with multiple characters, you have to loop.
Hence something like:
Code:

while (true) {
   x=fgetc(stream);
   fputc(stream);
   lcd_putc(x);
}

Depending on the actual data involved, and the delays involved, it may be better to consider something like:

Code:

int8 buffer[10];
int8 ctr,x;
while (true) {
   ctr=0;
   while ((x=fgetc(stream))!='\n') {
       buffer[ctr++]=x;
       if (ctr==8) break;
   }
   buffer[ctr+1]='\0';
   fprintf(stream,"%s\n",buffer);
   printf(lcd_putc,"%s\n",buffer);
}

This loops on a 'string' basis, stopping when a line feed is seen, or 9 characters have been received, and then echoing the whole string to the serial and the display.

Best Wishes
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