Re: Newbie question on C library system() function



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"
.



Relevant Pages

  • Re: Number of pause seconds is out of range
    ... I have a little command file that is invoked from all our ... > with the 'pause' command expires. ... STREAM a job that does nothing but wait thirty seconds ...
    (comp.sys.hp.mpe)
  • Re: [opensuse] Native printing via SSH
    ... Because they are a kernel driver for the very tty your terminal is using, it's possible for the driver to do a little magic and provide virtual printer device files. ... It appears to be possible to tell dosemu to run a command to print. ...
    (SuSE)
  • Re: XP Cmd. Statement help please
    ... PAUSE suspends processing of a batch program and displays the message ... If PAUSE is the last line, the command window stays open until you press any ... stay open when you run the batch file at startup. ... Note: The:: is the same as rem. ...
    (microsoft.public.windowsxp.general)
  • Re: Pausing/Waiting in C
    ... of "events" to be popped off, separated by a command to pause reading off ... only clock() is part of the ANSI Standard. ... If you're trying to implement a delay and all you have available ...
    (comp.lang.c)
  • Re: Pausing/Waiting in C
    ... of "events" to be popped off, separated by a command to pause reading off ... features, it has at least two major drawbacks: it measures CPU time, ... most operating systems will provide a good way to do this. ...
    (comp.lang.c)