怎样做出通用的pos小票打印程序
POS小票打印机分为热敏和针式俩种。
打印纸的宽度分为58毫米、76毫米和80毫米三种。
打印接口分为:串口、并口、USB和网口(以太网)。
热敏打印机速度较快,打印的时候噪音少,针打可以使用多联纸自动复印。
热敏打印机价格一般比较便宜,不需要频繁地更换色带。
并口打印机,可直接"端口输出",不需要安装打印机的驱动程序。
几乎所有的POS小票打印机都可以兼容EPSON的ESC POS打印机指令。
const
// 末尾走纸几行
c_run_paper_lines = 6;
// ESC指令 开钱箱
c_OpenMoneyBoxCommand = CHR(27) + CHR(112) + CHR(0) + CHR(17) + CHR(8);
// ESC指令 自动切纸
c_cut_paper = CHR(29) + CHR(86) + CHR(66) + CHR(0);
type // usb接口票打用
TOutBufPassThrough = record
nDataLen: word;
sEscData: array [0 .. 1024] of AnsiChar;
end;
// usb接口开钱箱
procedure OpenUSBMoneyBox;
var
prt: TPrinter;
esc: TOutBufPassThrough;
begin
try
prt := Printers.Printer;
prt.beginDoc;
esc.nDataLen := Length(c_OpenMoneyBoxCommand);
strpCopy(esc.sEscData, c_OpenMoneyBoxCommand);
windows.ExtEscape(prt.Handle, PASSTHROUGH, sizeOf(esc), @esc, 0, nil);
prt.endDoc;
except
end;
end;
// usb接口切纸
procedure usbCutPaper;
var
prt: TPrinter;
esc: TOutBufPassThrough;
begin
try
prt := Printers.Printer;
prt.beginDoc;
esc.nDataLen := Length(c_cut_paper);
strpCopy(esc.sEscData, c_cut_paper);
windows.ExtEscape(prt.Handle, PASSTHROUGH, sizeOf(esc), @esc, 0, nil);
prt.endDoc;
except
end;
end;
procedure TfrmReprint.Print80;
var
sPort: string;
RPrinter: TextFile;
i: Integer;
sBill, sBarcode, sXH, sPortType: string;
MyList: TStringList;
BillId: string;
sTmp: string;
iTmp: Integer;
sMoney: string;
sGoodName: string;
iLen: Integer;
sTmp2: string;
begin
// 生成一个小票的文本文件
sBill := ExtractFilePath(Application.ExeName) + 'bill.txt';
AssignFile(RPrinter, sBill);
Rewrite(RPrinter);
try
// 店名
Writeln(RPrinter, ' ' + UserInfo.ShopName);
Writeln(RPrinter, '机号 收款员 交易流水号');
sTmp := UserInfo.MachineId + ' ' + UserInfo.UserCode;
iTmp := 32 - Length(sTmp);
i := Length(cdsMaster.FieldByName('saleno').Text);
while i < iTmp do
begin
BillId := BillId + ' ';
i := i + 1;
end;
BillId := BillId + cdsMaster.FieldByName('saleno').Text;
Writeln(RPrinter, sTmp + BillId);
Writeln(RPrinter, '印小票时间:' + FormatDatetime('yyyy-mm-dd hh:nn', now));
Writeln(RPrinter, '-------------------------------------');
cdsDetail.First;
while not cdsDetail.Eof do
begin
// 序号
sXH := cdsDetail.FieldByName('Sequence').Text;
while Length(sXH) < 2 do
begin
sXH := sXH + ' ';
end;
// 金额
sMoney := FormatFloat('0.00', cdsDetail.FieldByName('amount').AsFloat);
i := Length(sMoney);
sTmp := '';
while i < 9 do
begin
sTmp := sTmp + ' ';
i := i + 1;
end;
sMoney := sTmp + sMoney;
// 商品名称
sGoodName := cdsDetail.FieldByName('goodsName').Text;
iLen := Length(sGoodName);
while iLen < 9 do
begin
sGoodName := sGoodName + ' ';
iLen := iLen + 1;
end;
Writeln(RPrinter, sXH + ' ' + sGoodName + cdsDetail.FieldByName('qty')
.Text + '*' + FormatFloat('0.00', cdsDetail.FieldByName('buyPrice')
.AsFloat) + sMoney);
cdsDetail.Next;
end;
Writeln(RPrinter, '-------------------------------------');
Writeln(RPrinter, '金额:' + FormatFloat('0.00',
cdsMaster.FieldByName('BalanceAmount').AsFloat));
Writeln(RPrinter, sTmp2);
Writeln(RPrinter, ' 谢谢惠顾!');
// 末尾走纸 行数
for i := 1 to c_run_paper_lines do
Writeln(RPrinter, '');
finally
CloseFile(RPrinter);
end;
if SameText(UserInfo.PrintPort, 'lpt') then // 直接并口输出 不要安装票打驱动
begin
// 读取文本文件打印小票
sPort := 'LPT1';
MyList := TStringList.Create;
try
AssignFile(RPrinter, sPort);
try
Rewrite(RPrinter);
MyList.LoadFromFile(sBill);
for i := 0 to MyList.Count - 1 do
begin
Writeln(RPrinter, MyList.Strings[i]);
end;
// 开钱箱
write(RPrinter, c_OpenMoneyBoxCommand);
write(RPrinter, c_cut_paper);
CloseFile(RPrinter);
except
// 如果LPT1端口不存在,会报错:the specified file not found
// 有些主板不提供LPT并口,不屏蔽错误,无法收银
end;
finally
MyList.Free;
end;
end
else if SameText(UserInfo.PrintPort, 'usb') then // 需要安装票打驱动
begin
try
RichEdit1.Font.Size := 12;
RichEdit1.Lines.Clear;
RichEdit1.Lines.LoadFromFile(sBill);
RichEdit1.Print('');
if UserInfo.openMoneyBox = 1 then
OpenUSBMoneyBox;
except
on e: Exception do
SysLog.WriteLog('TfrmReprint.Print80' + e.Message);
end;
end;
end;
怎样做出通用的pos小票打印程序的更多相关文章
- C# POS 小票打印
网上查了好多资料终于让我捣鼓出来了! public partial class Models_JXC_Sale_actNewSalePage : WebPartBase { public string ...
- 【转】C#使用ESC指令控制POS打印机打印小票
.前言 C#打印小票可以与普通打印机一样,调用PrintDocument实现.也可以发送标注你的ESC指令实现.由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的pos ...
- C#使用ESC指令控制POS打印机打印小票
1.前言 C#打印小票可以与普通打印机一样,调用PrintDocument实现.也可以发送标注你的ESC指令实现.由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的po ...
- 重复造轮子系列——基于FastReport设计打印模板实现桌面端WPF套打和商超POS高度自适应小票打印
重复造轮子系列——基于FastReport设计打印模板实现桌面端WPF套打和商超POS高度自适应小票打印 一.引言 桌面端系统经常需要对接各种硬件设备,比如扫描器.读卡器.打印机等. 这里介绍下桌面端 ...
- Ajax使用WCF实现小票pos机打印源码
通过ajax跨域方式调用WCF服务,实现小票pos机的打印,源码提供web方式,客户端方式测试,服务驻留右侧底部任务栏,可控制服务开启暂停,用户可自定义小票打印模板,配合零售录入. qq 22945 ...
- linux下使用小票打印
linux下使用小票打印 打印机: Xprinter XP-58IIH指令支持: ESC/POS接口: USB, 蓝牙 Linux系统: Centos7 蓝牙配对很快, 配对好后就是连接状态. 但很快 ...
- Delphi 10 Seattle 小票打印控件TQ_Printer
TQ_Printrer控件,是一个为方便需要控制打印命令而设计的跨平台专用控件,已包含标准ESC/POS打印控制的基本指令在内(这些基本指令已能很好的满足多数项目使用). TQ_Printrer控件让 ...
- c# 小票打印
c# 在进行小票打印时大致有三种方法. 1. 使用水晶报表进行打印.可以参考:https://www.cnblogs.com/aitong/p/10717786.html 2. 在 PrintDocu ...
- Android打印机--小票打印格式及模板设置
小票打印就是向打印设备发送控制打印格式的指令集,而这些打印格式须要去查询相应打印机的API文档,这里我把经常使用的api给封装了一下 文字对齐方式 打印字体大小 字体是否加粗 打印二维码 打印条形码 ...
随机推荐
- delphi xe5 android 开发数据访问手机端 解决乱码的办法
经过测试,将sqlserver里的字段由varchar 或者char 改为 nvarchar 或者nchar 然后在手机端的clientdataset 增加字段的时候数据类型选择widestrin ...
- responsive web design
http://d.alistapart.com/responsive-web-design/ex/ex-site-flexible.html http://alistapart.com/article ...
- 保护模式下pmtest1.asm的理解
整个代码对应内存线性地址分为四段,[gdt] [code32] [video32] [code16] 代码先在实模式[code16]下运行,code16中的cs就是系统分配的该程序物理地址的基址. 编 ...
- [水题]ZOJ3038 Triangle War II
题意: 给了这样一张图 有两种状态:pushed(*)和unpushed(.) 为方便起见分别成为 开 和 关 改变一个点的开关状态 会同时改变与它相邻的点的开关状态 比如改变5,则2.3.4 ...
- 如何在Oracle11中配置st_shapelib
- MySQL的SQL_CALC_FOUND_ROWS
分页程序一般由两条SQL组成: SELECT COUNT(*) FROM ... WHERE .... SELECT ... FROM ... WHERE LIMIT ... 如果使用SQL_CALC ...
- error: 'LOGE' was not declared in this scope
移植了下HAL,发现编译出现如下错误 error: 'LOGE' was not declared in this scope 比较了一下android4.1的 system/core/include ...
- ActionBar官方教程(10)ActionBar的下拉列表模式
Adding Drop-down Navigation As another mode of navigation (or filtering) for your activity, the acti ...
- 【HDOJ】2295 Radar
DLX+二分. /* 2295 */ #include <iostream> #include <string> #include <map> #include & ...
- Understanding Item Import and Debugging Problems with Item Import (Doc ID 268968.1)
In this Document Purpose Details Scenario 1: Testing the basic item import with minimum columns po ...