Delphi COM串口打印演示

unit Unit1;
//Download by http://www.NewXing.com
interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, RzPanel, StdCtrls, RzCmboBx, RzButton, ComCtrls,
RzEdit, OleCtrls, MSCommLib_TLB;

type
TForm1 = class(TForm)
mscm1: TMSComm;
edt1: TRzRichEdit;
rzbtbtn1: TRzBitBtn;
cbb1: TRzComboBox;
rzpnl1: TRzPanel;
rzbtbtn2: TRzBitBtn;
rzbtbtn3: TRzBitBtn;
edt2: TEdit;
procedure mscm1Comm(Sender: TObject);
procedure rzbtbtn1Click(Sender: TObject);
procedure rzbtbtn2Click(Sender: TObject);
procedure rzbtbtn3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.mscm1Comm(Sender: TObject);
var
n : Integer;
rx :Integer;
recstr : Variant;
t : string;
i : Integer;
tr : Integer;
strintext :string;
begin
recstr:= Copy(mscm1.Input,1,2);
strintext:= recstr ;
edt2.Text:=Trim(strintext);
// if mscm1.CommEvent =comEventBreak then
// begin
// edt1.Text:='PRINT';
// end;
{
if mscm1.CommEvent = ComEventRxParity then
tr:=1;
if mscm1.CommEvent = 2 then
begin
n:=mscm1.InBufferCount;
inc(rx,n);
recstr :=mscm1.Input;
if mscm1.InputMode = 0 then
begin
t:='';
t:= recstr;
if t<>'' then
begin
for i:= 0 to n do
begin
if t[i]='?' then
begin
tr:=1
end
else
if (tr=0) then
begin
strintext:=strintext+' ' + IntToHex(Byte(t[i]),2)
end
else
begin
strintext:= strintext+' ' + IntToHex(Byte(t[i])+126,2) ;
tr:=0;
end;
end;
end;
end;
end; }
end;

procedure TForm1.rzbtbtn1Click(Sender: TObject);
begin
if mscm1.PortOpen then
begin
mscm1.PortOpen:=False;
end;
try
mscm1.CommPort:=1;
mscm1.Settings:='9600,N,8,1';
mscm1.InputLen:=0; // default 0
mscm1.RThreshold:=1;
mscm1.InputMode:=comInputModeText;
mscm1.InputLen:=0;
mscm1.PortOpen:=True;
except
mscm1.PortOpen:=False;
end;
// end
end;

procedure TForm1.rzbtbtn2Click(Sender: TObject);
begin
Application.Terminate;
end;

procedure TForm1.rzbtbtn3Click(Sender: TObject);
begin
if mscm1.PortOpen = True then
mscm1.PortOpen := False;
end;

end.

转载于:https://www.cnblogs.com/fuhuo/p/11152105.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值