📄 testspeed.c
字号:
#include <stdio.h>#include <time.h>#include "posapi.h"#include "api.h"#include "syd520.h"#define FONT_NAME "/usr/bin/asc30.dot"void Test12(void);void Test24(void);int main(){ int nKey; Syd_OpenLCD(); Syd_ClearScreen(); Syd_DisplayLine(1, " 打印速度测试 ", 1, ALIGN_CENTER); while (1) { Syd_ClearWindow(2, 5); Syd_DisplayLine(3, "1. 12点阵测试", 0, ALIGN_CENTER); Syd_DisplayLine(4, "2. 24点阵测试", 0, ALIGN_CENTER);REDO: nKey = Sys_Key_WaitKey(); switch (nKey) { case KEY_1: Test12(); break; case KEY_2: Test24(); break; default: goto REDO; } } return 0;}void Test12(void){ unsigned char strData[50]; time_t tStart, tEnd; FONT_INFO_STRUCT FontInfo; SUN_PRINT_STRUCT PrintStruct; int i, nRet; Syd_ClearWindow(2, 5); Sys_Prn_Gray(2); if (!Syd_CheckPaper()) { Syd_ErrorMessageWait(3, "缺纸!", 0, ALIGN_CENTER); return; } Syd_DisplayLine(3, "正在打印...", 0, ALIGN_CENTER); Syd_OpenPrinter(); nRet = Syd_OpenSunFont(FONT_NAME, &FontInfo); if (nRet < 0) { Syd_ErrorMessageWait(3, "不能打开字库!", 0, ALIGN_CENTER); return; } nRet = Syd_AllocSunPrint(FontInfo.sDotHeight, &PrintStruct); //为字符点阵缓存申请内存 if (nRet < 0) { Syd_ErrorMessageWait(3, "不能分配内存!", 0, ALIGN_CENTER); Syd_CloseSunFont(&FontInfo); return; } tStart = time(NULL); for (i = 1; i <= 100; i++) { sprintf(strData, "PRINT SPEED TEST ##%d", i); Sys_Prn_Pixel_3(strData, 22); } tEnd = time(NULL); Syd_PrinterFeed(10); //motor go 10 steps //由于当前字库仍未烧入所以打印的结果还是请位图方式打印 strcpy(strData, "PRINTED 100 LINES"); //结果以为图方式打印 Sys_Prn_Pixel_3(strData,18); sprintf(strData, "PRINT TIME %ld sec", tEnd - tStart);fprintf(stderr, "PRINT TIME %ld sec", tEnd - tStart); Sys_Prn_Pixel_3(strData,18); sprintf(strData, "SPEED %.1lf line/sec", 100.0/(tEnd - tStart));fprintf(stderr, "SPEED %.1lf line/sec", 100.0/(tEnd - tStart)); Sys_Prn_Pixel_3(strData,22); Syd_PrinterFeed(100); Syd_FreeSunPrint(&PrintStruct); Syd_CloseSunFont(&FontInfo); Syd_ClosePrinter(); }void Test24(void){ unsigned char strData[50]; FONT_INFO_STRUCT FontInfo; SUN_PRINT_STRUCT PrintStruct; int i, nRet; time_t tStart, tEnd; Syd_ClearWindow(2, 5); Sys_Prn_Gray(2); if (!Syd_CheckPaper()) { Syd_ErrorMessageWait(3, "缺纸!", 0, ALIGN_CENTER); return; } nRet = Syd_OpenSunFont(FONT_NAME, &FontInfo); if (nRet < 0) { Syd_ErrorMessageWait(3, "不能打开字库!", 0, ALIGN_CENTER); return; } nRet = Syd_AllocSunPrint(FontInfo.sDotHeight, &PrintStruct); //为字符点阵缓存申请内存 if (nRet < 0) { Syd_ErrorMessageWait(3, "不能分配内存!", 0, ALIGN_CENTER); Syd_CloseSunFont(&FontInfo); return; } Syd_DisplayLine(3, "正在打印...", 0, ALIGN_CENTER); Syd_OpenPrinter(); tStart = time(NULL); for (i = 1; i <= 100; i++) { sprintf(strData, "PRINT SPEED TEST ##%d", i); //将字符串保存在strData中 Sys_Prn_Pixel_3(strData,22); //向430发送打印数据,以字符方式打印 } tEnd = time(NULL); Syd_PrinterFeed(10); strcpy(strData, "PRINTED 100 LINES"); //结果以为图方式打印 Syd_WriteSunPrint(strData, strlen(strData), &PrintStruct, &FontInfo); Syd_SendSunPrintInit(&PrintStruct, 1, 1); sprintf(strData, "PRINT TIME %ld sec", tEnd - tStart);fprintf(stderr, "PRINT TIME %ld sec", tEnd - tStart); Syd_WriteSunPrint(strData, strlen(strData), &PrintStruct, &FontInfo); Syd_SendSunPrintInit(&PrintStruct, 1, 1); sprintf(strData, "SPEED %.1lf line/sec", 100.0/(tEnd - tStart));fprintf(stderr, "SPEED %.1lf line/sec", 100.0/(tEnd - tStart)); Syd_WriteSunPrint(strData, strlen(strData), &PrintStruct, &FontInfo); Syd_SendSunPrintInit(&PrintStruct, 1, 1); Syd_PrinterFeed(100); Syd_FreeSunPrint(&PrintStruct); Syd_CloseSunFont(&FontInfo); Syd_ClosePrinter(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -