arthurcao
驱动小牛
驱动小牛
  • 注册日期2003-10-12
  • 最后登录2012-07-08
  • 粉丝0
  • 关注0
  • 积分92分
  • 威望20点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
阅读:1198回复:2

批量传输的应用程序问题(给分)

楼主#
更多 发布于:2003-12-21 18:28
我用的是EZ-USB FX2开发板,我的固件是厂商自带的例程BULKLOOP,就是2,4端点为输出,6,8端点为输入,但我想用EZ-USB FX开发板的一个应用程序,为我这个BULKLOOP固件配合工作,我把他哪个程序(他是用端点2为输出,端点0为输入)改做用端点4为输出,端点8为输入,怎么不好用啊,还需要改什么其他的地方么?请高手帮忙,前辈指导,急!(QQ:6611555)应用程序如下:// BulkXferDlg.cpp : implementation file
//


#include \"stdafx.h\"
#include \"BulkXfer.h\"
#include \"BulkXferDlg.h\"
#include \"devioctl.h\"
#include \"ezusbsys.h\"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBulkXferDlg dialog

CBulkXferDlg::CBulkXferDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBulkXferDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBulkXferDlg)
m_BlkSize = 1;
m_InData = _T(\"\");
m_Outdata = _T(\"\");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBulkXferDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBulkXferDlg)
DDX_Control(pDX, IDC_COMBO1, m_DriveName);
DDX_Text(pDX, IDC_BLKSIZE, m_BlkSize);
DDV_MinMaxInt(pDX, m_BlkSize, 1, 64);
DDX_Text(pDX, IDC_INDATA, m_InData);
DDX_Text(pDX, IDC_OUTDATA, m_Outdata);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBulkXferDlg, CDialog)
//{{AFX_MSG_MAP(CBulkXferDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnClear_InData)
ON_BN_CLICKED(IDC_BUTTON2, OnClear_OutData)
ON_EN_CHANGE(IDC_INDATA, OnChangeIndata)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBulkXferDlg message handlers

BOOL CBulkXferDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog.  The framework does this automatically
//  when the application\'s main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

SetupDriverComboBox(); // look for attached EZ-USB devices

return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CBulkXferDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
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;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CBulkXferDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CBulkXferDlg::OnClear_InData()
{
m_InData = \"\";
UpdateData(FALSE);
}

void CBulkXferDlg::OnClear_OutData()
{
m_Outdata = \"\";
UpdateData(FALSE);
}



void CBulkXferDlg::OnChangeIndata()
{

BULK_TRANSFER_CONTROL btc;
ULONG nBytes;
BOOLEAN bResult;
HANDLE hDevice;
CString sDriverName;
int n;

CComboBox* pCBox = GetCComboBox(); // inline defined in BulkXFERDlg.h

// get the driver name from the combobox
    n = pCBox->GetLBTextLen( pCBox->GetCurSel() );
    pCBox->GetLBText( pCBox->GetCurSel(), sDriverName.GetBuffer(n));
    sDriverName.ReleaseBuffer();


// update member variables from text box controls
UpdateData(TRUE);

// right-most char represents last keypress
// append right-most char to \"trigger\" buffer
m_StrBuffer = m_StrBuffer + m_InData.Right (1);

// if we have collected a \"block\", do the bulk xfer
if (m_StrBuffer.GetLength() == m_BlkSize)
{
// extract the individual characters and put them
// into the byte buffer
for (int i = 0; i< m_StrBuffer.GetLength(); i++)
{
m_Buffer = m_StrBuffer.GetAt(i);
}

// open driver
if (OpenDriver(&hDevice,sDriverName))
{

// we use pipes 1 and 0 because that\'s what \"ep-pair.hex\" sets up

btc.pipeNum = 4;

// write data OUT to EZUSB device
bResult = DeviceIoControl (hDevice,
IOCTL_EZUSB_BULK_WRITE,
&btc,
sizeof (BULK_TRANSFER_CONTROL),
m_Buffer,
m_StrBuffer.GetLength(),
(unsigned long *)&nBytes,
NULL);

if (!bResult)
AfxMessageBox(\"Correct Pipe not found. Perhaps \\\"Ep-pair.hex\\\" was not downloaded to a development board.\", MB_OK|MB_ICONSTOP);
else
{
// no rabbits up our sleeve
for (i = 0; i < 63; i++)
m_Buffer = 0;

btc.pipeNum = 8;

// read data IN from EZUSB device
bResult = DeviceIoControl (hDevice,
IOCTL_EZUSB_BULK_READ,
&btc,
sizeof (BULK_TRANSFER_CONTROL),
m_Buffer,
m_StrBuffer.GetLength(),
(unsigned long *)&nBytes,
NULL);

if (!bResult)
AfxMessageBox(\"Correct Pipe not found. Perhaps \\\"Ep-pair.hex\\\" was not downloaded to a development board.\", MB_OK|MB_ICONSTOP);
else
{
// move data from buffer to output member variable
for (i = 0; i < m_StrBuffer.GetLength(); i++)
m_Outdata += m_Buffer;

// clear out \"trigger\" buffer
m_StrBuffer.Empty();

// transfer data from output member variable to output textbox
UpdateData(FALSE);

}

}

}

}
}

void CBulkXferDlg::SetupDriverComboBox() {

CString sDriverName, sCompleteName;

char num[3] = {0,0,0};

HANDLE hDriver;

CComboBox* pCBox = GetCComboBox(); // inline defined in BulkXFERDlg.h

pCBox->ResetContent ();
  
// Assume 32 EZ-USB boards are attached to the PC.
// Try to open each driver.  If successful, add driver name to combobox

for (int i = 0; i < MAX_USB_DEV_NUMBER; i++)
{
_itoa( i, num, 10 );
  
sDriverName = (CString)\"Ezusb-\" + num;

if (OpenDriver(&hDriver, sDriverName))
pCBox->AddString ((LPCTSTR) sDriverName);
else
{
if (i==0)
{
AfxMessageBox(\"No EZ-USB device drivers were found.  Perhaps no device is connected\", MB_OK|MB_ICONSTOP);
exit(0);
}
}

}

pCBox->SetCurSel(0);
}


BOOLEAN
CBulkXferDlg::OpenDriver (HANDLE* phDriver, CString devname)
{
SECURITY_ATTRIBUTES security;

security.nLength = sizeof(security);
security.lpSecurityDescriptor = NULL;
security.bInheritHandle = false;

    CString completeDeviceName = (CString)\"\\\\\\\\.\\\\\" + devname;

    *phDriver = CreateFile(   completeDeviceName,
                           GENERIC_WRITE,
                           FILE_SHARE_WRITE,
                           &security,
                           OPEN_EXISTING,
                           0,
                           NULL);

    return (*phDriver != INVALID_HANDLE_VALUE);

}

arthurcao喜欢开源。
arthurcao
驱动小牛
驱动小牛
  • 注册日期2003-10-12
  • 最后登录2012-07-08
  • 粉丝0
  • 关注0
  • 积分92分
  • 威望20点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-12-21 19:51
斑竹救命!各位大侠都那去了?!再线等。。。。。
arthurcao喜欢开源。
arthurcao
驱动小牛
驱动小牛
  • 注册日期2003-10-12
  • 最后登录2012-07-08
  • 粉丝0
  • 关注0
  • 积分92分
  • 威望20点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-12-22 09:45
给点答案啊?提示一下也好啊。
arthurcao喜欢开源。
游客

返回顶部