javascript:void(0);
Здравствуйте люди!
пытаюсь работать с контроллером от CYPRESS режиме SLAVE FIFO
вот часть кода С++
CCyUSBDevice *FX2Device;
int main(int argc, char* argv[])
{
FX2Device = new CCyUSBDevice(Handle);
return 0;
возникает ошибка доступа к памяти
(похожа на ту когда выходиш за пределы массива)
компилятор указывает на строку
FX2Device = new CCyUSBDevice(Handle);
самое интересное что на соседнем компе код работает в таких же условиях ошибки не возникает
Помогите начинающему.
Алексей.
}
Не смешно!
я раньше работал с FT245, вынужден осваивать USB 2.0 Нужно очень быстро передать 34 000 байт с внешнего устройства.
Вот пример часть того что я пытаюсь запустить(списал с одного сайта)
код:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit7.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include "CyAPI.h"
#define USB_DEVICE_NAME "My Own design"
TForm7 *Form7;
static CCyUSBDevice *s_usb_device;
static CCyUSBEndPoint *s_in_fifo_endpoint, *s_out_fifo_endpoint;
static CCyControlEndPoint* s_control_endpoint;
static OVERLAPPED s_out_overlap, s_in_overlap;
static unsigned char *s_in_context, *s_out_context;
int s_has_to_close_out, s_has_to_close_in;
LONG s_buffer_size_out, s_buffer_size_in;
PUCHAR s_buffer_out, s_buffer_in;
// For now it is static, might change it to a dynamic later
void* usb_init(void) {
int i = 0;
CCyUSBDevice* s_usb_device = new CCyUSBDevice();
// open my device
if (s_usb_device->DeviceCount()) {
// search for all connected devices, and add the one that has the right name
for (i = 0; i < s_usb_device->DeviceCount(); i++) {
s_usb_device->Open(i);
if(strcmp (USB_DEVICE_NAME, s_usb_device->DeviceName) == 0)
break;
s_usb_device->Close();
}
} else {
// Cannot find my device
return NULL;
}
if (!s_usb_device->IsOpen()) {
// Could not open my device
return NULL;
}
// get usb IN and OUT FIFOs endpoints
int endpoints_count = s_usb_device->EndPointCount();
for (i=1; i<endpoints_count; i++) {
CCyUSBEndPoint *endpoint;
endpoint = s_usb_device->EndPoints[i];
if (endpoint->Attributes == 2) {
// it is a Bulk endpoint
if(endpoint->Address == 0x86) {
// my IN endpoint
s_in_fifo_endpoint = endpoint;
}
if(endpoint->Address == 0x02) {
// my OUT endpoint
s_out_fifo_endpoint = endpoint;
}
}
}
// get Control enpoint
s_control_endpoint = s_usb_device->ControlEndPt;
// create events for data transfers
s_out_overlap.hEvent = CreateEventA(NULL, false, false, "CYUSB_OUT");
s_in_overlap.hEvent = CreateEventA(NULL, false, false, "CYUSB_IN");
return (void*)1;
}
void usb_close() {
usb_finish_in_transfer();
usb_finish_out_transfer();
delete s_usb_device;
CloseHandle(s_out_overlap.hEvent);
CloseHandle(s_in_overlap.hEvent);
}
void usb_begin_out_transfer(unsigned char* buffer, int size) {
if (s_has_to_close_out == 1) {
s_out_fifo_endpoint->FinishDataXfer (s_buffer_out, s_buffer_size_out, &s_out_overlap,s_out_context);
}
s_buffer_out = buffer;
s_buffer_size_out = size;
s_out_context = s_out_fifo_endpoint->BeginDataXfer(s_buffer_out, s_buffer_size_out, &s_out_overlap);
s_has_to_close_out = 1;
}
void usb_begin_in_transfer(unsigned char* buffer, int size) {
if (s_has_to_close_in == 1) {
s_in_fifo_endpoint->FinishDataXfer(s_buffer_in, s_buffer_size_in, &s_in_overlap,s_in_context);
}
s_buffer_in = buffer;
s_buffer_size_in = size;
s_in_context = s_in_fifo_endpoint->BeginDataXfer(s_buffer_in, s_buffer_size_in, &s_in_overlap);
s_has_to_close_in = 1;
}
int usb_finish_in_transfer() {
if (s_has_to_close_in == 1) {
s_in_fifo_endpoint->FinishDataXfer(s_buffer_in, s_buffer_size_in, &s_in_overlap,s_in_context);
}
s_has_to_close_in = 0;
return s_buffer_size_in;
}
int usb_finish_out_transfer() {
if (s_has_to_close_out == 1) {
s_out_fifo_endpoint->FinishDataXfer(s_buffer_out, s_buffer_size_out, &s_out_overlap,s_out_context);
}
s_has_to_close_out = 0;
return s_buffer_size_out;
}
int usb_is_in_transfer_done() {
return s_in_fifo_endpoint->WaitForXfer(&s_in_overlap,1);
}
int usb_is_out_transfer_done() {
return s_out_fifo_endpoint->WaitForXfer(&s_out_overlap,1);
}
void usb_wait_in_transfer_finish() {
while(!s_in_fifo_endpoint->WaitForXfer(&s_in_overlap,1));
}
void usb_wait_out_transfer_finish() {
while(!s_out_fifo_endpoint->WaitForXfer(&s_out_overlap,1));
}
//---------------------------------------------------------------------------
__fastcall TForm7::TForm7(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm7::Button1Click(TObject *Sender)
{
usb_init();
}
//-
Рекомендую оборачивать код - иначе он нечитаемый