unit serial1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, IniFiles, LazSerial, LazSynaSer;
const
Prefix = 'BV EBDS';
CTRL_Omnibus = $10;
CTRL_Calibrate = $40;
CTRL_Download = $50;
CTRL_Auxiliary = $60;
CTRL_Extended = $70;
type
{ TMod_Billetero }
TMod_Billetero = class(TDataModule)
LazSerial1: TLazSerial;
procedure LazSerial1Status(Sender: TObject; Reason: THookSerialReason;
const Value: string);
private
PP :String;
Function Conectar( Inicializar_BV: Boolean): Integer;
public
Function Start_Up (Boot_BV: Boolean): Longint;
Function Cerrar: Longint;
end;
var
Mod_Billetero: TMod_Billetero;
implementation
{$R *.lfm}
Function TMod_Billetero.Cerrar: Longint;
begin
//TXTime.Enabled:=false;
//RXTime.Enabled:=false;
if LazSerial1.Active then
begin
LazSerial1.SynSer.Purge;
LazSerial1.Close;
end;
{ if BV_Bill_Config.Operativo then
begin
BV_Bill_Config.Operativo := False;
end; }
{if Activar_Logs then
Registro_Log(Archivo_Logs,Prefix,'DLL Correctamente Cerrada'); }
Result := 0;
end;
Function TMod_Billetero.Start_Up (Boot_BV: Boolean) : Integer;
var
Log_Dir : String;
Temp_Str : String;
FIniFileName : String;
Grabar : Boolean;
IniFile : TIniFile;
Temp_Int : Integer;
App_Name : String;
begin
{$IFDEF LINUX}
IniFile := TIniFile.Create(
GetAppConfigFile(False) + '.conf');
{$ELSE}
IniFile := TIniFile.Create(
ExtractFilePath(Application.EXEName) + 'SimuGps.ini');
{$ENDIF}
{ Temp_Str := ExtractFilePath (Get_Aplication_Name);
{$IFDEF MSWINDOWS}
Log_Dir := Temp_Str + 'Logs\';
{$ENDIF}
{$IFDEF Linux}
Log_Dir := Temp_Str + 'Logs';
{$ENDIF}
if Not DirectoryExists(Log_Dir) then
CreateDir(Log_Dir);
Temp_Str := ExtractFileName(Get_Aplication_Name);
Archivo_logs := ChangeFileExt(Temp_Str,'.log');
{$IFDEF MSWINDOWS}
Archivo_Logs := Log_Dir + Archivo_Logs;
{$ENDIF}
Temp_Str := Get_Aplication_Name;
App_Name := Temp_Str;
FIniFileName := ChangeFileExt(Temp_Str, '.ini');
Grabar := False;
if Not FileExists(FIniFilename) then
begin
Grabar := True;
end;
IniFile := TIniFile.Create(FIniFileName);
Temp_Int := IniFile.ReadInteger('LOGS', 'Activar', 1);
if Temp_Int = -1 then
begin
Grabar := true;
Activar_Logs := True;
end
else
Activar_Logs := (Temp_Int = 1);
Temp_Int := IniFile.ReadInteger('LOGS', 'Nivel', -1);
if Temp_Int = -1 then
begin
Grabar := true;
Log_Level := L_Info;
end
else
Log_Level := Temp_Int;
Temp_Int := IniFile.ReadInteger('Lenguaje', 'Idioma', -1);
if Temp_Int = -1 then
begin
Grabar := true;
LenguajeIndex := 1;
end
else
LenguajeIndex := Temp_Int;
if Grabar then
begin
if Activar_Logs then
IniFile.WriteInteger('LOGS', 'Activar', 1)
else
IniFile.WriteInteger('LOGS', 'Activar', 0);
end;
IniFile.Free;
if Activar_Logs then
begin
Registro_Log(Archivo_Logs,Prefix,'#################################');
Registro_Log(Archivo_Logs,Prefix,' EBDSCOMM');
Registro_Log(Archivo_Logs,Prefix,' Iniciando Servicio por Start_Up');
Registro_Log(Archivo_Logs,Prefix,'#################################');
Registro_Log(Archivo_Logs,Prefix,'Version de DLL : ' + About);
Registro_Log(Archivo_Logs,Prefix,'Indentificador de Hardware : ' + Get_Identifier);
end;
if Leer_Valores_Default then // Arranco con algo configurado por las dudas
begin
if Not Load_Variables_Entorno_Puerto(true) then // Si no esta configurado - Configuro y Guardo
begin
Result := -2;
Exit;
end
else
if Not Load_Variables_Entorno_Billetes(true) then // Si no esta configurado - Configuro y Guardo
begin
Result := -2;
Exit;
end
else
begin
Cargar_Tabla_Paises;
BV_Protocolo := 'EBDS';
StrPLCopy(PChar(@BV_Bill_Config.Protocolo[0]), BV_Protocolo, High(BV_Bill_Config.Protocolo)); }
Result := Conectar(Boot_BV);
{ end;
end
else
begin // Aca no deberia entrar NUNCA
Result := -1;
Exit;
end; }
end;
procedure TMod_Billetero.LazSerial1Status(Sender: TObject;
Reason: THookSerialReason; const Value: string);
begin
case Reason of
HR_SerialClose : begin
pp :='Cerrado';
// StatusBar1.SimpleText := 'Port ' + Value + ' closed';
end;
HR_Connect : begin
pp :='Conectado';
// StatusBar1.SimpleText := 'Port ' + Value + ' connected';
end;
HR_CanRead : begin
pp :='Puede Leer';
// StatusBar1.SimpleText := 'CanRead : ' + Value ;
end;
HR_CanWrite : begin
pp :='Puede Escribir';
// StatusBar1.SimpleText := 'CanWrite : ' + Value ;
end;
HR_ReadCount : begin
pp :='Conteo de Lectura';
// StatusBar1.SimpleText := 'ReadCount : ' + Value ;
end;
HR_WriteCount : begin
pp :='Conteo de Escritura';
// StatusBar1.SimpleText := 'WriteCount : ' + Value ;
end;
HR_Wait : begin
pp :='Wait';
// StatusBar1.SimpleText := 'Wait : ' + Value ;
end;
end ;
end;
Function TMod_Billetero.Conectar( Inicializar_BV: Boolean): Integer;
begin
LazSerial1.Device:= '/dev/ttyUSB0';
LazSerial1.DataBits:= db7bits;
LazSerial1.Parity:= pEven;
LazSerial1.BaudRate:= br__9600;
LazSerial1.open;
Result := 0;
end;
initialization
try
Mod_Billetero := TMod_Billetero.Create(nil);
except
begin
//Result := -1;
end;
end;
finalization
if Assigned(Mod_Billetero) then
begin
FreeAndNil(Mod_Billetero);
end;
end.