#include "../Inc/Godex500.h" int GODEX500_setup_serial(const char* device) { int serial_port = open(device, O_RDWR); if (serial_port < 0) { perror("Ошибка открытия последовательного порта"); return -1; } struct termios tty; memset(&tty, 0, sizeof tty); if (tcgetattr(serial_port, &tty) != 0) { perror("Ошибка получения атрибутов TTY"); close(serial_port); return -1; } cfsetospeed(&tty, B9600); cfsetispeed(&tty, B9600); tty.c_cflag &= ~PARENB; tty.c_cflag &= ~CSTOPB; tty.c_cflag &= ~CSIZE; tty.c_cflag |= CS8; tty.c_cflag |= CREAD | CLOCAL; if (tcsetattr(serial_port, TCSANOW, &tty) != 0) { perror("Ошибка установки атрибутов TTY"); close(serial_port); return -1; } return serial_port; } void GODEX500_send_to_printer(int serial_port, const char* data) { write(serial_port, data, strlen(data)); tcdrain(serial_port); } void GODEX500_print_label(int serial_port, const char* id, const char* model) { char buffer[1024]; char datamatrix_data[200]; snprintf(datamatrix_data, sizeof(datamatrix_data), "%s", id); int datamatrix_length = strlen(datamatrix_data); snprintf(buffer, sizeof(buffer), "^Q10,2\n" "^W25^H14\n" "^P1\n" "^S2\n" "^AT\n" "^C1\n" "^R0\n~Q+0\n" "^O0\n^D0\n^E30\n~R255\n" "^L\n" "Dy2-me-dd\nTh:m:s\n" "AB,5,10,1,1,0,0E,%s\n" "AB,40,45,1,1,0,0E,%s\n" "XRB130,14,4,0,%d\n" "%s\n" "E\n", id, model, datamatrix_length, datamatrix_data); GODEX500_send_to_printer(serial_port, buffer); }