![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jan_boes
Joined: 04 Feb 2004 Posts: 3
|
receiving and sending multiple characters |
Posted: Fri Feb 13, 2004 6:55 am |
|
|
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] |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: receiving and sending multiple characters |
Posted: Fri Feb 13, 2004 8:18 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|