ler dados porta serial

Delphi

23/01/2004

Estou usando um coletor com código de barras, ele manda o que leu no código de barras para porta serial. Qdo vou abrir o canal de conexão , dá um erro -518. Alguém tem idéia do que está acontecendo?

Obrigada,
Debora


Debora

Debora

Curtidas 0

Respostas

Aroldo Zanela

Aroldo Zanela

23/01/2004

Colega,

O que você está utilizando para efetuar a leitura?


GOSTEI 0
Debora

Debora

23/01/2004

[quote:0965c9f4aa=´Aroldo Zanela´]Colega,

O que você está utilizando para efetuar a leitura?[/quote:0965c9f4aa]

um amigo me passou este programa, não entendi direito...
( aqui é a parte para abrir o canal de comunicação)


{-------------------------------------------------------------------------------
TRIX Tecnologia Ltda.
--------------------------------------------------------------------------------
Projeto.........: RFTEST
Modulo..........: OPENRF.PAS - Definicao do Projeto
Versao..........: 1.0
Compilacao......: Delphi 3.0
Ambientes.......: Windows 95/NT
Ultima alteracao: 10/08/1999
Responsavel.....: VM
-------------------------------------------------------------------------------}

unit openRF;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask;

type
TfrmOpenRF = class(TForm)
grpRFCanal: TGroupBox;
rbRFCom1: TRadioButton;
rbRFCom2: TRadioButton;
rbRFCom3: TRadioButton;
rbRFCom4: TRadioButton;
cmdOK: TButton;
cmdCancela: TButton;
grpTaxa: TGroupBox;
lbTaxa: TListBox;
Label1: TLabel;
Label2: TLabel;
StaticText1: TStaticText;
txtHostTimeout: TEdit;
txtHostRetries: TEdit;
Label3: TLabel;
procedure OnCreate(Sender: TObject);
procedure OnActivate(Sender: TObject);
procedure cmdCancelaClick(Sender: TObject);
procedure cmdOKClick(Sender: TObject);

private
rbCOM: array[0..3] of TRadioButton;

public
{ Public declarations }
end;

var
frmOpenRF: TfrmOpenRF;

implementation

uses Global, XPCom32, main;

{$R *.DFM}

{*------------------------------------------------------------------------------
TFrmOpenRF.OnCreate - Inicializacao do Form
------------------------------------------------------------------------------*}

procedure TfrmOpenRF.OnCreate(Sender: TObject);

begin

{Prepara Array para acessar Radio Buttons dos Canais Seriais -----------}

rbCOM[0] := rbRFCom1;rbCOM[1] := rbRFCom2;
rbCOM[2] := rbRFCom3;rbCOM[3] := rbRFCom4;

{Inicializa Lista de Taxas de Comunicacao e seleciona default ----------}

lbTaxa.Items.Add(´1200´);
lbTaxa.Items.Add(´2400´);
lbTaxa.Items.Add(´4800´);
lbTaxa.Items.Add(´9600´);
lbTaxa.Items.Add(´19200´);
lbTaxa.Items.Add(´38400´);
lbTaxa.ItemIndex := 3;

{ Seleciona o tempo de timeout do Host ---------------------------------------}

txtHostTimeout.Text := ´10´;

{ Seleciona o numero de retries do Host --------------------------------------}

txtHostRetries.Text := ´5´;
end;

{*-----------------------------------------------------------------------------
TFrmOpenRF.OnActivate - Atualiza Dialog Box antes de sua exibicao
------------------------------------------------------------------------------*}

procedure TfrmOpenRF.OnActivate(Sender: TObject);

Var
nCom: integer;
nSetCom: integer;
nResult: integer;
bHasChannel: boolean;

begin

{ Seleciona primeiro canal que pode ser aberto -------------------------------}

bHasChannel := FALSE;
for nCom := 3 downto 0 do
begin
nResult := ComOpen(nCom, 9600, 8, 1, COM_NONEP, COM_NOFLOW, COM_NOFLOW, 100, 100);
if nResult <> 0 then
rbCOM[nCom].Enabled := FALSE
else
begin
nResult := ComClose(nCom);
nSetCom := nCom;
bHasChannel := TRUE
end;
end;
if bHasChannel = TRUE then
rbCOM[nSetCom].Checked := TRUE
else
cmdOK.Enabled := FALSE;
end;

