Re: Newbie question on C library system() function
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sun, 13 May 2007 12:46:16 -0700
philbo30 <masferfc@xxxxxxxxx> writes:
Newbie question here...
I need to send control data (rewind by 3 lines) to a kiosk printer via
a 115200 tty and then print out information associated with a
transaction. The problem is that my control command is executed via a
bash shell system() call which is apparently much slower than my c
data processing. The end result is a printer trying to back up and
move forward at the same time. Unpretty.
Here' s the code for the system call:
char backup[32]="echo -ne \033K7 > /dev/ttyS0 \n"
int rewindsome(void)
{
system(backup);
system(backup);
system(backup);
return 0;
}
I need to make sure that the function above fully completes before the
rest of my app executes. Ideas?
You're missing a semicolon on the declaration of backup. Please post
actual code; otherwise, we have no way of guessing what other mistakes
you've introduced by re-typing it.
Why do you specify the size of the backup array? Why not just declare
it as
char backup[] = "...";
and let the compiler figure out how big it needs to be?
Printers, ttys, and the "echo" command are all off-topic here. If you
want information about them, you should ask in a system-specific
newsgroup, probably comp.unix.programmer or one of the Linux groups.
<OFFTOPIC>
You don't need the trailing space and newline in the argument to
system(). On some systems you might, but not on the one you appear to
be using.
</OFFTOPIC>
However, I don't think you *need* to use system() at all. Let's
assume that the echo command writes some specified output to some
specified location, and that "/dev/ttyS0" is the name of the output
file. (I happen to know that that's the case for your system, but the
C standard is silent on that question.) Why not just open the file
"/dev/ttyS0" using fopen(), and write data to it directly? You can
use the fflush() function to ensure (more or less) that the data is
actually sent.
That's likely to be faster than what you're doing, but it may or may
not not fix your problem. Is the data being sent to the printer out
of order, or is the problem in the way the printer is processing it?
After sending a command to the printer, do you need to pause before
sending another command? We can't answer those questions here (we
can't really even tell you how to pause), but that should let you make
a bit more progress.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- Newbie question on C library system() function
- From: philbo30
- Newbie question on C library system() function
- Prev by Date: Re: Pointer arithmetics in 2D arrays
- Next by Date: Re: unions as function args
- Previous by thread: Re: Newbie question on C library system() function
- Index(es):
Relevant Pages
|