MFC und USB2.0 betreiben



  • Hi leutz,

    mein Problem lautet wie folgt:
    Habe eine bestehende Konsolenanwendung(DOS-Shell) in C++ und integriere diese gerade in eine grafische MFC-Umgebung. Eine der Methoden des Programms läd eine Datei über die USB Schnittstelle in ein FPGA. Die dazu nötigen Methoden stimmen. Nun ist es so, das die Konsolenanwendung für diesen Ladevorgang ca. 4 Sekunden, die grafische Oberfläche 20 - 30 Sekunden braucht.

    Was mach die MFC Oberfläche anders als die Konsolenanwendung?
    Müsste man vielleicht einen eigenen Prozess für die grafische Anwendung starten?

    Sorry ich bin MFC noobie 🙄

    Danke für hilfreiche Antworten!

    Chiao



  • Zeig doch mal Quelltext, ist einfacher zu analysieren...



  • Den Code kann ich nicht posten, da das ein firmeninternes Programm ist. Ausserdem ist der Code zu lang, um ihn zu posten.

    Möchte nur wissen, wie bei oben genannten Problem es bei MFC zu Engpässen in der Programmverarbeitung kommen kann!

    Chiao



  • Zu Engpässen kommt es garnicht außer du macht irgendwas damit was wir nicht wissen weil du entweder den Ablauf genau beschreibst oder einen Teil des Codes postest



  • naja den part wo du auf die schnittstelle zugreifst kann ja wohl nicht so ..naja ok! ist aber schwer zu sagen. könnte alles mögliche sein, kann auch sein das du unsauber konvertiert hast etc. gibt viele möglichkeiten!

    kann aber auch einfach daran liegen das du dabei evtl. auf funktionen der mfc zugreifst etc.



  • Ok leute, hier ist der Quellcode

    Alle Funktionen, die nicht von MFC Objekten abgeleitet sind, stammen aus der alten Konsolenanwendung. Die sollten funktionieren.

    // MchTrDlg.cpp : Implementierungsdatei
    //
    
    #include "stdafx.h"
    #include "MchTr.h"
    #include "MchTrDlg.h"
    #include <windows.h>
    
    #include <io.h>
    #include <sys\stat.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <objbase.h>
    #include <initguid.h>	//this file is necessary for GUID macros like in Guids.h
    
    #include <mapidefs.h>
    #include <Setupapi.h>	//Win32 setup API header file, required library file is "Setupapi.lib"
    						//in VS: goto "Project/Settings", "Link" and  
    						//				insert filename "Setupapi.lib" in "Object/library modules"
    #include <winioctl.h>	//includes macro definitions for IOCTL operations
    						//this file must be included!!
    
    #include "CeUsb2if.h"	//CeUsb2 driver programming interface (structures, definitions and IOCTL codes)
    #include "CeFirmware.h" //Definition of the firmware programming interface
    #include "CeError.h"	//Status code definitions for CeUSb2 interface
    #include "Guids.h"		//CeUsb2 device interface GUIDs are defined in this file
    
    //#include "tcapture.h"
    #include <winbase.h>
    
    #include "Usbd.h"		//Necessary to get interface information: GetIFInfo()
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    //classes and defines from tcapture.h
    
    #define CAPTURE_NO_ERROR					0x00
    #define CEUSB2_OPEN_FAILED				    0x01
    #define CEUSB2_IOCTL_OPERATION_FAILED		0x02
    #define CEUSB2_FPGA_CONFIGURATION_FAILED	0x03
    #define EXO_FILE_OPEN_FAILED				0x04
    #define CEUSB2_RESET_FAILED					0x05
    #define PIPE_RESET_FAILED					0x06
    #define FILE_NOT_CREATED					0x07
    #define PIPE_ABORT_FAILED					0x08
    #define TESTMODE_ACTIVATE_FAILED			0x09
    #define READ_STREAM_FAILED					0x0A
    #define START_TRACER_FAILED					0x0B
    #define WRITE_TO_DISK_FAILED				0x0C
    #define MANUAL_ABORT						0x0D
    
    //#define CAPTURE_EXO_FILE				"tracer_testmode_off.exo"
    //#define CAPTURE_EXO_FILE_TESTMODE		"D:\\ftp\\MchTr_GUI\\Debug\\tracer_testmode_on.exo"
    
    #define BLOCK_SIZE			1024
    
    //Globals
    char *ExoFile;
    unsigned int CaptureFileSize;
    unsigned int StartTriggerPoint;
    unsigned int EndTriggerPoint;
    bool overwrite=false;
    bool start=false;
    bool stop=false;
    bool filter=false;
    bool leave=false;
    //End Globals		
    
    class TCapture : public CMchTrDlg
    {
    public:
    	TCapture();
    
    	// Destructor: closes connections to CEUSB2-board
    	~TCapture();
    
    	int capture(int total_time, char* file, int channel, int transfer_rate, int testmode);
    	bool OpenCeUsb2 (void);
    	DWORD OpenUsb2(GUID Guid, UINT DeviceIndex, HANDLE *DevHandle);
    	void CloseCeUsb2(HANDLE DevHandle);
    	bool ResetPipe(unsigned long pipe);
    	bool AbortPipe(unsigned long pipe);
    	bool InitFpga(void);
    	bool WriteFpgaBuffer(unsigned char *lBuffer, unsigned long Length);
    	int IsFpgaConfiguredCorrectly(void);
    	bool GpifAbort(void);
    	bool ReinitFw(void);
    	bool StartTracer(void);
    	bool Testmode(void);
    	int ReadExoFileBuffer(FILE *file_stream, unsigned char *Buffer, int Length);
    	int ConfigureFpga(int testm);
    	bool ResetFpga(void);
    	bool ReadData(unsigned char *lBuffer, unsigned long Length);
    	void error(int e);
    
    protected:
    
    	int filehandle;
    	time_t start_time;
    
    	// handle to CEUSB2 device
    	HANDLE m_board_handle;
    };
    
    TCapture::TCapture()
    {
    }
    
    int TCapture::capture(int total_time, char *capture_file, int chan, int transfer_rate, int testmode)
    {
    	int RetCode;
    	int i=0, elapsed_time = 0;
    	unsigned char Databuffer[BLOCK_SIZE]; //for trace on all channels = 128kbit/s
    	unsigned char dummy1[BLOCK_SIZE/2];   //for trace on all channels with 64kbit/s
    	unsigned char dummy3[BLOCK_SIZE/128]; //for trace on specific channel with 64kbit/s
    	unsigned char dummy4[BLOCK_SIZE/64];  //for trace on specific channel with 128kbit/s
    	int tmp_chan=chan;
    
    //	time_t finish_time;
    //	double elapsed_time_, Speed = 0;
    
    	// Configure FPGA on CEUSB2 Board ****************************************
    	if ( (RetCode = ConfigureFpga (testmode)) != CAPTURE_NO_ERROR )
    		return RetCode;
    
    	// Open Handle to CEUSB2 Board *******************************************
    	if (!OpenCeUsb2 () )
    	{
    		CloseCeUsb2 (&m_board_handle) ;
    		return CEUSB2_OPEN_FAILED;
    	}
    
    	//Delete old capturefile before creating new empty file
    	_unlink(capture_file);
    
    	//Create new file
    	if ( (filehandle = _open( capture_file, _O_RDWR | _O_BINARY | _O_CREAT, _S_IWRITE )) == -1 )
    		return FILE_NOT_CREATED;
    
    	//Reset FPGA design
    	if (!ResetFpga () )
    		return CEUSB2_RESET_FAILED;
    	else
    		m_CaptureError+="FPGA reset successful\r\n";
    
    	//Abort GPIF waveform transition
    	if (!GpifAbort () )
    		perror("GPIF abort failed\n");
    	else
    		m_CaptureError+="GPIF aborted successfully\r\n";
    
    	// Reset pipe1 for ReadData()
    	if (!ResetPipe (1) )
    		return PIPE_RESET_FAILED;
    	else
    		m_CaptureError+="Pipe reset successful\r\n";
    
    	// Reinitialize Firmware
    	if (ReinitFw () )
    		m_CaptureError+="Firmware reinit successful\r\n";
    
    	time(&start_time);
    
    	// Write header information
    	_write( filehandle, &start_time, 4);
    	_write( filehandle, &chan, 1);
    	_write( filehandle, &total_time, 11);
    
    	//Reset FPGA design
    	if (!ResetFpga () )
    		return CEUSB2_RESET_FAILED;
    //	else
    //		printf("FPGA reset successful\n");
    
    	//Testmode or not
    	if ( testmode == 1 ) 
    	{
    		m_CaptureError+="*** Testmode activated! ***\r\n";
    			//Send start signal
    		if (!StartTracer () )
    		return START_TRACER_FAILED;
    	}
    
    	//	time(&start_time);			
    
    	//Starting capture process ***********************************************
    	if ( chan==0 )
    	{
    		if (transfer_rate==64)
    		{
    		      MessageBox("0xff 64");
    			while (elapsed_time < total_time)
    			{
    				if( !ReadData(Databuffer, BLOCK_SIZE) )
    					return READ_STREAM_FAILED;
    
    				for (i=0; i<512; i++)
    					dummy1[i]=Databuffer[i*2];
    
    				if ( unsigned(_write( filehandle, dummy1, BLOCK_SIZE/2 )) != BLOCK_SIZE/2 )
    					return WRITE_TO_DISK_FAILED;
    				elapsed_time++;
    			}
    
    		}
    		else
    		{
    			MessageBox("0xff 128");
    			while (elapsed_time < total_time)
    			{
    				if( !ReadData(Databuffer, BLOCK_SIZE) )
    					return READ_STREAM_FAILED;
    
    				if ( unsigned(_write( filehandle, Databuffer, BLOCK_SIZE )) != BLOCK_SIZE )
    					return WRITE_TO_DISK_FAILED;
    				elapsed_time++;
    			}
    		}
    	}
    	else
    	{ // single-channel trace (Parameter -c set)
    
    		if (transfer_rate==64)
    		{
    			MessageBox("-c 64");
    			while (elapsed_time < total_time)
    			{
    				if( !ReadData(Databuffer, BLOCK_SIZE) )
    				return READ_STREAM_FAILED;
    
    				for (int i=0; i<BLOCK_SIZE/128; i++)
    					dummy3[i] = Databuffer[(128*i)+tmp_chan];
    
    				if ( unsigned(_write( filehandle, dummy3, BLOCK_SIZE/128 )) != BLOCK_SIZE/128 )
    					return WRITE_TO_DISK_FAILED;
    			   elapsed_time++;
    			}
    		}
    		else
    		{
    			MessageBox("-c 64");
    			while (elapsed_time < total_time)
    			{
    				if( !ReadData(Databuffer, BLOCK_SIZE) )
    					return READ_STREAM_FAILED;
    
    				for (i=0; i<(BLOCK_SIZE/128); i++)
    				{	
    					dummy4[i]=Databuffer[tmp_chan+i*128];
    					dummy4[++i]=Databuffer[tmp_chan+i*128+1];
    				}
    
    				//write sgl_channel in file
    				if ( unsigned(_write( filehandle, dummy4, BLOCK_SIZE/64 )) != BLOCK_SIZE/64 )
    					return WRITE_TO_DISK_FAILED;
    
    				/* //write all in alles.txt
    				if ( unsigned(_write( fh1, Databuffer, BLOCK_SIZE )) != BLOCK_SIZE )
    					return WRITE_TO_DISK_FAILED;
    				*/
    				elapsed_time++;
    			}
    		}
    	}	
    
    	//calculate elapsed time and speed
    /*	time(&finish_time);
    	elapsed_time_ = difftime(finish_time, start_time);
    	printf("\nElapsed time while capturing %dKB: %2.2f seconds\n", (BLOCK_SIZE*total_frames)/1024, elapsed_time_);
    	Speed = (BLOCK_SIZE*total_frames)/(elapsed_time_*1024*1024);
    	printf("Speed: %2.4fMB/s", Speed);
    */
    
    	return CAPTURE_NO_ERROR;
    }
    
    TCapture::~TCapture()
    {
    	// close files
    	_close( filehandle );
    
    	// CeUsb2-Close
    	CloseCeUsb2 (&m_board_handle) ;
    }
    
    //Initialize Fpga device for configuration.
    //Returns TRUE if succeeds, otherwise returns FALSE
    //
    bool TCapture::InitFpga(void)
    {
    	DWORD BytesReturned;
    	unsigned char DummyBuffer[1];	//0x00 if initialization successful, 0xAB if error
    
    	CEUSB2_VENDOR_REQUEST_CONTROL VenRequest;	//vendor request control structure
    
    	//set up the FPGA initialization structure to initialize FPGA device for configuration
    	VenRequest.Request = CEUSB2_CMD_FPGA_INIT;	
    	VenRequest.Direction = 1;
    	VenRequest.Value = 0;
    	VenRequest.Index = 0;
    
    	//call the driver
    	return  DeviceIoControl(
    						m_board_handle,							//	handle to device
    						IOCTL_CEUSB2_VENDOR_REQUEST,			//	operation control code
    						&VenRequest,							//	input data buffer
    						sizeof(CEUSB2_VENDOR_REQUEST_CONTROL),	//	size of input data buffer
    						&DummyBuffer,							//	output data buffer
    						1,										//	size of output data buffer
    						&BytesReturned,							//	byte count
    						NULL									//	overlapped information
    							)!=0;
    }
    
    // Opens the CeUsb2 device with the given index and device interface GUID, and stores its handle in
    // DevHandle pointer. This functions return 32 bit status code (0 = success).
    //
    DWORD TCapture::OpenUsb2(GUID Guid, UINT DeviceIndex, HANDLE *DevHandle)
    {
    	DWORD dwStatus = 0;		// return status
    	SP_INTERFACE_DEVICE_DATA DevInterfaceData;
    	PSP_INTERFACE_DEVICE_DETAIL_DATA pDevDetail = NULL;
    	SP_DEVINFO_DATA DevInfoData;
    	DWORD Size;
    
    	// open a device enumeration handle
    	HDEVINFO hDevInfo = SetupDiGetClassDevs(&Guid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE );
    	if (hDevInfo == INVALID_HANDLE_VALUE)
    		return GetLastError();
    
    	// find the device with DeviceIndex index
    	DevInterfaceData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
    	if(!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &Guid, DeviceIndex, &DevInterfaceData ))
    	{
    		dwStatus = GetLastError();
    		goto exit_open;
    	}
    
    	// first get the length of detailed information
    	SetupDiGetDeviceInterfaceDetail(hDevInfo, &DevInterfaceData, NULL, 0, &Size, NULL );
    
    	pDevDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(Size);
    	pDevDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
    	DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
    
    	// get device details
    	if(!SetupDiGetDeviceInterfaceDetail(hDevInfo, &DevInterfaceData, pDevDetail, Size, NULL, &DevInfoData))
    	{	
    		dwStatus = GetLastError();
    		goto exit_open;
    	}
    
    	// open the device
    	*DevHandle = CreateFile(
    						pDevDetail->DevicePath,			// name of the device
    						GENERIC_READ | GENERIC_WRITE,	// access mode
    						0,								// share mode
    						NULL,							// security desc.
    						OPEN_EXISTING,					// how to create
    						0,								// file attributes
    						NULL							// template file
    							);
    
    	if ( *DevHandle == INVALID_HANDLE_VALUE )
    		dwStatus = GetLastError();
    
    	exit_open:
    
    	if(pDevDetail)
    	{
    		free(pDevDetail);
    		pDevDetail = NULL;
    	}
    
    	SetupDiDestroyDeviceInfoList(hDevInfo);		// destroy device information list
    
    	return dwStatus;
    }
    
    //Open handle to CEUSB2 device.
    //
    bool TCapture::OpenCeUsb2 (void)
    {
    
       	__GUIDS_H__		//start macro
    
    	// open handle to the device
    	OpenUsb2(GUID_INTERFACE_CEUSB2, 0, &m_board_handle);
    
    	if ( m_board_handle == INVALID_HANDLE_VALUE )
    	{
    		//something wrong! There is not a device in the system
    		//with this link name
    		return FALSE;
    	}
    	return TRUE;
    }
    
    // CloseCeUsb2 function traverses the functionality of OpenCeUsb function, and closes (nullifies) the
    // device handle stored during open device process.
    //
    void TCapture::CloseCeUsb2(HANDLE DevHandle)
    {
    	if(!DevHandle)
    	{
    		CloseHandle(DevHandle);
    		DevHandle = NULL;
    	}
    }
    
    // Reset USB pipe, necessary to use it
    //
    bool TCapture::ResetPipe(unsigned long pipe)
    {
    	DWORD BytesReturned;
    	bool Ret;
    
        Ret = DeviceIoControl(
    					m_board_handle,				// handle to device
    					IOCTL_CEUSB2_RESET_PIPE,	// operation control code
    					&pipe,						// input data buffer
    					sizeof(ULONG),				// size of input data buffer
    					NULL,						// output data buffer
    					0,				 			// size of output data buffer
    					&BytesReturned,				// byte count
    					NULL						// overlapped information
    						)!=0;	
    	return Ret;
    }
    
    // Abort USB pipe, might be implemented before reset pipe
    //
    bool TCapture::AbortPipe(unsigned long pipe)
    {
    	DWORD BytesReturned;
    	bool Ret;
    
        Ret = DeviceIoControl(
    					m_board_handle,				// handle to device
    					IOCTL_CEUSB2_ABORT_PIPE,	// operation control code
    					&pipe,						// input data buffer
    					sizeof(ULONG),				// size of input data buffer
    					NULL,						// output data buffer
    					0,				 			// size of output data buffer
    					&BytesReturned,				// byte count
    					NULL						// overlapped information
    						)!=0;	
    	return Ret;
    }
    
    //Write a buffer of bytes to the Fpga.
    //Returns TRUE if succeeds, otherwise returns FALSE
    //
    bool TCapture::WriteFpgaBuffer(unsigned char *lBuffer, unsigned long Length)
    {
    	DWORD BytesReturned; //dummy
    	bool Ret;
    
    	ULONG pipe;
    
    	pipe = 0;  //pipe 0 means: Type Bulk, Direction Out, Endpoint number 2
    
        Ret = DeviceIoControl(
    					m_board_handle,				// handle to device
    					IOCTL_CEUSB2_WRITE_BULK,	// operation control code
    					&pipe,						// input data buffer
    					sizeof(ULONG),				// size of input data buffer
    					lBuffer,				    // output data buffer
    					Length,				 		// size of output data buffer
    					&BytesReturned,				// byte count
    					NULL						// overlapped information
    						)!=0;	
    
    	return Ret;
    }
    
    //Read Fpga's done status.
    //Returns -1 if IOCTL call fails, 1 if Fpga is configured successfully and 0 if it
    //could not be configured correctly.
    //
    int TCapture::IsFpgaConfiguredCorrectly(void)
    {
    	DWORD BytesReturned;
    	unsigned char Result;
    	BOOL Ret;
    
    	CEUSB2_VENDOR_REQUEST_CONTROL VenRequest;	//vendor request control structure
    
    	//set up the FPGA initialization structure to initialize FPGA device for configuration
    	VenRequest.Request = CEUSB2_CMD_FPGA_GET_STATUS;	
    	VenRequest.Direction = 1;
    	VenRequest.Value = 0;
    	VenRequest.Index = 0;
    
    	//call the driver
    	Ret = DeviceIoControl(
    					m_board_handle,							// handle to device
    					IOCTL_CEUSB2_VENDOR_REQUEST,			// operation control code
    					&VenRequest,							// input data buffer
    					sizeof(CEUSB2_VENDOR_REQUEST_CONTROL),	// size of input data buffer
    					&Result,								// output data buffer
    					sizeof(unsigned char),					// size of output data buffer
    					&BytesReturned,							// byte count
    					NULL									// overlapped information
    						);
    
    	if ( !Ret )
    	{
    		return -1;
    	}
    	else
    	{
    		if (Result == 0)
    			return 1;
    		else
    			return 0;
    	}
    }
    
    //function that reads an exo file whose handle is passed with file_stream
    //argument. Data read from the file is returned in Buffer argument. Length is
    //max. number of bytes requested. It returns actual number of bytes read.
    //
    int TCapture::ReadExoFileBuffer(FILE *file_stream, unsigned char *Buffer, int Length)
    {
    	int c;
    	int Index;
    	int type;
    	int i;
    
    	int len;
    	int addr;
    	int value;
    	unsigned char DummyBuffer[64];
    
    	// fill the buffer with data
    	if ( (c=getc(file_stream)) != -1) 
    	{
    		Index = len = 0;
    		if (c != 'S') 
    		{
    			return 0;
    		}
    
    		fscanf(file_stream,"%1d",&type);
    		switch (type) 
    		{
    			case 8:
    
    			case 9:
    				break;	//end
    
    			case 1:	//S1 records
    				fscanf(file_stream,"%2x%4x",&len,&addr);
    				len-=3;
    				for (i=len;i>0;i--)
    				{
    					fscanf(file_stream,"%2x",&value);
    					Buffer[Index++]=value;
    				}
    				break;
    
    			case 2:	//S2 records
    				fscanf(file_stream,"%2x%6x",&len,&addr);
    				len-=4;
    				for (i=0;i<len;i++) 
    				{	
    					fscanf(file_stream,"%2x",&value);
    					Buffer[Index++]=value;
    				}
    				break;
    
    			default:
    				break;
    		}
    
    		// get the rest fo the line 
    		fgets((char*)DummyBuffer,Length,file_stream);
    	}
    	else
    		return 0;
    
    	return len;
    }
    
    //Configure Fpga
    //
    int TCapture::ConfigureFpga(int testm)
    {
    	int BytesRead = 0;
    	unsigned char Buffer[64] = {0};
    	FILE *m_file_stream;
    
    	//open file-stream for FPGA conf.data
    	if( testm == 0)
    	{
    		if ( (m_file_stream = fopen (ExoFile, "rt" )) == NULL )
    		{	
    			MessageBox("The ExoFile must have the same dir as the capture-file!","EXO_FILE_OPEN_FAILED",MB_ICONSTOP);
    			return EXO_FILE_OPEN_FAILED;
    		}
    	}
    	else
    	{
    		if ( (m_file_stream = fopen (ExoFile, "rt" )) == NULL )
    		{
    			MessageBox("The ExoFile must have the same dir as the capture-file","EXO_FILE_OPEN_FAILED",MB_ICONSTOP);
    			return EXO_FILE_OPEN_FAILED;
    		}
    	}
    
    	// rewind the file
    	rewind(m_file_stream);
    
    //	printf ("Exo-file opened\n");
    
    	//open handle to CEUSB2 board
    	if (!OpenCeUsb2 () )
    	{
    		m_CaptureError+="OpenCeUsb2 failed!\r\n";
    		return CEUSB2_OPEN_FAILED;
    	}
    
    	m_CaptureError+="CeUsb2 opened\r\n";
    
    	// Reset pipe0 for WriteFpga()
    	if (!ResetPipe(0))
    		return PIPE_RESET_FAILED;
    
    	if (!InitFpga () )
    	{
    		CloseCeUsb2 (&m_board_handle) ;
    		return CEUSB2_FPGA_CONFIGURATION_FAILED;
    	}
    
    	m_CaptureError+="FPGA initialized\r\n";
    
    	while((BytesRead = ReadExoFileBuffer(m_file_stream, Buffer, 64 )) != 0)
    	{
    		if ( !WriteFpgaBuffer(Buffer,BytesRead) )
    			break;
    	}
    
    	fclose( m_file_stream );
    
    	int FpgaStatus = IsFpgaConfiguredCorrectly();
    
    	CloseCeUsb2 (&m_board_handle) ;
    
    	if(FpgaStatus == -1)
    		return CEUSB2_IOCTL_OPERATION_FAILED;
    	else if(FpgaStatus == 0)
    	{
    		return CEUSB2_FPGA_CONFIGURATION_FAILED;
    	}
    
    	m_CaptureError+="FPGA configured successfully\r\n";
    	return CAPTURE_NO_ERROR;
    
    }
    
    //Reset FPGA design
    //Returns TRUE if succeeds, otherwise returns FALSE
    //
    bool TCapture::ResetFpga(void)
    {
    	DWORD BytesReturned;
    
    	CEUSB2_VENDOR_REQUEST_CONTROL VenRequest;	//vendor request control structure
    
    	//set up the FPGA initialization structure to initialize FPGA device for configuration
    	VenRequest.Request = CEUSB2_CMD_FPGA_RESET;	
    	VenRequest.Direction = 0;
    	VenRequest.Value = 0;
    	VenRequest.Index = 0;
    
    	//call the driver
    	return  DeviceIoControl(
    						m_board_handle,							//	handle to device
    						IOCTL_CEUSB2_VENDOR_REQUEST,			//	operation control code
    						&VenRequest,							//	input data buffer
    						sizeof(CEUSB2_VENDOR_REQUEST_CONTROL),	//	size of input data buffer
    						NULL,									//	output data buffer
    						0,										//	size of output data buffer
    						&BytesReturned,							//	byte count
    						NULL									//	overlapped information
    							)!=0;
    }
    
    // Abort the current GPIF waveform transition
    //
    bool TCapture::GpifAbort(void)
    {
    	DWORD BytesReturned;
    
    	CEUSB2_VENDOR_REQUEST_CONTROL VenRequest;	//vendor request control structure
    
    	//set up the FPGA initialization structure to initialize FPGA device for configuration
    	VenRequest.Request = CEUSB2_CMD_GPIF_ABORT;	
    	VenRequest.Direction = 0;
    	VenRequest.Value = 0;
    	VenRequest.Index = 0;
    
    	//call the driver
    	return  DeviceIoControl(
    						m_board_handle,							//	handle to device
    						IOCTL_CEUSB2_VENDOR_REQUEST,			//	operation control code
    						&VenRequest,							//	input data buffer
    						sizeof(CEUSB2_VENDOR_REQUEST_CONTROL),	//	size of input data buffer
    						NULL,									//	output data buffer
    						0,										//	size of output data buffer
    						&BytesReturned,							//	byte count
    						NULL									//	overlapped information
    							)!=0;
    }
    
    // Reinitialize Firmware
    //
    bool TCapture::ReinitFw(void)
    {
    	DWORD BytesReturned;
    
    	CEUSB2_VENDOR_REQUEST_CONTROL VenRequest;	//vendor request control structure
    
    	//set up the FPGA initialization structure to initialize FPGA device for configuration
    	VenRequest.Request = CEUSB2_CMD_FW_REINIT;	
    	VenRequest.Direction = 0;
    	VenRequest.Value = 0;
    	VenRequest.Index = 0;
    
    	//call the driver
    	return  DeviceIoControl(
    						m_board_handle,							//	handle to device
    						IOCTL_CEUSB2_VENDOR_REQUEST,			//	operation control code
    						&VenRequest,							//	input data buffer
    						sizeof(CEUSB2_VENDOR_REQUEST_CONTROL),	//	size of input data buffer
    						NULL,									//	output data buffer
    						0,										//	size of output data buffer
    						&BytesReturned,							//	byte count
    						NULL									//	overlapped information
    							)!=0;
    }
    
    // Send startsignal to FPGA's internal bitgenerator
    //
    bool TCapture::StartTracer(void)
    {
    	DWORD BytesReturned; //dummy
    	int startbyte;
    
    	CEUSB2_VENDOR_REQUEST_CONTROL VenRequest;	//vendor request control structure
    
    	//set up the FPGA initialization structure to initialize FPGA device for configuration
    	VenRequest.Request = CEUSB2_CMD_GPIF_SINGLE_READ_WRITE;	
    	VenRequest.Direction = 1;
    	VenRequest.Value = 0;
    	VenRequest.Index = 0;
    
    	//call the driver
    	return  DeviceIoControl(
    						m_board_handle,							//	handle to device
    						IOCTL_CEUSB2_VENDOR_REQUEST,			//	operation control code
    						&VenRequest,							//	input data buffer
    						sizeof(CEUSB2_VENDOR_REQUEST_CONTROL),	//	size of input data buffer
    						&startbyte,								//	output data buffer
    						sizeof(int),							//	size of output data buffer
    						&BytesReturned,							//	byte count
    						NULL									//	overlapped information
    							)!=0;
    }
    
    // Read datastream on pipe1, write it to buffer
    //
    bool TCapture::ReadData(unsigned char *lBuffer, unsigned long Length)
    {
    	DWORD BytesReturned; //dummy
    	bool Ret;
    	int error;
    
    	ULONG pipe = 1;		//pipe 1 means: Type Bulk, Direction In, Endpoint number 6
    
        Ret = DeviceIoControl(
    					m_board_handle,				// handle to device
    					IOCTL_CEUSB2_READ_BULK,		// operation control code
    					&pipe,						// input data buffer
    					sizeof(ULONG),				// size of input data buffer
    					lBuffer,				    // output data buffer
    					Length,				 		// size of output data buffer
    					&BytesReturned,				// byte count
    					NULL						// overlapped information
    						)!=0;
    
    	error = GetLastError();
    	return Ret;
    }
    
    // Starts ConfigureFPGA, opens device, creates file, resets FPGA, aborts GPIF Settings,
    // resets pipe, starts capturing and finally writes data to file
    //
    
    //////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    // CAboutDlg-Dialogfeld für Anwendungsbefehl "Info"
    
    class CAboutDlg : public CDialog
    {
    public:
    	CAboutDlg();
    
    // Dialogfelddaten
    	//{{AFX_DATA(CAboutDlg)
    	enum { IDD = IDD_ABOUTBOX };
    	CString	m_Information;
    	//}}AFX_DATA
    
    	// Vom Klassenassistenten generierte Überladungen virtueller Funktionen
    	//{{AFX_VIRTUAL(CAboutDlg)
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV-Unterstützung
    	//}}AFX_VIRTUAL
    
    // Implementierung
    protected:
    	//{{AFX_MSG(CAboutDlg)
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    };
    
    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    
    }
    
    void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CAboutDlg)
    	DDX_Text(pDX, IDC_EDIT1, m_Information);
    	//}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    	//{{AFX_MSG_MAP(CAboutDlg)
    		// Keine Nachrichten-Handler
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CMchTrDlg Dialogfeld
    
    CMchTrDlg::CMchTrDlg(CWnd* pParent /*=NULL*/)
    	: CDialog(CMchTrDlg::IDD, pParent)
    {
    	//{{AFX_DATA_INIT(CMchTrDlg)
    	m_CaptureFilePath=_T("");
    	m_CaptureTime =0;
    	m_CaptureChannel = 0;
    	m_CaptureError = _T("");
    	m_Capture64k = FALSE;
    	m_Capture128k = FALSE;
    	m_CaptureSize = 0;
    	m_CaptureStartTrigger = 0;
    	m_CaptureEndTrigger = 0;
    	m_TriggerCondition = 0;
    	//}}AFX_DATA_INIT
    	// Beachten Sie, dass LoadIcon unter Win32 keinen nachfolgenden DestroyIcon-Aufruf benötigt
    	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }
    
    void CMchTrDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CMchTrDlg)
    	DDX_Text(pDX, IDC_EDIT1,m_CaptureFilePath);
    	DDX_Text(pDX, IDC_EDIT2, m_CaptureTime);
    	DDX_Text(pDX, IDC_EDIT, m_CaptureSize);
    	DDX_CBIndex(pDX, IDC_COMBO1, m_CaptureChannel);
    	DDX_Text(pDX, IDC_EDIT3, m_CaptureError);
    	DDX_Check(pDX, IDC_CHECK1, m_Capture64k);
    	DDX_Check(pDX, IDC_CHECK2, m_Capture128k);
    	DDX_Text(pDX, IDC_EDIT_starttrigger, m_TriggerCondition);
    	//}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CMchTrDlg, CDialog)
    	//{{AFX_MSG_MAP(CMchTrDlg)
    	ON_WM_SYSCOMMAND()
    	ON_WM_PAINT()
    	ON_WM_QUERYDRAGICON()
    	ON_BN_CLICKED(IDC_BUTTON2, OnCaptureSaveButton)
    	ON_BN_CLICKED(IDC_BUTTON_start, OnCaptureStartButton)
    	ON_BN_CLICKED(IDC_RADIO_filter, OnRADIOfilter)
    	ON_BN_CLICKED(IDC_RADIO_start, OnRADIOstart)
    	ON_BN_CLICKED(IDC_RADIO_stop, OnRADIOstop)
    	ON_BN_CLICKED(IDC_BUTTON_start2, OnCaptureStopButton)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CMchTrDlg Nachrichten-Handler
    
    BOOL CMchTrDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// Hinzufügen des Menübefehls "Info..." zum Systemmenü.
    
    	// IDM_ABOUTBOX muss sich im Bereich der Systembefehle befinden.
    	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    	ASSERT(IDM_ABOUTBOX < 0xF000);
    
    	CMenu* pSysMenu = GetSystemMenu(FALSE);
    	if (pSysMenu != NULL)
    	{
    		CString strAboutMenu;
    		strAboutMenu.LoadString(IDS_ABOUTBOX);
    		if (!strAboutMenu.IsEmpty())
    		{
    			pSysMenu->AppendMenu(MF_SEPARATOR);
    			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    		}
    	}
    
    	// Symbol für dieses Dialogfeld festlegen. Wird automatisch erledigt
    	//  wenn das Hauptfenster der Anwendung kein Dialogfeld ist
    	SetIcon(m_hIcon, TRUE);			// Großes Symbol verwenden
    	SetIcon(m_hIcon, FALSE);		// Kleines Symbol verwenden
    
    	// ZU ERLEDIGEN: Hier zusätzliche Initialisierung einfügen
    
    	return TRUE;  // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
    }
    
    void CMchTrDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    	{
    		CAboutDlg dlgAbout;
    		dlgAbout.DoModal();
    	}
    	else
    	{
    		CDialog::OnSysCommand(nID, lParam);
    	}
    }
    
    // Wollen Sie Ihrem Dialogfeld eine Schaltfläche "Minimieren" hinzufügen, benötigen Sie 
    //  den nachstehenden Code, um das Symbol zu zeichnen. Für MFC-Anwendungen, die das 
    //  Dokument/Ansicht-Modell verwenden, wird dies automatisch für Sie erledigt.
    
    void CMchTrDlg::OnPaint() 
    {
    	if (IsIconic())
    	{
    		CPaintDC dc(this); // Gerätekontext für Zeichnen
    
    		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
    
    		// Symbol in Client-Rechteck zentrieren
    		int cxIcon = GetSystemMetrics(SM_CXICON);
    		int cyIcon = GetSystemMetrics(SM_CYICON);
    		CRect rect;
    		GetClientRect(&rect);
    		int x = (rect.Width() - cxIcon + 1) / 2;
    		int y = (rect.Height() - cyIcon + 1) / 2;
    
    		// Symbol zeichnen
    		dc.DrawIcon(x, y, m_hIcon);
    	}
    	else
    	{
    		CDialog::OnPaint();
    	}
    }
    
    // Die Systemaufrufe fragen den Cursorform ab, die angezeigt werden soll, während der Benutzer
    //  das zum Symbol verkleinerte Fenster mit der Maus zieht.
    HCURSOR CMchTrDlg::OnQueryDragIcon()
    {
    	return (HCURSOR) m_hIcon;
    }
    
    void CMchTrDlg::OnCaptureSaveButton() 
    {
    
    	CFileDialog dlg(FALSE,NULL,NULL,NULL,"Textfiles txt|");
    
    	if ((dlg.DoModal())==IDOK) 
    			m_CaptureFilePath=dlg.GetPathName();
    	UpdateData(FALSE);
    
    }
    
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    //////////////////////CAPTURE START//////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    
    void CMchTrDlg::OnCaptureStartButton()
    {
    	UpdateData(TRUE); //Fields ---> Vars
    
    	m_CaptureError="";
    
    	UpdateData(FALSE);
    
    	TCapture* capture = new TCapture();	
    	char *EXO_TEST_ON = "tracer_testmode_on.exo";	//FPGA-load has to have the same dir as the saved capture
    	char *EXO_TEST_OFF = "tracer_testmode_off.exo";
    	char *CaptureFile = new char[m_CaptureFilePath.GetLength()+1];    // CStrings to ANSI string
    	strcpy(CaptureFile,m_CaptureFilePath);
    	int c, ok=1, count=0, transfer_rate;
    	char buffer[8];
    
    	 char buffer1[_MAX_PATH];
    	 HMODULE hEXE;
    
    	 hEXE = GetModuleHandle("MchTr.exe");
    	 ::GetModuleFileName (hEXE, buffer1, _MAX_PATH);
    	 CString Path=buffer;
    	 Path=(CString(buffer1).Left(CString(buffer1).ReverseFind('\\')+1));
    
    	 //char d[8];
    	 //sprintf(d,"%d",m_CaptureChannel);
    	 //MessageBox(d);	
    
    	if (strcmp(CaptureFile,"")==0 || !isalpha(CaptureFile[0]) || CaptureFile[1]!=':' || CaptureFile[2]!='\\' || !isgraph(CaptureFile[3]))
    	{	m_CaptureError += "Please enter a legal capture-file!\r\n"; ok=0; }
    	else
    	{
    		//combine the exopath
    		ExoFile = new char[strlen(Path)+1+strlen(EXO_TEST_ON)];
    
    		strcpy(ExoFile,Path);
    
    		strcat(ExoFile,EXO_TEST_ON);
    
    	}
    
    	//CaptureSize or CaptureTime selected
    	if (m_CaptureSize==0 && m_CaptureTime==0 || m_CaptureSize!=0 && m_CaptureTime!=0)
    	{
    			m_CaptureError+="Please enter Max.FileSize OR CaptureTime!\r\n";
    			ok=0;
    	}
    
    	//64k oder 128k -Kanal
    	if (m_Capture64k==FALSE && m_Capture128k==FALSE || m_Capture64k==TRUE && m_Capture128k==TRUE)
    	{ 
    		m_CaptureError+="Please select 64kbit/s OR 128kbit/s\r\n";
    		ok=0;
    	}
    	else
    		if (m_Capture64k==TRUE)
    			transfer_rate=64;
    		else
    		       transfer_rate=128;
    
    	if (ok==1)
    	{    
    		c = capture->capture( m_CaptureTime*1024, CaptureFile, m_CaptureChannel, transfer_rate, 0/*TESTMODE ON*/);
    
    		switch (c)
    		{
    			case CEUSB2_OPEN_FAILED :				m_CaptureError +="Error 0x01: unable open connection to CeUsb2 board.\r\n"; break;
    			case CEUSB2_IOCTL_OPERATION_FAILED :		m_CaptureError +="Error 0x02: unable to access CeUsb2 board.\r\n"; break;
    			case CEUSB2_FPGA_CONFIGURATION_FAILED :		m_CaptureError +="Error 0x03: unable to configure FPGA on CeUsb2 board.\r\n"; break;
    			case CEUSB2_RESET_FAILED :				m_CaptureError +="Error 0x05: unable to give reset signal.\r\n"; break; 
    			case PIPE_RESET_FAILED :				m_CaptureError +="Error 0x06: unable to reset pipe.\r\n"; break; 
    			case PIPE_ABORT_FAILED :				m_CaptureError +="Error 0x08: unable to abort pipe.\r\n"; break;
    			case EXO_FILE_OPEN_FAILED :				m_CaptureError +="Error 0x04: unable to open FPGA-load.\r\n"; break;
    			case TESTMODE_ACTIVATE_FAILED:			m_CaptureError +="Error 0x09: unable to activate testmode.\r\n"; break;
    			case FILE_NOT_CREATED	:			m_CaptureError +="Error 0x07: unable to create destination file.\r\n"; break;
    			case READ_STREAM_FAILED	 :			m_CaptureError +="Error 0x0A: error reading from stream.\r\n"; break;
    			case START_TRACER_FAILED :				m_CaptureError +="Error 0x0B: error giving start signal to internal bitgenerator.\r\n"; break;
    			case WRITE_TO_DISK_FAILED :				m_CaptureError +="Error 0x0C: unable to write data to disk.\r\n"; break;
    			case CAPTURE_NO_ERROR :				break;
    			case MANUAL_ABORT:					m_CaptureError +="Error 0x0D: capture finished by manual abort.\r\n"; break;
    			default :						sprintf(buffer,"%x",c); m_CaptureError+=buffer; m_CaptureError +=": unknown error occured.\r\n"; break;
    		}
    
    		delete capture;
    		delete ExoFile;
    	}
    
    	m_CaptureError+="... Capturing finished";
    
    	UpdateData(FALSE);	//Variablen ---> Felder
    
    	 //exit(0);
    }
    
    void CMchTrDlg::OnRADIOfilter() 
    {
    	filter=true;
    	start=false;
    	stop=false;
    }
    
    void CMchTrDlg::OnRADIOstart() 
    {
    	filter=false;
    	start=true;
    	stop=false;
    }
    
    void CMchTrDlg::OnRADIOstop() 
    {
    	filter=false;
    	start=false;
    	stop=true;
    }
    
    //manual abort the capture
    void CMchTrDlg::OnCaptureStopButton() 
    {
    	leave=true;
    }
    

    Hoffe ihr könnt das lesen!
    Danke im Voraus für eure Hilfe!

    Chiao


Anmelden zum Antworten