while true
parent
cc7b8e863e
commit
9d60e6c285
59
main.c
59
main.c
|
@ -1,10 +1,57 @@
|
||||||
#include "./GODEX500/Godex500.h"
|
#include "./GODEX500/Godex500.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define SerialDevice "/dev/ttyUSB0"
|
#define SerialDevice "/dev/ttyUSB0"
|
||||||
int main() {
|
|
||||||
const char* id = "2E000504";
|
static int serial_port = -1;
|
||||||
const char* model = "LS3";
|
|
||||||
int serial_port = GODEX500_setup_serial(SerialDevice);
|
static void cleanup(int signum)
|
||||||
GODEX500_print_label(serial_port, id, model);
|
{
|
||||||
close(serial_port);
|
(void)signum;
|
||||||
|
if (serial_port >= 0)
|
||||||
|
close(serial_port);
|
||||||
|
write(STDOUT_FILENO, "\nПорт закрыт. \n", 23);
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void install_handler(int signo)
|
||||||
|
{
|
||||||
|
struct sigaction sa = {
|
||||||
|
.sa_handler = cleanup,
|
||||||
|
.sa_flags = SA_RESTART
|
||||||
|
};
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sigaction(signo, &sa, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
install_handler(SIGINT);
|
||||||
|
install_handler(SIGTERM);
|
||||||
|
install_handler(SIGHUP);
|
||||||
|
install_handler(SIGQUIT);
|
||||||
|
|
||||||
|
const char *model = "LS3";
|
||||||
|
char id[256];
|
||||||
|
|
||||||
|
serial_port = GODEX500_setup_serial(SerialDevice);
|
||||||
|
if (serial_port < 0) {
|
||||||
|
perror("serial");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("Введите ID (Ctrl+D, Ctrl+C или kill для выхода):");
|
||||||
|
while (fgets(id, sizeof id, stdin)) {
|
||||||
|
id[strcspn(id, "\n")] = '\0';
|
||||||
|
if (*id == '\0') continue;
|
||||||
|
GODEX500_print_label(serial_port, id, model);
|
||||||
|
printf("Печать %s завершена\n", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue