有开发过cpt8000的数据读取程序的吗? ( 积分: 200 )

  • 主题发起人 主题发起人 duancy
  • 开始时间 开始时间
D

duancy

Unregistered / Unconfirmed
GUEST, unregistred user!
盘点机光盘中只有一个VC的说明文件,我用delphi测试可以连接了,但是有一个奇怪的问题:
读取的第一条记录总是空的,而以后的记录正常!请大家帮忙,代码如下:

unit UnitCpt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TFormCpt = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

//动态库的函数声明
function OpenIrCom(nport:smallint; nBaud:longint): longint; stdcall;far;external 'IrLib.dll';
function vbOpenIrCom(nport:smallint; nBaud:longint): longint; stdcall;far;external 'IrLib.dll';
procedure CloseIrCom()stdcall;far;external 'IrLib.dll';
procedure WriteIrCom(Str:Pchar)stdcall;far;external 'IrLib.dll';
function ReadIrCom():Pchar;stdcall;far;external 'IrLib.dll';
function vbReadIrCom(arr:Pchar):longint;stdcall;far;external 'IrLib.dll';
function ShowErrorMessage(nShow:smallint):smallint;stdcall;far;external 'IrLib.dll';

var
FormCpt: TFormCpt;

implementation

{$R *.dfm}

procedure TFormCpt.Button1Click(Sender: TObject);
var
szData : array[0..255] of char;
begin
if combobox1.ItemIndex < 0 then
begin
MessageBox (Handle, '端口没有选择!', '错误', MB_OK);
exit;
end;
memo1.Lines.Clear;
memo1.Lines.Add('开始');
OpenIrCom(Combobox1.ItemIndex+1, 115200);
WriteIrCom('READ' + #13);
while True do
begin
fillchar(szData[low(szData)],length(szData),#0);
StrPCopy(szData, ReadIrCom());
if szData = 'OVER' + #13 then
begin
MessageBox (Handle, '传输完成!', '提示', MB_OK);
break;
end;
if szData = 'NAK' + #13 then
begin
MessageBox (Handle, '命令错误!', '提示', MB_OK);
break;
end;
// if szData = '' then //注意:第一条记录总是出现为空,没办法,暂时不用
// begin
// MessageBox (Handle, '传输错误!', '提示', MB_OK);
// break;
// end;
WriteIrCom ('ACK' + #13); //如果NAK则表示接受错误,需要重发数据
memo1.Lines.Add(szData);
sleep(100)
end;
memo1.Lines.Add('结束');
CloseIrCom();
end;

procedure TFormCpt.Button2Click(Sender: TObject);
begin
close;
end;

end.
 
这种东西太专业了,相信做过的人不多。
建议你找一下厂家的技术支持,你这里搞半天,说不定人家一句话就帮你解决了。
 
我联系了厂家,他发了一个通讯协议过来:
****************************************************************************
***** Protocol for receiving transaction data from CPT-7xx terminals *****
****************************************************************************

Note : All commands or records sent to or received from the CPT-7xx
terminals should be ended with a return character (0x0d).

1. Send the &quot;READ&quot; command to the CPT-7xx terminal and wait for return.

2. If the terminal returns &quot;ACK&quot;, then it is ready to send data to PC.

3. The format of each record received from the terminal is as follows,

A. The first byte is a sequence count rotated from 0 to 9. It's purpose
is to ensure the correct order of data transmission.
B. The last two bytes are the checksum values. The checksum is calculated
by adding up the sequence count and all the data bytes.
C. Devide the sum calculated above by 256 will get the last byte checksum
value. If this value happens to be 13 (the return character: 0x0d),
change it to 14 (0x0e).
D. The remaining of the above calculation is the first byte checksum
value. If it happens to be 13, change it to 14.
E. Please note that the checksum byte-order for this protocol is different
to that of downloading lookup files.

4. If the received data is correct, the PC program should return &quot;ACK&quot; to the
CPT-7xx terminal so that it can send the next record.

5. If the received data is not correct, the PC program should return &quot;NAK&quot; to
the CPT-7xx terminal so that it can resend the record.

6. If the received data is duplicated (i.e. the sequence count is same as
previous record), then the PC program should discard this record but still
return &quot;ACK&quot; to the CPT-7xx terminal so that it can send the next record.

7. Repeat the above procedures until receiving the &quot;OVER&quot; command from the
CPT-7xx terminal.
我应该是照做的,难道没有看明白!!
 
后退
顶部