procedure tform1.OpenSerialPort;
var
cc:TCommConfig;
Temp:string;
begin
Temp:=\'Com\'+inttostr(RadioGroup1.ItemIndex+1);
hSerialPort:=CreateFile(PChar(Temp),GENERIC_READ or GENERIC_WRITE,0,nil,OPEN_EXISTING,0,0);
if (hSerialPort=invalid_handle_value) then
begin
MessageBox(0,\'打开串口失败\',\'\',MB_OK);
Exit;
end;
GetCommState(hSerialPort,cc.dcb);
cc.dcb.BaudRate:=CBR_9600;
cc.dcb.ByteSize:=8;
cc.dcb.Parity:=NOPARITY;
cc.dcb.StopBits:=ONESTOPBIT;
if not SetCommState(hSerialPort,cc.dcb) then
begin
ShowMessage(\'不能设置串口\');
CloseHandle(hSerialPort);
Exit;
end
else
ShowMessage(\'打开,并设置成功!\');
end;
procedure TFrmMain.ShowMoney(Money_Port: String;Money_String:String);
//Moneey_Port 顾显接口Com1 or Com2 Money_String 顾显显示的内容
var
PrnFileName:TextFile;
begin
Assignfile(PrnFileName,Money_Port);
printer.Canvas.Font.Name:=\'宋体\';
printer.Canvas.Font.Size:=8;
printer.Canvas.Font.Charset:=GB2312_CHARSET;
Rewrite(PrnFileName);
write(PRNFileName,chr(12)); //清除顾显
write(PRNFileName,chr(27)+chr(81)+chr(65)+Money_String+chR(13)); //显示信息
CloseFile(PRNFileName);
end;
2、不换页走纸的打印
procedure TFrmMain.AddPrintStrings(Strings: TStrings);
var
Prn: TextFile;
i: word;
begin
Assignfile(Prn,\'lpt1\');
printer.Canvas.Font.Name:=\'宋体\';
printer.Canvas.Font.Size:=9;
printer.Canvas.Font.Charset:=GB2312_CHARSET;
try
Rewrite(Prn);
try
for i := 0 to Strings.Count - 1 do
writeln(Prn, Strings.Strings[i]);
finally
CloseFile(Prn);
end;
except
on EInOutError do
MessageBox(Handle,PChar(\'文本打印出错!\'),\'警告\',MB_ICONEXCLAMATION or MB_OK);
end;
end;
3、走纸换页的打印
procedure TFrmMain.PrintStrings(Strings: TStrings);
var
Prn: TextFile;
i: word;
begin
AssignPrn(Prn);
try
Rewrite(Prn);
printer.Canvas.Font.Name:=\'宋体\';
printer.Canvas.Font.Size:=9;
printer.Canvas.Font.Charset:=GB2312_CHARSET;
try
for i := 0 to Strings.Count - 1 do
writeln(Prn, Strings.Strings[i]);
finally
CloseFile(Prn);
end;
except
on EInOutError do
MessageBox(Handle,PChar(\'文本打印出错!\'),\'警告\',MB_ICONEXCLAMATION or MB_OK);
end;
end;
4、打开钱箱
procedure TFrmMain.OpenMoneyBox;
Var F:TextFile;
PDStr:string;
begin
//弹出钱箱功能
PDStr:= Chr(27)+\'p\'+Chr(0)+Chr(60)+Chr(255);
AssignFile(F, \'LPT1\');
Rewrite(F);
Write(F, PDStr);
CloseFile(F);
end;
请发表评论