Re: Newbie question on C library system() function



In article <1179083185.637754.170360@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
philbo30 <masferfc@xxxxxxxxx> wrote:
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 probably don't need the \n in there.

You could do the same thing in C by using

#include <stdio.h>
int rewindsome(void) {
FILE *printer = fopen("/dev/ttyS0","a");
if (!printer) {
perror("Problem opening the printer");
return 1;
}
fprintf( printer, "\033K7\033K7\033K7" );
fclose( printer );
return 0;
}

However, this -probably- won't solve the problem. In my experience, your
problem likely is not with system() being slow, but rather with the
printer being slow and with there being no way to check with the
printer to see whether it completed a command yet. You are sending
the characters to the printer, but the characters are getting buffered
in the printer memory and executed in the printer's own sweet time.

Lacking a way to check completion, the best you would be able to do
would be to wait for a period of time, hoping the command completes
(which would depend on what else the printer is doing); unfortunately,
there is no way in standard C to wait for a given amount of time.
Most operating systems provide ways outside of C to wait gracefully;
chances are that your operating system supports a sleep() function
for example.
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
.



Relevant Pages

  • Re: Need Help With Script
    ... The moment this line of the script executes, ... When you execute the command ... with debug gave the expected result of three ASCII characters followed by ...
    (microsoft.public.windows.server.general)
  • Re: Using os.system() and string concatenation
    ... > I think take those lists and provide them to an os.systemcall. ... > This executes without any errors, but doesn't execute the command ... > supply it to os.systemit executes just fine. ... a shell command out of data from files, ...
    (comp.lang.python)
  • Re: Fat32 format: a DFsee question
    ... Since it was never adopted by other operating systems it is not ... >>> volume or partition,' the program hangs with the use F10 to return to ... >>> the menus from the command line. ...
    (comp.os.os2.setup.misc)
  • Re: RH 9.0 log in question: seems a bit long
    ... No lag after I enter my password. ... in my username. ... When I type in command, it executes right away. ...
    (RedHat)
  • Re: Unable to filter records using a command button
    ... continuous view form which is not a subform on another form? ... > I created a command button on the form that executes a macro. ...
    (microsoft.public.access.forms)