{*------------------------------------------------------------------------------
TFrmOpenRF.cmdCancelaClick - Cancela Dialog Box
------------------------------------------------------------------------------*}

procedure TfrmOpenRF.cmdCancelaClick(Sender: TObject);

begin
Close;
end;

{*------------------------------------------------------------------------------
TFrmOpenRF.cmdOKClick - Confirma Dialog Box
------------------------------------------------------------------------------*}

procedure TfrmOpenRF.cmdOKClick(Sender: TObject);

Var
nCom: Integer;
nChannel: Integer;
nPos: Integer;
nResult: Integer;
nSize: integer;

lTaxa: Longint;
nHostTimeout: integer;
nHostRetries: integer;

sResult: String;
sMsg: string; {string auxiliar para mensagens de erro}

sTaxa: String;
sHostTimeout: string;
sHostRetries: string;


begin

{Obtem canal selecionado -----------------------------------------------}

for nCom := 0 to 3 do
if rbCOM[nCom].Checked = TRUE then
nChannel := nCom;

{ Obtem taxa selecionada ------------------------------------------------}

sTaxa := lbTaxa.Items[lbTaxa.ItemIndex];
Val(sTaxa, lTaxa, nPos);

{ Obtem o tempo de timeout do Host ---------------------------------------}

sHostTimeout := txtHostTimeout.Text;
TrimLeft(sHostTimeout);
TrimRight(sHostTimeout);
nSize := Length(sHostTimeout);
if nSize = 0 then
begin
MessageDlg(´Tempo de Timeout Precisa ser Fornecido´, mtWarning, [mbOK], 0);
Exit;
end;
nHostTimeout := StrToInt(sHostTimeout);

{ Obtem o numero de retries do Host --------------------------------------}

sHostRetries := txtHostRetries.Text;
TrimLeft(sHostRetries);
TrimRight(sHostRetries);
nSize := Length(sHostRetries);
if nSize = 0 then
begin
MessageDlg(´Numero de Retries Precisa ser Fornecido´, mtWarning, [mbOK], 0);
Exit;
end;
nHostRetries := StrToInt(sHostRetries);

{ Chama funcao da XPCOMLIB para abertura do Canal ----------------------------}

nResult := RFnetOpen(nChannel, lTaxa, TXBUFFER, RXBUFFER, nHostRetries);
if nResult = 0 then
begin
frmMain.MainMenu1.Items[1].Enabled := True; { ativa menus de config e Msgs}
frmMain.MainMenu1.Items[2].Enabled := True;
end
else
begin
Str(nResult, sResult);
sMsg := ´Erro: ´ + sResult + ´ na Abertura do Canal !´;
nResult := MessageDlg(sMsg, mtWarning, [mbOK], 0);
Exit;
end;

//----------------------------------------------------------------------------

if nResult >= 0 then
begin
nResult := RFnetSetConfig(nChannel, RFNCFG_HOSTTIMEOUT, nHostTimeout);
if nResult >= 0 then
nResult := RFnetWaitResult(nChannel);
if nResult < 0 then
begin
Str(nResult, sResult);
sMsg := ´Erro: ´ + sResult + ´ na configuracao do Timeout!´;
nResult := MessageDlg(sMsg, mtWarning, [mbOK], 0);
nResult := RFnetClose(nChannel);
frmMain.MainMenu1.Items[1].Enabled := False;
frmMain.MainMenu1.Items[2].Enabled := False;
Exit;
end;
end;

//----------------------------------------------------------------------------

if nResult >= 0 then
begin
nResult := RFnetSetConfig(nChannel, RFNCFG_HOSTRETRIES, nHostRetries);
if nResult >= 0 then
nResult := RFnetWaitResult(nChannel);
if nResult < 0 then
begin
Str(nResult, sResult);
sMsg := ´Erro: ´ + sResult + ´ na configuracao dos Retries!´;
nResult := MessageDlg(sMsg, mtWarning, [mbOK], 0);
nResult := RFnetClose(nChannel);
frmMain.MainMenu1.Items[1].Enabled := False;
frmMain.MainMenu1.Items[2].Enabled := False;
Exit;
end;
end;

//--------------------

Close;
end;

end.


GOSTEI 0
POSTAR