CFile liefert Fehler



  • hi,

    benutz zum auslesen lieber CStdioFile



  • Grund?



  • UpdateDate ist da, CStdioFile geht nicht, da mein array zum speichern unsigned char ist und nicht char



  • Zeig mal etwas mehr Code.



  • void CI2c_porgDlg::OnWrite() 
    {
    	CComboBox * pCB1 = (CComboBox *) GetDlgItem ( IDC_COM ) ; 
    	int com_no = pCB1 -> GetCurSel () ;
    	CComboBox * pCB2 = (CComboBox *) GetDlgItem ( IDC_ADR ) ; 
    	int i2c_adr = pCB2 -> GetCurSel () ;
    	if ( com_no >= 0 && i2c_adr >= 0)		// nur dann wurde etwas aus der Liste angeklickt
    	{
    		pCB1 -> GetLBText( com_no , iCOM ) ;
    		pCB2 -> GetLBText( i2c_adr, iADR ) ;
    		CFileDialog wr ( 1,". bin", "default", 0, "Bin-Dateien(*.bin)|*.bin||" ) ;
    		if (wr.DoModal() == IDOK)
    		{
    			if (iADR == "0") rADR = '0';
    			if (iADR == "1") rADR = '1';
    			if (iADR == "2") rADR = '2';
    			if (iADR == "3") rADR = '3';
    			if (iADR == "4") rADR = '4';
    			if (iADR == "5") rADR = '5';
    			if (iADR == "6") rADR = '6';
    			if (iADR == "7") rADR = '7';
    			WPI2C[9] = rADR;
    			if (iCOM == "COM1") cport = 1;
    			if (iCOM == "COM2") cport = 2;
    			CString m_sPath = wr.GetPathName( );
    			CFile databin;
    		    CSerial serial;
    			if (serial.Open(cport, 38400))
    			{
    				str_ptr = &CWP[0];	
    				while (*str_ptr)
    						{
    						serial.WriteCommByte(*str_ptr);
    						str_ptr++;
    						_sleep(100);			
    						}
    					WPI2C[11] = '0';
    					adr = 0;
    					UpdateData(TRUE); 
    					databin.Open(m_sPath, CFile::modeCreate|CFile::modeWrite);
    					databin.Read (data_to_send,256);
    					AfxMessageBox("OK 4");
    					for(adr=0;adr<256;adr+=64)
    					{
    
    						if(adr==0) WPI2C[11] = '0';
    						if(adr==64) WPI2C[11] = '4';
    						if(adr==128) WPI2C[11] = '8';
    						if(adr==192) WPI2C[11] = 'C';
    						str_ptr = &WPI2C[0];
    						str_ptr2 = &data_to_send[0];
    						while (*str_ptr)
    							{
    							serial.WriteCommByte(*str_ptr);
    							str_ptr++;
    							_sleep(100);
    
    							for(i=adr;i<adr+64;i++)
    							{
    								serial.WriteCommByte(*str_ptr2);
    								str_ptr2++;
    								_sleep(100);
    							}
    							}
    					}
    
    			}
    			else AfxMessageBox("Failed to open port!\nPlease check if it is used by another programm!",MB_OK | MB_ICONINFORMATION);
    		}
    	}
    	else AfxMessageBox ("Please check your selection for COM-port and i²c adress!",MB_OK | MB_ICONINFORMATION);
    }
    

    Das ist die gesammte Fkt die beim Buttponklick abgearbeitet werden soll



  • lol, du bist witzig. Du öffnest deine Datei WriteOnly!



  • databin.Open(m_sPath, CFile::modeRead); 
    databin.Read (data_to_send,256);
    


  • :p mist hatte auf der scuhe nach nem fehler wohl das flag geändert und ned rückgängig gemacht

    jetzt kommt ein weiteres problem ins spiel, endlosschleife 😡

    das unterscheidet halt noobs von profis



  • auch wenn ich mir nich sicher bin is
    while (*str_ptr)

    nich immer true wenn danach str_ptr++;

    aber wie geasagt nich sicher



  • str_ptr = &WPI2C[0];
    

    wobei

    unsigned char WPI2C[] = {'#','W','P','I','2','C','_','A','_','0','_','1','0',0x00};
    

    ist und wenn der pointer aud 0x00 zeigt bricht diese schleife ab... bei der schleife fürs auslesen funktioniert das ja auch


Anmelden zum Antworten