I wonder if anyone could tell me how I can send a text to the serial port.
I’m writing a C program for a sensor that periodically takes reading and
would like to output the readings on the serial port. I was thinking of
initialising the port with system(“stty baud=115200 </dev/ser2”); etc and
then outputting a formatted datastring using a fprintf command.
Initialisation is ok but I can’t manage to get the fprintf to work! I can
output a file to the serial port like system(“cp testfile.txt /dev/ser2”);
however this is not really what I want as the readings I want to output
constantly changes.
Thanks a lot for any help
Regards
Lars
Lars Skade wrote:
I wonder if anyone could tell me how I can send a text to the serial port.
I’m writing a C program for a sensor that periodically takes reading and
would like to output the readings on the serial port. I was thinking of
initialising the port with system(“stty baud=115200 </dev/ser2”); etc and
then outputting a formatted datastring using a fprintf command.
Initialisation is ok but I can’t manage to get the fprintf to work! I can
output a file to the serial port like system(“cp testfile.txt /dev/ser2”);
however this is not really what I want as the readings I want to output
constantly changes.
Thanks a lot for any help
Regards
Lars
Lars,
I have an application that writes ascii characters to a stepper motor
controller. I start by opening the serial port
port = open("/dev/ser1", O_RDWR);
then using write to output text
write(port, str, strlen(str);
I test by connecting a VT100 terminal to the serial port to look at the
output.
John McClurkin <jwm@lsr.nei.nih.gov> wrote:
JM > Lars Skade wrote:
I wonder if anyone could tell me how I can send a text to the serial port.
I’m writing a C program for a sensor that periodically takes reading and
would like to output the readings on the serial port. I was thinking of
initialising the port with system(“stty baud=115200 </dev/ser2”); etc and
then outputting a formatted datastring using a fprintf command.
Initialisation is ok but I can’t manage to get the fprintf to work! I can
output a file to the serial port like system(“cp testfile.txt /dev/ser2”);
however this is not really what I want as the readings I want to output
constantly changes.
Thanks a lot for any help
Regards
Lars
JM > Lars,
JM > I have an application that writes ascii characters to a stepper motor
JM > controller. I start by opening the serial port
JM > port = open("/dev/ser1", O_RDWR);
JM > then using write to output text
JM > write(port, str, strlen(str);
JM > I test by connecting a VT100 terminal to the serial port to look at the
JM > output.
I think the issue your up against is that fprintf() can buffer it’s output.
Use write() instead.
Or, you can call fflush() after fprintf() on the file pointer to flush the
data from the local buffer.
“Bill Caroselli” <qtps@earthlink.net> wrote in message
news:cpmqqk$a5f$2@inn.qnx.com…
John McClurkin <> jwm@lsr.nei.nih.gov> > wrote:
JM > Lars Skade wrote:
I wonder if anyone could tell me how I can send a text to the serial
port.
I’m writing a C program for a sensor that periodically takes reading and
would like to output the readings on the serial port. I was thinking of
initialising the port with system(“stty baud=115200 </dev/ser2”); etc
and
then outputting a formatted datastring using a fprintf command.
Initialisation is ok but I can’t manage to get the fprintf to work! I
can
output a file to the serial port like system(“cp testfile.txt
/dev/ser2”);
however this is not really what I want as the readings I want to output
constantly changes.
Thanks a lot for any help
Regards
Lars
JM > Lars,
JM > I have an application that writes ascii characters to a stepper motor
JM > controller. I start by opening the serial port
JM > port = open("/dev/ser1", O_RDWR);
JM > then using write to output text
JM > write(port, str, strlen(str);
JM > I test by connecting a VT100 terminal to the serial port to look at
the
JM > output.
I think the issue your up against is that fprintf() can buffer it’s
output.
Use write() instead.
thanks a lot everybody
problem sorted
Lars
“Kevin Miller” <kevin.miller@transcore.com> escribió en el mensaje
news:cpn0ce$ekj$1@inn.qnx.com…
Or, you can call fflush() after fprintf() on the file pointer to flush the
data from the local buffer.
“Bill Caroselli” <> qtps@earthlink.net> > wrote in message
news:cpmqqk$a5f$> 2@inn.qnx.com> …
John McClurkin <> jwm@lsr.nei.nih.gov> > wrote:
JM > Lars Skade wrote:
I wonder if anyone could tell me how I can send a text to the serial
port.
I’m writing a C program for a sensor that periodically takes reading
and
would like to output the readings on the serial port. I was thinking of
initialising the port with system(“stty baud=115200 </dev/ser2”); etc
and
then outputting a formatted datastring using a fprintf command.
Initialisation is ok but I can’t manage to get the fprintf to work! I
can
output a file to the serial port like system(“cp testfile.txt
/dev/ser2”);
however this is not really what I want as the readings I want to output
constantly changes.
Thanks a lot for any help
Regards
Lars
JM > Lars,
JM > I have an application that writes ascii characters to a stepper
motor
JM > controller. I start by opening the serial port
JM > port = open("/dev/ser1", O_RDWR);
JM > then using write to output text
JM > write(port, str, strlen(str);
JM > I test by connecting a VT100 terminal to the serial port to look at
the
JM > output.
I think the issue your up against is that fprintf() can buffer it’s
output.
Use write() instead.