// code by SASANO Takayoshi, CC BY-SA #include #include #include #include #include #include #include #define BUFSIZE 256 #define CRLF "\x0d\x0a" #if 1 #define X_SIZE 160 #define Y_SIZE 128 #else #define X_SIZE 320 #define Y_SIZE 240 #endif #define DELAY 250000 #define FONTSIZE 32 static void tx_test(int fd, int init, int fontsize, int xsize, int ysize, int line, char *text) { unsigned int i; uint8_t buf[BUFSIZE], str[BUFSIZE]; if (init) { sprintf(buf, "RESET;" CRLF); write(fd, buf, strlen(buf)); usleep(250000); sprintf(buf, "CLR(0);DIR(%d);SBC(0);" CRLF, xsize > ysize); write(fd, buf, strlen(buf)); usleep(250000); } sprintf(buf, "DCV%d(%d,%d,'%s',%d)" CRLF, fontsize, 0, fontsize * line, text, 15); write(fd, buf, strlen(buf)); usleep(DELAY); } static int setup_serial(int fd) { struct termios t; memset(&t, 0, sizeof(t)); cfsetospeed(&t, 115200); cfsetispeed(&t, 115200); t.c_cflag = CREAD | CLOCAL | CS8; t.c_iflag = INPCK; t.c_oflag = 0; t.c_lflag = 0; t.c_cc[VTIME] = 0; t.c_cc[VMIN] = 1; tcflush(fd, TCIFLUSH); if (tcsetattr(fd, TCSANOW, &t) < 0) goto fail; return 0; fail: return -1; } int main(int argc, char *argv[]) { int fd; if (argc < 2) { printf("%s [device]\n", argv[0]); goto fin0; } fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY); if (fd < 0) { printf("device open error\n"); goto fin0; } if (setup_serial(fd) < 0) { printf("serial parameter error\n"); goto fin1; } // ASCII tx_test(fd, 1, FONTSIZE, X_SIZE, Y_SIZE, 0, "ABC"); // Shift-jis, '亜'〜 tx_test(fd, 0, FONTSIZE, X_SIZE, Y_SIZE, 1, "\x88\x9f\x88\xa0\x88\xa1"); // EUC-JP, '亜'〜 tx_test(fd, 0, FONTSIZE, X_SIZE, Y_SIZE, 2, "\xb0\xa1\xb0\xa2\xb0\xa3"); // KS C 5061 (EUC-KR) '伽'〜 tx_test(fd, 0, FONTSIZE, X_SIZE, Y_SIZE, 3, "\xca\xa1\xca\xa2\xca\xa3"); // GB2312 (EUC-CN), '薄'〜 tx_test(fd, 0, FONTSIZE, X_SIZE, Y_SIZE, 4, "\xb1\xa1\xb1\xa2\xb1\xa3"); fin1: close(fd); fin0: return 0; }