See C++ FX22MB_REG0_START_TX example.
See C++ FX22MB_REG0_START_RX example.
This example program implements a simple console that
Code Block | ||
---|---|---|
| ||
//This line creates a list of USB device that are used through |
...
Cypress driver |
...
CCyUSBDevice *USBDeviceList = new CCyUSBDevice((HANDLE)0,CYUSBDRV_GUID,true); |
...
unsigned long Timeout = 1000; |
...
int NumberOfCardAttached = TE_USB_FX2_ScanCards(USBDeviceList); |
...
cout << endl << NumberOfCardAttached << endl; |
...
//If you want use the first Trenz Electronic module use 0 |
...
if (TE_USB_FX2_Open(USBDeviceList, 0)==0) |
...
cout << "Module is connected!" <<endl; |
...
else |
...
cout << "Module is not connected!" <<endl; |
...
//USBDevice->Open(CypressDeviceNumber); it is used in |
...
TE_USB_FX2_Open() |
...
int vID = USBDeviceList->VendorID; |
...
int pID = USBDeviceList->ProductID; |
...
cout << "VID" << vID << endl; |
...
cout << "PID" << pID << endl; |
...
byte Command[64], Reply[64]; |
...
long CmdLength = 64; |
...
long ReplyLength = 64; |
...
Command[0] = 0x00;//comand read FX2 version |
...
if (!TE_USB_FX2_SendCommand(USBDevicelist, Command, CmdLength, Reply, ReplyLength, Timeout)) |
...
{ if (ReplyLength >= 4) |
...
{ printf("Major version: %d \n", Reply[0]); |
...
printf("Minor version: %d \n", Reply[1]); |
...
printf("Device hi: %d \n", Reply[2]); |
...
printf("Device lo: %d \n", Reply[3]); |
...
} } else cout << "Error" << endl; |
...
//If you want use the first Trenz Electronic module use 1 |
...
if (TE_USB_FX2_Open(USBDeviceList, 1)==0) |
...
cout << "Module is connected!" <<endl; |
...
else |
...
cout << "Module is not connected!" <<endl; |
...
byte Command1[64], Reply1[64]; |
...
long CmdLength1 = 64; |
...
long ReplyLength1 = 64; |
...
Command1[0] = SET_INTERRUPT; //0xB0;//comand SET_INTERRUPT |
...
Command1[1] = MB_I2C_ADRESS; //0x3F;//I2C slave address |
...
Command1[2] = I2C_BYTES;//12;//12 bytes payload |
...
if (TE_USB_FX2_SendCommand(USBDeviceList, Command1, CmdLength1, Reply1, ReplyLength1, Timeout)) |
...
cout << "Error Send Command SET INTERRUPT" << endl; |
...
Command1[0] = I2C_WRITE; //0xAD;//comand I2C_WRITE |
...
//Command1[1] = MB_I2C_ADRESS; //0x3F;//I2C slave address |
...
//Command1[2] = I2C_BYTES; //12 bytes payload |
...
Command1[3] = 0; |
...
Command1[4] = 0; |
...
Command1[5] = 0; |
...
Command1[6] = FX22MB_REG0_GETVERSION; //1; //get FPGA version |
...
if (TE_USB_FX2_SendCommand(USBDeviceList, Command1, CmdLength1, Reply1, ReplyLength1, Timeout)) |
...
cout << "Error Send Command Get FPGA Version" << endl; |
...
Command[0] = GET_INTERRUPT; //0xB1;//comand GET_INTERRUPT |
...
if (!TE_USB_FX2_SendCommand(USBDeviceList, Command1, CmdLength1, Reply1, ReplyLength1, Timeout)) |
...
{ if ((ReplyLength1 > 4) &&(Reply1[0] != 0)) |
...
{ printf("Major version: %d \n", Reply1[1]); |
...
printf("Minor version: %d \n", Reply1[2]); |
...
printf("Release version: %d \n", Reply1[3]); |
...
printf("Build version: %d \n", Reply1[4]); |
...
} } else cout << "Error, GET INTERRUPT" << endl; |