VC++ USBxpress 接收数据

2020-02-05 08:47发布

我在用VC++6.0打算为C8051F320编写了一个上位机软件,通过PC给MCU发数据可以,如程序
void CUsb_LedDlg::OnLedon()
{
        // TODO: Add your control notification handler code here
        SI_STATUS status = SI_SUCCESS;
        DWORD dwBytesSucceed = 0;
        DWORD dwBytesWriteRequest =8;
        BYTE Out_Packet[8]={0xAA,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
        status = SI_Write(m_hUSBDevice, &Out_Packet, dwBytesWriteRequest, &dwBytesSucceed);
       
        if (dwBytesSucceed != dwBytesWriteRequest || status != SI_SUCCESS)
        {               
                CString sError;
                sError.Format("Error writing to USB. Wrote %d of %d bytes. Application is aborting. Reset hardware and try again.", dwBytesSucceed, dwBytesWriteRequest);               
        }

}
但是当我通过MCU给PC发数据时,这样写可以吗?
void CUsb_LedDlg::OnButtonRx()
{
        SI_STATUS status = SI_SUCCESS;
        DWORD dwBytesSucceed = 0;
        DWORD dwBytesWriteRequest =8;
        BYTE In_Packet[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
        status = SI_Read(m_hUSBDevice, &In_Packet, dwBytesWriteRequest, &dwBytesSucceed);
       
        if (dwBytesSucceed != dwBytesWriteRequest || status != SI_SUCCESS)
        {               
                CString sError;
                sError.Format("Error writing to USB. Wrote %d of %d bytes. Application is aborting. Reset hardware and try again.", dwBytesSucceed, dwBytesWriteRequest);               
        }
        if(In_Packet[0] != 0x00)
        {
                MessageBox("正确,数据连接了","welcome",NULL);       
        }
        else MessageBox("错误,没连接","welcome",NULL);
       
}

上面只是验证一下收没收到数据,可是一点按钮他就卡了。没反应了。PC给MCU发送各种数据都正常。我只是想通过它验证接收数据正常与否。这样写对吗?
单片机上面的中断估计对的。
void         USB_API_TEST_ISR(void)        interrupt        16
{
        BYTE        INTVAL        =        Get_Interrupt_Source();        //        Determine type of API interrupts
        if (INTVAL & TX_COMPLETE)
        {
                Block_Write(In_Packet, 8);
        }
        if (INTVAL & RX_COMPLETE)
        {
                Block_Read(Out_Packet, 8);
        }
}
要用定时刷新????还是怎么改,求例程,求大侠。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。