Knowledge Base Nr: 00148 euchner.cpp - http://www.swe-kaiser.de

Downloads:

Win32: Electronic Key System (Transponder) Chipdaten auslesen
www.euchner.de

  
void GetData3964() //3964
{
char szEntry[40] = {0};

BOOL bSucc = Open3964REx(g_nPortNo, 9600, 1000, 'E');
if (!bSucc)
{
g_nErr = 1;
sprintf(g_szError, "ERROR: COM%d nicht verfügbar!", g_nPortNo+1);

strcpy(g_szUser, "ERROR!");
strcpy(g_szPWD, "ERROR!");
return;
}

unsigned char pBuffer[40] = {0};
int nTeleLen = 0;
pBuffer[nTeleLen++] = 7;
pBuffer[nTeleLen++] = 'T';
pBuffer[nTeleLen++] = 'L';
pBuffer[nTeleLen++] = 1;
pBuffer[nTeleLen++] = 0;
pBuffer[nTeleLen++] = 0;
pBuffer[nTeleLen++] = 0x20;
pBuffer[nTeleLen++] = 0x10;
pBuffer[nTeleLen++] = 0x10;
pBuffer[nTeleLen++] = 3;
pBuffer[nTeleLen++] = 0x0d;
bSucc = Tx3964R(g_nPortNo, pBuffer, nTeleLen, FALSE);
if (!bSucc)
{
g_nErr = 2;
sprintf(g_szError, "ERROR: Senden Tx3964R() fehlgeschlagen!");
strcpy(g_szUser, "ERROR!");
strcpy(g_szPWD, "ERROR!");
return;
}

Sleep(500);
nTeleLen = Rx3964R(g_nPortNo, pBuffer, sizeof(pBuffer), FALSE);
if (nTeleLen <= 0)
{
g_nErr = 3;
sprintf(g_szError, "ERROR: Lesen Rx3964R() fehlgeschlagen: %d!", nTeleLen);
strcpy(g_szUser, "ERROR!");
strcpy(g_szPWD, "ERROR!");
return;
}

char szData[100] = {0};
if ((pBuffer[1] == 'R') && (pBuffer[2] == 'L'))
{
const int DATAOFFSET = 7;

char* p = strstr((char*)&pBuffer[DATAOFFSET], DELIMITER);
if (!p)
{
g_nErr = 4;
sprintf(g_szError, "ERROR: kein '" DELIMITER "'-Trenner!");
strcpy(g_szUser, "ERROR!");
strcpy(g_szPWD, "ERROR!");
}
else
{
*p = 0;
strcpy(g_szUser, (char*)&pBuffer[DATAOFFSET]);
strcpy(g_szPWD, p+1);

g_nErr = 0;
sprintf(g_szError, "OK!");
}
}
else
{
g_nErr = 5;
sprintf(g_szError, "ERROR: Gerät sendet Fehler oder kein Chip <%s>!", pBuffer);
strcpy(g_szUser, "ERROR!");
strcpy(g_szPWD, "ERROR!");
}

bSucc = Close3964R(g_nPortNo);
}