📄 pr3.c
字号:
/* PR50 Olivetti Emulation Mode Test Program */
/*ESC&n1n2 line space */
/* '4''0' */
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/termio.h>
#define init_printer "\x1bl\x1bn\x1b.\x1bQ066\x1bZ\x1bM001\x1bUq"
#define insert_paper "\x1b&32\x1bL006"
#define answer_of_printer "\x1br%"
int inkey(t)
{
struct termio ORG_tm, tm;
int key;
ioctl(0, TCGETA, &ORG_tm);
ioctl(0, TCGETA, &tm);
/*
memcpy(&tm, &ORG_tm, sizeof(tm));
*/
tm.c_lflag &= (ISIG & ~ECHO & ~ICANON);
tm.c_cc[VMIN] = 0; tm.c_cc[VTIME] = 1;
ioctl(0, TCSETA, &tm);
do {
key = getchar();
t--;
} while(key==-1 && t>0);
ioctl(0, TCSETA, &ORG_tm);
return(key);
}
unsigned char set_pr50_on()
{
char buf[16], c;
int i,j=0;
printf("请插入打印纸\n");
printf("\x1b[/3;1;8;0;1;0M");
printf("\x1b[5i");
do
{
printf("%s",init_printer);
for (i=0;i<=2;i++) buf[i]=inkey(i==0?50:2);
buf[i]=0;
j++;
}
while ((c=(strcmp(buf,answer_of_printer)))&&(j!=3));
if (j!=3)
{
printf("%s",insert_paper);
printf("\x1bj");
c=inkey(100);
c=inkey(3);
c=inkey(3);
if (c=='P')
return(0);
else
{ printf("\x1b[4i");
return(1);
}
}
else
{
printf("\x1b[4i\x1b[/M");
return(1);
}
}
void set_pr50_off()
{
printf("\x1b[4i\x1b[/M");
}
unsigned char test_oli()
{
if (set_pr50_on()==1)
return(1); /*打开打印机*/
printf("\012\033&40\033<");
printf("\033#1\033L002 Printer 五笔字型计算机汉字输入技术 Test Pr50(Olivetti mode)\012");
printf("\033L003passbook printer,This is normal character\012");
printf("\033L005\0333\033>passbook printer,This is double width character\015\012\033<\0334");
printf("\033L007\033d\033>passbook printer,This is double high & double width character\015\012\033<\033e");
printf("\033L009\033*0passbook printer,This is under line character\012\033+");
printf("\033L011\033(passbook printer,This is black character\012\033)");
printf("\033L013passbook printer\033`0This is up site character ABCabc\012\033{");
printf("\033L015passbook printer, Now set line space 80/240 inch, and skip 3 lines(1 inch)\012\033&80\x0a\x0a\x0a\x0d");
printf("\033&40");
printf("If this is PR970s, It will test paper here ... \x0a\x0d");
printf("\033L023\033>passbook printer, This character is 16.6cpi 060Absolute locate 60th\015\012\033=");
printf("\033L024passbook printer, This character is 12cpi 60Absolute locate 60th\012\033<");
printf("\033L025passbook printer, This character is 10cpi 060Absolute locate 60th\012");
printf("\x0a\x0a\x0a\x0a\x0a\x0a\0337\0337\0337\0337\012\015");
printf(" Printer Test finish, Thank You!\012\015");
printf("\x1b&40");
printf("\x1bO");
set_pr50_off(); /*关闭打印机*/
return(0);
}
main()
{
unsigned char ch;
if ((ch=test_oli())==0)
printf("打印完毕,正常结束\n");
else
printf("打印机可能发生故障, 请检查\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -