first commit (2002-04-24)
This commit is contained in:
5
ZT-2000/CardWriter.bpf
Normal file
5
ZT-2000/CardWriter.bpf
Normal file
@ -0,0 +1,5 @@
|
||||
USEUNIT("ZT2000.cpp");
|
||||
//---------------------------------------------------------------------------
|
||||
This file is used by the project manager only and should be treated like the project file
|
||||
|
||||
|
140
ZT-2000/CardWriter.bpr
Normal file
140
ZT-2000/CardWriter.bpr
Normal file
@ -0,0 +1,140 @@
|
||||
<?xml version='1.0' encoding='utf-8' ?>
|
||||
<!-- C++Builder XML Project -->
|
||||
<PROJECT>
|
||||
<MACROS>
|
||||
<VERSION value="BCB.06.00"/>
|
||||
<PROJECT value="CardWriter.exe"/>
|
||||
<OBJFILES value="ZT2000.obj"/>
|
||||
<RESFILES value=""/>
|
||||
<IDLFILES value=""/>
|
||||
<IDLGENFILES value=""/>
|
||||
<DEFFILE value=""/>
|
||||
<RESDEPEN value="$(RESFILES)"/>
|
||||
<LIBFILES value=""/>
|
||||
<LIBRARIES value="VCL50.lib"/>
|
||||
<SPARELIBS value="VCL50.lib"/>
|
||||
<PACKAGES value="rtl.bpi vcl.bpi vclx.bpi bcbsmp.bpi dbrtl.bpi vcldb.bpi adortl.bpi
|
||||
ibsmp.bpi bdertl.bpi vcldbx.bpi qrpt.bpi teeui.bpi teedb.bpi tee.bpi
|
||||
dss.bpi teeqr.bpi ibxpress.bpi dsnap.bpi vclie.bpi inetdb.bpi inet.bpi
|
||||
nmfast.bpi webdsnap.bpi bcbie.bpi dclocx.bpi bcb2kaxserver.bpi asgc5.bpi
|
||||
CabForCB.bpi CoolPack.bpi JDsoft.bpi PhantomPack.bpi RAS_Tools.bpi
|
||||
LM2000_vcl.bpi"/>
|
||||
<PATHCPP value=".;"/>
|
||||
<PATHPAS value=".;"/>
|
||||
<PATHRC value=".;"/>
|
||||
<PATHASM value=".;"/>
|
||||
<DEBUGLIBPATH value="$(BCB)\lib\debug"/>
|
||||
<RELEASELIBPATH value="$(BCB)\lib\release"/>
|
||||
<LINKER value="ilink32"/>
|
||||
<USERDEFINES value="_DEBUG"/>
|
||||
<SYSDEFINES value="NO_STRICT;_NO_VCL;USEPACKAGES"/>
|
||||
<MAINSOURCE value="CardWriter.bpf"/>
|
||||
<INCLUDEPATH value="..\checksum_gen;..\;$(BCB)\include;$(BCB)\include\vcl;..\..\VCLs\lib;..\LM2000_vcl"/>
|
||||
<LIBPATH value="..\..\..\VCLs\lib;"C:\Archivos de programa\Borland\CBuilder6\Lib\Debug";..\checksum_gen;$(BCB)\Projects\Lib;..\;..\..\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib;..\LM2000_vcl"/>
|
||||
<WARNINGS value="-w-par"/>
|
||||
<OTHERFILES value=""/>
|
||||
</MACROS>
|
||||
<OPTIONS>
|
||||
<IDLCFLAGS value="-I..\checksum_gen -I..\. -I$(BCB)\include -I$(BCB)\include\vcl
|
||||
-I..\..\VCLs\lib -I..\LM2000_vcl -src_suffix cpp -D_DEBUG -boa"/>
|
||||
<CFLAG1 value="-Od -H=c:\ARCHIV~1\BORLAND\CBUILD~2\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8
|
||||
-b- -k -y -v -vi- -tWC -tWM -c"/>
|
||||
<PFLAGS value="-$YD -$W -$O- -$A8 -v -JPHNE -M"/>
|
||||
<RFLAGS value=""/>
|
||||
<AFLAGS value="/mx /w2 /zd"/>
|
||||
<LFLAGS value="-D"" -ap -Tpe -x -Gn -v"/>
|
||||
<OTHERFILES value=""/>
|
||||
</OPTIONS>
|
||||
<LINKER>
|
||||
<ALLOBJ value="c0x32.obj $(PACKAGES) $(OBJFILES)"/>
|
||||
<ALLRES value="$(RESFILES)"/>
|
||||
<ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cw32mt.lib"/>
|
||||
<OTHERFILES value=""/>
|
||||
</LINKER>
|
||||
<FILELIST>
|
||||
<FILE FILENAME="CardWriter.bpf" FORMNAME="" UNITNAME="CardWriter" CONTAINERID="BPF" DESIGNCLASS="" LOCALCOMMAND=""/>
|
||||
<FILE FILENAME="ZT2000.cpp" FORMNAME="" UNITNAME="ZT2000" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
|
||||
</FILELIST>
|
||||
<BUILDTOOLS>
|
||||
</BUILDTOOLS>
|
||||
|
||||
<IDEOPTIONS>
|
||||
[Version Info]
|
||||
IncludeVerInfo=0
|
||||
AutoIncBuild=0
|
||||
MajorVer=1
|
||||
MinorVer=0
|
||||
Release=0
|
||||
Build=0
|
||||
Debug=0
|
||||
PreRelease=0
|
||||
Special=0
|
||||
Private=0
|
||||
DLL=0
|
||||
Locale=3082
|
||||
CodePage=1252
|
||||
|
||||
[Version Info Keys]
|
||||
CompanyName=
|
||||
FileDescription=
|
||||
FileVersion=1.0.0.0
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=1.0.0.0
|
||||
Comments=
|
||||
|
||||
[HistoryLists\hlIncludePath]
|
||||
Count=4
|
||||
Item0=$(BCB)\include;$(BCB)\include\vcl;..\..\VCLs\lib;C:\Mis documentos\Fuentes de Programacion\C++ Builder\CAP\LM2000_vcl
|
||||
Item1=$(BCB)\include;$(BCB)\include\vcl;..\..\VCLs\lib
|
||||
Item2=$(BCB)\include;$(BCB)\include\vcl;C:\Mis documentos\Fuentes de Programacion\C++ Builder\VCLs\lib
|
||||
Item3=$(BCB)\include;$(BCB)\include\vcl
|
||||
|
||||
[HistoryLists\hlLibraryPath]
|
||||
Count=3
|
||||
Item0=..\..\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib;C:\Mis documentos\Fuentes de Programacion\C++ Builder\CAP\LM2000_vcl
|
||||
Item1=..\..\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib
|
||||
Item2=..\..\VCLs\lib;$(BCB)\lib\obj;$(BCB)\lib;C:\Mis documentos\Fuentes de Programacion\C++ Builder\VCLs\lib
|
||||
|
||||
[HistoryLists\hlDebugSourcePath]
|
||||
Count=1
|
||||
Item0=$(BCB)\source\vcl
|
||||
|
||||
[HistoryLists\hlConditionals]
|
||||
Count=1
|
||||
Item0=_DEBUG
|
||||
|
||||
[Debugging]
|
||||
DebugSourceDirs=$(BCB)\source\vcl
|
||||
|
||||
[Parameters]
|
||||
RunParams=
|
||||
Launcher=
|
||||
UseLauncher=0
|
||||
DebugCWD=
|
||||
HostApplication=
|
||||
RemoteHost=
|
||||
RemotePath=
|
||||
RemoteLauncher=
|
||||
RemoteCWD=
|
||||
RemoteDebug=0
|
||||
|
||||
[Compiler]
|
||||
ShowInfoMsgs=0
|
||||
LinkDebugVcl=0
|
||||
LinkCGLIB=0
|
||||
|
||||
[CORBA]
|
||||
AddServerUnit=1
|
||||
AddClientUnit=1
|
||||
PrecompiledHeaders=1
|
||||
|
||||
[Language]
|
||||
ActiveLang=
|
||||
ProjectLang=
|
||||
RootDir=
|
||||
</IDEOPTIONS>
|
||||
</PROJECT>
|
BIN
ZT-2000/CardWriter.exe
Normal file
BIN
ZT-2000/CardWriter.exe
Normal file
Binary file not shown.
359
ZT-2000/ZT2000.cpp
Normal file
359
ZT-2000/ZT2000.cpp
Normal file
@ -0,0 +1,359 @@
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#pragma hdrstop
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#pragma argsused
|
||||
#include "stdio.h"
|
||||
//#include "cstring.h"
|
||||
#include "stdlib.h"
|
||||
#include "conio.h"
|
||||
#include "windows.h"
|
||||
|
||||
#define _verbose ACTIVA_EXPLICACION_PROCESOS
|
||||
|
||||
HANDLE LM_handle;
|
||||
bool LM_opened = false;
|
||||
|
||||
int AbrePuerto(LPTSTR lpszPortName)
|
||||
{
|
||||
DWORD dwError;
|
||||
DCB PortDCB;
|
||||
COMMTIMEOUTS CommTimeouts;
|
||||
|
||||
if ( LM_opened ) return true;
|
||||
|
||||
LM_opened = false;
|
||||
|
||||
// Open the serial port.
|
||||
LM_handle = CreateFile (lpszPortName, // Pointer to the name of the port
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
// Access (read/write) mode
|
||||
0, // Share mode
|
||||
NULL, // Pointer to the security attribute
|
||||
OPEN_EXISTING,// How to open the serial port
|
||||
0, // Port attributes
|
||||
NULL); // Handle to port with attribute
|
||||
// to copy
|
||||
|
||||
// If it fails to open the port, return FALSE.
|
||||
if ( LM_handle == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
dwError = GetLastError ();
|
||||
return false;
|
||||
} else {
|
||||
LM_opened = true;
|
||||
}
|
||||
|
||||
PortDCB.DCBlength = sizeof (DCB);
|
||||
|
||||
// Get the default port setting information.
|
||||
GetCommState (LM_handle, &PortDCB);
|
||||
|
||||
// Change the DCB structure settings.
|
||||
PortDCB.BaudRate = 9600; // Current baud
|
||||
PortDCB.fBinary = TRUE; // Binary mode; no EOF check
|
||||
PortDCB.fParity = TRUE; // Enable parity checking.
|
||||
PortDCB.fOutxCtsFlow = FALSE; // No CTS output flow control
|
||||
PortDCB.fOutxDsrFlow = FALSE; // No DSR output flow control
|
||||
PortDCB.fDtrControl = DTR_CONTROL_ENABLE;
|
||||
// DTR flow control type
|
||||
PortDCB.fDsrSensitivity = FALSE; // DSR sensitivity
|
||||
PortDCB.fTXContinueOnXoff = TRUE; // XOFF continues Tx
|
||||
PortDCB.fOutX = FALSE; // No XON/XOFF out flow control
|
||||
PortDCB.fInX = FALSE; // No XON/XOFF in flow control
|
||||
PortDCB.fErrorChar = FALSE; // Disable error replacement.
|
||||
PortDCB.fNull = FALSE; // Disable null stripping.
|
||||
PortDCB.fRtsControl = RTS_CONTROL_ENABLE;
|
||||
// RTS flow control
|
||||
PortDCB.fAbortOnError = FALSE; // Do not abort reads/writes on
|
||||
// error.
|
||||
PortDCB.ByteSize = 7; // Number of bits/bytes, 4-8
|
||||
/*
|
||||
PortDCB.ByteSize = 8; // Number of bits/bytes, 4-8
|
||||
*/
|
||||
PortDCB.Parity = EVENPARITY; // 0-4=no,odd,even,mark,space
|
||||
PortDCB.StopBits = 0; // 0,1,2 = 1, 1.5, 2
|
||||
|
||||
// Configure the port according to the specifications of the DCB
|
||||
// structure.
|
||||
if (!SetCommState (LM_handle, &PortDCB))
|
||||
{
|
||||
// Could not configure the serial port.
|
||||
printf( "Unable to configure the serial port\n%s\n" );
|
||||
dwError = GetLastError ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// Retrieve the time-out parameters for all read and write operations
|
||||
// on the port.
|
||||
GetCommTimeouts (LM_handle, &CommTimeouts);
|
||||
|
||||
// Change the COMMTIMEOUTS structure settings.
|
||||
CommTimeouts.ReadIntervalTimeout = MAXDWORD;
|
||||
|
||||
// CommTimeouts.ReadTotalTimeoutMultiplier = 0;
|
||||
CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
|
||||
|
||||
CommTimeouts.ReadTotalTimeoutConstant = 1000;
|
||||
CommTimeouts.WriteTotalTimeoutMultiplier = 10;
|
||||
CommTimeouts.WriteTotalTimeoutConstant = 1000;
|
||||
|
||||
// Set the time-out parameters for all read and write operations
|
||||
// on the port.
|
||||
if (!SetCommTimeouts (LM_handle, &CommTimeouts))
|
||||
{
|
||||
// Could not set the time-out parameters.
|
||||
printf( "Unable to set the time-out parameters" );
|
||||
dwError = GetLastError ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Direct the port to perform extended functions SETDTR and SETRTS.
|
||||
// SETDTR: Sends the DTR (data-terminal-ready) signal.
|
||||
// SETRTS: Sends the RTS (request-to-send) signal.
|
||||
EscapeCommFunction (LM_handle, SETDTR);
|
||||
EscapeCommFunction (LM_handle, SETRTS);
|
||||
|
||||
return LM_opened;
|
||||
};
|
||||
|
||||
void CierraPuerto(void)
|
||||
{
|
||||
if ( LM_opened )
|
||||
{
|
||||
CloseHandle( LM_handle );
|
||||
}
|
||||
};
|
||||
|
||||
// ObtenerRespuesta
|
||||
// Lee del puerto los datos pendientes del buffer
|
||||
// (solo lee lo que expulse el LM)
|
||||
//
|
||||
//
|
||||
char *ObtenerRespuesta( char *rcv )
|
||||
{
|
||||
bool waitingResp = true;
|
||||
DWORD CHK, chkF = 0;
|
||||
int i = 0;
|
||||
DWORD dwCommModemStatus;
|
||||
|
||||
if ( LM_opened )
|
||||
{
|
||||
/*
|
||||
// Specify a set of events to be monitored for the port.
|
||||
SetCommMask (LM_handle, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING);
|
||||
// Wait for an event to occur for the port.
|
||||
WaitCommEvent (LM_handle, &dwCommModemStatus, 0);
|
||||
// Re-specify the set of events to be monitored for the port.
|
||||
SetCommMask (LM_handle, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING);
|
||||
*/
|
||||
// Recogemos la respuesta del lector
|
||||
while( i < 75 )
|
||||
{
|
||||
ReadFile( LM_handle, &(rcv[i]), 1, &CHK, NULL );
|
||||
if ( CHK == 1 )
|
||||
{
|
||||
if ( waitingResp )
|
||||
{
|
||||
if ( rcv[i] != 0x06) waitingResp = false;
|
||||
// ACK
|
||||
// printf( "Esperando a la tarjeta\n" );
|
||||
}
|
||||
|
||||
if ( rcv[i] == 13 ) break; else {
|
||||
if ( !waitingResp || i==0 ) i++;
|
||||
}
|
||||
} else
|
||||
if ( CHK == 0 )
|
||||
{
|
||||
chkF++;
|
||||
if ( chkF == 20 )
|
||||
{
|
||||
sprintf( rcv, "ERROR: Respuesta fuera de tiempo" );
|
||||
return rcv;
|
||||
}
|
||||
}
|
||||
}
|
||||
rcv[i+1] = '\0';
|
||||
|
||||
} else {
|
||||
sprintf( rcv, "ERROR: LM no abierto" );
|
||||
}
|
||||
|
||||
#ifdef _verbose
|
||||
printf( "Recibido: %s\n", rcv );
|
||||
#endif
|
||||
|
||||
return rcv;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// EnviarComando
|
||||
// Envia el comando CMD al lector ID, devolviendo la respuesta 'rcv'
|
||||
//
|
||||
//
|
||||
//
|
||||
char *EnviaCMD1( char *CMD, char *rcv, char mlen )
|
||||
{
|
||||
DWORD CHK;
|
||||
if ( LM_opened )
|
||||
{
|
||||
|
||||
#ifdef _verbose
|
||||
printf( "Enviado: %s\n", CMD );
|
||||
#endif
|
||||
WriteFile( LM_handle, CMD, strlen(CMD)+mlen, &CHK, NULL );
|
||||
|
||||
ObtenerRespuesta( rcv );
|
||||
} else
|
||||
sprintf( rcv, "ERROR: LM no abierto" );
|
||||
|
||||
return rcv;
|
||||
}
|
||||
char *EnviaCMD( char *CMD, char *rcv )
|
||||
{
|
||||
EnviaCMD1( CMD, rcv, 0 );
|
||||
return rcv;
|
||||
}
|
||||
|
||||
#define ZT_ClearCommand "/CL0/"
|
||||
// #define ZT_ReadCommand "/RD3/"
|
||||
#define ZT_ReadCommand "/RD1/"
|
||||
#define ZT_WriteCommand "/WR1/"
|
||||
#define ACK 0x06
|
||||
#define STX 0x02
|
||||
#define NAK 0x15
|
||||
#define ETX 0x03
|
||||
#define EOT 0x04
|
||||
#define CR 0x0D
|
||||
|
||||
|
||||
char CalculaBCC( char *cadena )
|
||||
{
|
||||
int i, dev=0;
|
||||
for ( i=0; cadena[i] != ETX; i++ )
|
||||
{
|
||||
dev ^= cadena[i];
|
||||
}
|
||||
dev ^= cadena[i];
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
||||
char *LeeTarjeta( char *rcv )
|
||||
{
|
||||
// Leemos una tarjeta
|
||||
char buff[3];
|
||||
EnviaCMD( ZT_ReadCommand, rcv );
|
||||
if ( rcv[0] == ACK && rcv[1] == 0x0D )
|
||||
{
|
||||
// Ahora si se ha recibido <ACK><CR> Leemos la tarjeta que pasemos
|
||||
ObtenerRespuesta( rcv );
|
||||
// Vemos si es la tarjeta o un error
|
||||
if ( rcv[0] == STX && rcv[1] == '/' && rcv[2] == 'E' && rcv[3] == 'R' )
|
||||
{
|
||||
//es un error
|
||||
#ifdef _verbose
|
||||
printf( "Error: %d", rcv[1] );
|
||||
#endif
|
||||
} else {
|
||||
char len = 0;
|
||||
while( rcv[len]!=CR )len++;
|
||||
|
||||
char BCC = CalculaBCC( &rcv[1] ),
|
||||
BCCr = rcv[ len-1 ];
|
||||
if ( BCC != BCCr )
|
||||
{
|
||||
printf( "Error: BCC recibido es incorrecto BCC(%x) != R(%x)\n", BCC, BCCr );
|
||||
}
|
||||
}
|
||||
buff[0] = ACK; buff[1] = '\0';
|
||||
EnviaCMD( buff, rcv );
|
||||
} else {
|
||||
sprintf( rcv, "ERROR: Commando no aceptado\n");
|
||||
}
|
||||
return rcv;
|
||||
}
|
||||
|
||||
char *EscribeTarjeta( char *datos, char *rcv )
|
||||
{
|
||||
// Leemos una tarjeta
|
||||
char env[140], buff[140], BCC;
|
||||
EnviaCMD( ZT_WriteCommand, rcv );
|
||||
if ( rcv[0] == ACK && rcv[1] == CR )
|
||||
{
|
||||
sprintf( env, "%s%c", datos, ETX );
|
||||
BCC = CalculaBCC( env );
|
||||
sprintf( buff, "%c%s%c", STX, env, BCC );
|
||||
if ( BCC )
|
||||
EnviaCMD( buff, rcv );
|
||||
else
|
||||
EnviaCMD1( buff, rcv, 1 );
|
||||
|
||||
if ( rcv[0] == ACK && rcv[1] == CR )
|
||||
{
|
||||
// Ahora si se ha recibido <ACK><CR> Leemos la tarjeta que pasemos
|
||||
ObtenerRespuesta( rcv );
|
||||
// Vemos si es la tarjeta o un error
|
||||
if ( !(rcv[0] == EOT && rcv[1] == CR) )
|
||||
{
|
||||
//es un error
|
||||
sprintf( rcv, "Error: %s\n", rcv );
|
||||
#ifdef _verbose
|
||||
printf( "Error: %s\n", rcv );
|
||||
#endif
|
||||
}
|
||||
buff[0] = ACK; buff[1] = CR; buff[2] = '\0';
|
||||
EnviaCMD( buff, rcv );
|
||||
} else {
|
||||
sprintf( rcv, "ERROR: No se recibio respuesta despues de los datos\n" );
|
||||
}
|
||||
} else {
|
||||
sprintf( rcv, "ERROR: Commando no aceptado\n");
|
||||
}
|
||||
return rcv;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
printf("Pruebas con LM2000 JD soft (c)\n");
|
||||
printf("------------------\n");
|
||||
|
||||
AbrePuerto("COM1:");
|
||||
|
||||
char rcv[80];
|
||||
|
||||
// Inicializamos el ZT-2300
|
||||
EnviaCMD( ZT_ClearCommand, rcv );
|
||||
if ( rcv[0] == 'E' )
|
||||
{
|
||||
printf( "\nError durante la comunicaci<63>n" );
|
||||
} else {
|
||||
/*
|
||||
do{
|
||||
LeeTarjeta( rcv );
|
||||
} while ( getch() != 13 );
|
||||
*/
|
||||
LeeTarjeta( rcv );
|
||||
printf("\n\n\n%s\n\n", rcv );
|
||||
// EscribeTarjeta( "123456789123465789765132156484513216", rcv );
|
||||
}
|
||||
printf( "\n\n FIN DEL PROGRAMA \n\n" );
|
||||
getch();
|
||||
|
||||
CierraPuerto();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user