Serial port

B

BartC

I'd been looking for a standalone Windows (7) executable to monitor a serial
port, but thought I'd try the following code, and it worked!

This is not exactly a C problem but perhaps someone might know why fgetc()
mostly returns -1 (EOF), presumably when no character is ready, rather than
wait until one is available (as it might do for f==stdin). As it is, it ties
up the processor, so can't be used seriously.

#include <stdio.h>
#include <stdlib.h>

int main (void) {
FILE* f;
int c;

f=fopen("com3","r");

if (!f) exit(0);

while (1) {
c=fgetc(f);
if (c!=EOF) printf("%c",c);
}
}
 
J

James Kuyper

I'd been looking for a standalone Windows (7) executable to monitor a serial
port, but thought I'd try the following code, and it worked!

This is not exactly a C problem ...
Correct.

... but perhaps someone might know why fgetc()
mostly returns -1 (EOF), presumably when no character is ready, rather than
wait until one is available (as it might do for f==stdin). ...

Almost certainly true - but did you really think you were more likely to
find such a person here, rather than in a forum associated with Windows?
 
K

Kenny McCormack

I'd been looking for a standalone Windows (7) executable to monitor a serial
port, but thought I'd try the following code, and it worked!

A million or so years ago, I used a program called DSZ to do exactly this.
It still works to this day.

I could probably shoot you a binary if you are interested.

--
"They shall be attended by boys graced with eternal youth, who to the
beholder?s eyes will seem like sprinkled pearls. When you gaze upon that
scene, you will behold a kingdom blissful and glorious."

--- Qur'an 76:19 ---
 
L

Les Cargill

BartC said:
I'd been looking for a standalone Windows (7) executable to monitor a
serial
port, but thought I'd try the following code, and it worked!

This is not exactly a C problem but perhaps someone might know why fgetc()
mostly returns -1 (EOF), presumably when no character is ready, rather than
wait until one is available (as it might do for f==stdin). As it is, it
ties
up the processor, so can't be used seriously.

#include <stdio.h>
#include <stdlib.h>

int main (void) {
FILE* f;
int c;

f=fopen("com3","r");

if (!f) exit(0);

while (1) {
c=fgetc(f);
if (c!=EOF) printf("%c",c);
}
}


I use PuTTY for this purpose:

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Working with files 1
Small script to check serial port sucking down system resources. 2
// comments 35
Taking a stab at getline 40
How to remove // comments 100
Help with serial port. 2
Help with Loop 0
Text processing 29

Members online

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,443
Members
47,089
Latest member
Bobby2025b

Latest Threads

Top