LS3_PrintLabel/main.c

57 lines
1.2 KiB
C
Raw Normal View History

2025-07-29 15:08:26 +07:00
#include "./GODEX500/Godex500.h"
2025-08-01 13:18:36 +07:00
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
2025-07-29 15:08:26 +07:00
#define SerialDevice "/dev/ttyUSB0"
2025-08-01 13:18:36 +07:00
static int serial_port = -1;
static void cleanup(int signum)
{
(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);
2025-07-29 15:08:26 +07:00
return 0;
}