#include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { /////////////////////////////////////////////////////////////////////////// //Lecture du fichier texte et enregistrement dans une chaine de caractere// /////////////////////////////////////////////////////////////////////////// string koordinaten_zero = "0" ; char a; // Une variable pour stocker les lignes lues. string koordinaten_Daten ; ifstream file; // Un flux entrant sans fichier associe en mode lecture file.open("koordinaten.txt"); // Ouverture du fichier if(file) { // LŽouverture sŽest bien passee. On peut donc lire while(file) // Tant quŽon nŽest pas a la fin, on lit { a = file.get(); // cout << a ; // affichage dans la console koordinaten_Daten.push_back(a); // Ajout de cases supplementaires a la fin du tableau // cout << koordinaten_Daten << endl ; } file.close(); } else { cout << "Erreur: Impossible dŽouvrir le fichier en mode lecture" << endl; } ///////////////////////////////////////////////////////////////////////// ////////////////////// Traitement du fichier texte ////////////////////// ///////////////////////////////////////////////////////////////////////// int i = 0 ; while( i < koordinaten_Daten.size()) // Tant que i est inferieur au nombre dŽelement du tableau { // cout << koordinaten_Daten.size() << endl ; // Affichage du nombre dŽelements du tableau if(koordinaten_Daten[i]=='X' && koordinaten_Daten[i+5]=='Y' ) { koordinaten_Daten.insert(i+1, koordinaten_zero); } if(koordinaten_Daten[i]=='Y' && koordinaten_Daten[i+5]=='\n' ) { koordinaten_Daten.insert(i+1, koordinaten_zero); } i++; } // cout << koordinaten_Daten ; ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// int k = 0, l_x = 0, l_y = 0; float f_x_pos , f_y_pos ; float f_x = 0, f_y = 0; char x_pos[10] = " "; // position suivant lŽaxe X char y_pos[10] = " "; // position suivant lŽaxe Y unsigned int pasdemoteur_x [500]; unsigned int pasdemoteur_y [500]; char All_Ascii_Pos_x[1000]; char All_Ascii_Pos_y[1000]; while(k < koordinaten_Daten.length()) { // cout << koordinaten_Daten.length() << endl ; if(koordinaten_Daten[k] == 'X') { for(int j_x=0; j_x<5; j_x++) { x_pos[j_x] = koordinaten_Daten[k+j_x+1]; } f_x_pos = atof (x_pos); // Conversion de ascii en nombre flottant // cout << f_x_pos << endl ; f_x = ((f_x_pos*25.4)/10000)*100; // // conversion de la position en pas // cout << f_x << endl ; pasdemoteur_x[l_x] = (int)f_x; // cout << pasdemoteur_x << endl; l_x++; } if(koordinaten_Daten[k] == 'Y') { for(int j_y=0; j_y<5; j_y++) { y_pos[j_y] = koordinaten_Daten[k+j_y+1]; } f_y_pos = atof (y_pos); // Conversion ascii en nombre flottant float // cout << f_y_pos << endl ; f_y = ((f_y_pos*25.4)/10000)*100; // conversion de la position en pas // cout << f_y << endl ; pasdemoteur_y[l_y] = (int)f_y; // cout << pasdemoteur_y << endl; l_y++; } k++ ; } ///////////////////////////////////////////////////////////////////// /////// Transformation des positions X de int en char //////////////////// ///////////////////////////////////////////////////////////////////// int i_x=0, j_x=0, i_help_x = 0, x1 = 1000 ; char x[x1] ; while(i_x<=l_x) { itoa(pasdemoteur_x[i_x],x,10); // cout << x << endl ; i_x++; i_help_x += 1 ; // compteur } ///////////////////////////////////////////////////////////////////// /////// Transformation Y-position de int en char //////////////////// ///////////////////////////////////////////////////////////////////// int i_y=0, j_y=0, i_help_y = 0, y1 = 1000 ; char y[y1] ; while(i_y<=l_y) { itoa(pasdemoteur_y[i_y],y,10); // cout << y << endl ; i_y++; i_help_y += 1 ; // compteur } ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Sleep (3000) ; // pause char * temp_x, *temp_y ; temp_x = x ; temp_y = y ; // cout << temp_x << endl ; // cout << temp_y << endl ; ///////////////////////////////////////////////////////////////// //Transmission des positions X et Y vers le port seriel RS232//// ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// ////Initialisation ou configuration du port seriel ///////////// ///////////////////////////////////////////////////////////////// HANDLE h = CreateFile("COM1", // specification du port GENERIC_READ | GENERIC_WRITE, // lecture, écriture ou les deux 0, // the devide isn't shared. NULL, // no security attributes OPEN_EXISTING, // // comm devices must use OPEN_EXISTING FILE_ATTRIBUTE_NORMAL, 0); // not overlapped I/O DWORD written = 0; DCB dcb = { 0 }; BOOL dcbOk = GetCommState(h, &dcb); ////////////////////////////////////////////////////////////////// ////////// Reglage du Baudrate, de la taille du byte,///////////// //////////du bit de parite, du stopbit//////////////////////////// ////////////////////////////////////////////////////////////////// dcb.BaudRate = CBR_115200; // Specify buad rate of communicaiton. dcb.ByteSize = 8; // Specify byte of size of communication. dcb.Parity = NOPARITY; // Specify parity of communication. dcb.StopBits = TWOSTOPBITS; // Two stop bit dcb.fOutxCtsFlow = false; dcbOk = SetCommState(h, &dcb); DWORD dwModemStatus; BOOL fCTS;// fDSR, fRING, fRLSD; int k1 = 0 ; int control=0 ; while(k1<(i_help_x)) { GetCommModemStatus(h, &dwModemStatus); fCTS = MS_CTS_ON & dwModemStatus; if (fCTS) { if( control == 0 ) { // Transmission des coordonnees X // WriteFile(h, // handle to file to write to temp_x, // pointer to data to write to file 1, // number of bytes to write &written, // pointer of number of bytes written 0); cout << "Envoi des coordonnees X" << temp_x << endl; temp_x++; // Sleep(200); } else { // Transmission des coordonnees Y // WriteFile(h, // handle to file to write to temp_y, // pointer to data to write to file 1, // number of bytes to write &written, // pointer of number of bytes written 0); cout << " Envoi des coordonnees Y" << temp_y << endl; temp_y++; // Sleep(200); } } } CloseHandle(h); system ("pause"); return 0; }