Boa Tarde a todos, me desculpem pela demora, estava meio fora da programação.
Segue a unit da Balança digitron, eu ja utililzo ele e funciona perfeitamente, seria interessando os colegas adicionar no projeto, pois ficaria mais fácil as atualizações, pois hoje toda vez que atualizo tenho que alterar as units.
{$I ACBr.inc}
unit ACBrBALDigitron;
interface
uses ACBrBALClass,
Classes;
const STX = #02 ;
ETX = #03 ;
CR = #13 ;
type
TACBrBALDigitron = class( TACBrBALClass )
public
constructor Create(AOwner: TComponent);
function LePeso( MillisecTimeOut : Integer = 3000) :Double; override;
procedure LeSerial( MillisecTimeOut : Integer = 500) ; override ;
end ;
implementation
Uses ACBrBAL, ACBrUtil,
{$IFDEF COMPILER6_UP} DateUtils, StrUtils {$ELSE} ACBrD5, Windows{$ENDIF},
SysUtils, Math ;
{ TACBrBALToledo }
constructor TACBrBALDigitron.Create(AOwner: TComponent);
begin
inherited Create( AOwner );
fpModeloStr := 'Digitron' ;
end;
function TACBrBALDigitron.LePeso( MillisecTimeOut : Integer) : Double;
begin
fpUltimoPesoLido := 0 ;
fpUltimaResposta := '' ;
fpDevice.Serial.Purge ; { Limpa a Porta }
fpDevice.EnviaString( #05 ); { Envia comando solicitando o Peso }
sleep(200) ;
LeSerial( MillisecTimeOut );
Result := fpUltimoPesoLido ;
end;
procedure TACBrBALDigitron.LeSerial(MillisecTimeOut: Integer);
Var
Resposta : AnsiString ;
Decimais : Integer ;
St2 : AnsiChar ;
PI,PF : Integer ;
begin
fpUltimoPesoLido := 0 ;
fpUltimaResposta := '' ;
Decimais := 100 ;
Try
fpUltimaResposta := Copy(fpDevice.Serial.RecvPacket( MillisecTimeOut ),1,10);
Resposta := Trim( copy( fpUltimaResposta, 2, 6 )) ;
{ Ajustando o separador de Decimal corretamente }
Resposta := StringReplace(Resposta, '.', DecimalSeparator, [rfReplaceAll]);
Resposta := StringReplace(Resposta, ',', DecimalSeparator, [rfReplaceAll]);
try
if pos(DecimalSeparator,Resposta) > 0 then { Já existe ponto decimal ? }
fpUltimoPesoLido := StrToFloat(Resposta)
else
fpUltimoPesoLido := StrToInt(Resposta) / Decimais ;
except
case Resposta[1] of
'I' : fpUltimoPesoLido := -1 ; { Instavel }
'N' : fpUltimoPesoLido := -2 ; { Peso Negativo }
'S' : fpUltimoPesoLido := -10 ; { Sobrecarga de Peso }
else
fpUltimoPesoLido := 0 ;
end;
end;
except
{ Peso não foi recebido (TimeOut) }
fpUltimoPesoLido := -9 ;
end ;
end;
end.
Fim
Att.
Adauto