002
05.10.2004, 15:35 Uhr
~Archie
Gast
|
C++: |
void CLesen::OnLesen() { DCB PortConfig; HANDLE hCom; hCom = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(GetCommState(hCom,&PortConfig) == 0) { //hier fehlerbehandlung MessageBox("1.Senden nicht möglich!"); return; } PortConfig.BaudRate = CBR_9600; PortConfig.StopBits = ONESTOPBIT; PortConfig.Parity = NOPARITY; PortConfig.ByteSize = 8; if(SetCommState(hCom,&PortConfig) == 0) { //hier error; MessageBox("2.Senden nicht möglich!"); }
//SENDEN unsigned long length1 = 0; CString sEoT = 0x03; CString sROSaus = "600301000062"; WriteFile(hCom, sROSaus, sROSaus.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(250); CString sPUp = "6002121363"; WriteFile(hCom, sPUp, sPUp.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); char Antwort1[15]; ReadFile(hCom, Antwort1, sizeof(Antwort1), &length1, NULL); if(Antwort1[13]=='F') { if(Antwort1[14]=='B') { MessageBox("Keine Karte im Leser."); CloseHandle(hCom); OnClose(); } } else { Sleep(1000); //SELECT GSM CString sSelectGSM = "600814A0A40000027F2025"; WriteFile(hCom, sSelectGSM, sSelectGSM.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); int i; //PIN ABFRAGE********************************* if (m_dPin1.DoModal() == IDOK) { CString PinEingabe; CString test1 = ""; CString XOR = "F"; CString XOR1; CString PinSenden = "600E14A020000108"; CString drei = "3"; PinEingabe = m_dPin1.m_PinCode; if(PinEingabe.GetLength()==4) { for (i=0; i<=3; i++) { test1 = test1 + drei; test1 = test1 + PinEingabe[i]; } //XOR BERECHNEN************************************** int m_sXOR1 = 3; for(i=0; i<=(PinEingabe.GetLength()-1); i++) { m_sXOR1 = m_sXOR1 ^ (PinEingabe[i]-48); } XOR1.Format(_T("%X"), m_sXOR1); WriteFile(hCom, PinSenden, PinSenden.GetLength(), &length1, NULL); WriteFile(hCom, test1, test1.GetLength(), &length1, NULL); CString Fs4 = "FFFFFFFF"; WriteFile(hCom, Fs4, Fs4.GetLength(), &length1, NULL); } else { int i; for(i=0; i<=(PinEingabe.GetLength()-1); i++) { test1 = test1 + drei; test1 = test1 + PinEingabe[i]; } //XOR BERECHNEN************************************** int m_sXOR1 = 3; for(i=0; i<=(PinEingabe.GetLength()-1); i++) { m_sXOR1 = m_sXOR1 ^ (PinEingabe[i]-48); } XOR1.Format(_T("%X"), m_sXOR1); WriteFile(hCom, PinSenden, PinSenden.GetLength(), &length1, NULL); WriteFile(hCom, test1, test1.GetLength(), &length1, NULL); CString Fs6 = "FFFFFF"; WriteFile(hCom, Fs6, Fs6.GetLength(), &length1, NULL); } WriteFile(hCom, XOR, XOR.GetLength(), &length1, NULL); WriteFile(hCom, XOR1, XOR1.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); //PIN RESPONSE********************************************** char Antwort1[10]; ReadFile(hCom, Antwort1, sizeof(Antwort1), &length1, NULL); } Sleep(300); COMSTAT stat; DWORD dwErrors; if(!ClearCommError(hCom, &dwErrors, &stat)) { TRACE(_T("Hallo Döner")); // AfxThrowSerialException(); }
DWORD dwLength = 0; DWORD dwWaitingBytes = stat.cbInQue;
CString strRead; strRead.GetBufferSetLength(dwWaitingBytes); ReadFile(hCom, strRead.GetBuffer(6), dwWaitingBytes, &dwLength, NULL); strRead.ReleaseBuffer(dwWaitingBytes); //SELECT LOCI****************************************** CString sSelectLoci = "600814A0A40000026F7E6B"; WriteFile(hCom, sSelectLoci, sSelectLoci.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); //READ LOCI CString sReadLOCI= "600613A0B000000B6E"; WriteFile(hCom, sReadLOCI, sReadLOCI.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); //clear(buffer); m_sLOCI =""; char AntwortLOCI[46]; ReadFile(hCom, AntwortLOCI, sizeof(AntwortLOCI), &length1, NULL); for(i=19; i<=40; i++) { m_sLOCI += AntwortLOCI[i]; } UpdateData(FALSE); Sleep(200); //SELECT Kc************************************* CString sSelectKc = "600814A0A40000026F2035"; WriteFile(hCom, sSelectKc, sSelectKc.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); //READ Kc CString sReadKC= "600613A0B00000096C"; WriteFile(hCom, sReadKC, sReadKC.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); m_sKC =""; char AntwortKC[42]; ReadFile(hCom, AntwortKC, sizeof(AntwortKC), &length1, NULL); for(i=21; i<=38; i++) { m_sKC += AntwortKC[i]; } UpdateData(FALSE); Sleep(200); //SELECT BCCH******************************** CString sSelectBCCH = "600814A0A40000026F7461"; WriteFile(hCom, sSelectBCCH, sSelectBCCH.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); //READ BCCH CString sReadBCCH = "600613A0B000001075"; WriteFile(hCom, sReadBCCH, sReadBCCH.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); m_sBCCH =""; char AntwortBCCH[55]; ReadFile(hCom, AntwortBCCH, sizeof(AntwortBCCH), &length1, NULL); for(i=23; i<=54; i++) { m_sBCCH += AntwortBCCH[i]; } UpdateData(FALSE); Sleep(200); //SELECT Forbidden PLMN************************* CString sSelectFPLMN = "600814A0A40000026F7B6E"; WriteFile(hCom, sSelectFPLMN, sSelectFPLMN.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); //READ Forbdden PLMN CString sReadFPLMN = "600613A0B000000C69"; WriteFile(hCom, sReadFPLMN , sReadFPLMN.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); Sleep(200); m_sFPLMN =""; char AntwortFPLMN[50]; ReadFile(hCom, AntwortFPLMN, sizeof(AntwortFPLMN), &length1, NULL); for(i=26; i<=49; i++) { m_sFPLMN += AntwortFPLMN[i]; } UpdateData(FALSE); //POWER OFF Sleep(200); CString PowerDown = "60011170"; WriteFile(hCom, PowerDown, PowerDown.GetLength(), &length1, NULL); WriteFile(hCom, sEoT, sEoT.GetLength(), &length1, NULL); CloseHandle(hCom); } }
|
|