First example: read test

See C++ FX22MB_REG0_START_TX example.

Second example: write test

See C++ FX22MB_REG0_START_RX example.

Third example: select module, read firmware version, read VID/PID

This example program implements a simple console that

  1. creates an instance (TE_USB_FX2_USBDevice) initialized to null of the class CyUSBDevice
  2. reads and displays the number of Trenz Electronic modules (TE_USB_FX2_ScanCards())
  3. selects the first (0) Trenz Electronic module: modifies the instance of the class CyUSBDevice, making this instance different from null and properly initialized with the data of the selected Trenz Electronic module. If no module is attached, the instance remains initialized to null.
  4. reads and displays VID and PID of the selected module
  5. reads the firmware version of the selected module
  6. selects the second (1) Trenz Electronic module: modifies the instance of class CyUSBDevice to represent the new selected Trenz Electronic module. If the selected module is not attached, the instance is reinitialized to null and the reference to the previous module (0) is lost.
  7. reads the FPGA firmware version of the second (1) module

 

// This line creates a concrete class that is able to manage one single FX2
//device (one single Trenz module)
CyUSBDevice TE_USB_FX2_USBDevice = null;
//This line creates a list of USB device that are used through Cypress driver
USBDeviceList USBdevList = new USBDeviceList(CyConst.DEVICES);
//This line read the number of modules (cards) that are identified by VID and PID //as Trenz Electronic modules
int NumberOfCardAttached = TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_ScanCards(ref USBdevList);
Console.WriteLine("The number of card is {0} ", NumberOfCardAttached);
//If you want use the first Trenz Electronic module use 0
if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open(ref TE_USB_FX2_USBDevice, ref USBdevList, 0) == false) Console.WriteLine("Module is not connected!");
else Console.WriteLine("Module is connected!");
byte[] Command = new byte[64];
byte[] Reply = new byte[64];
int CmdLength = 64;
int ReplyLength = 64;
// Timeout of 1000 milliseconds
uint TIMEOUT_MS = 1000;
if (TE_USB_FX2_USBDevice == null)
{
	Console.WriteLine("Error,no device is selected");
	return;
}
else
{
	UInt16 VID = TE_USB_FX2_USBDevice.VendorID;
	Console.WriteLine("VID {0:X4} e ", VID);
	UInt16 PID = TE_USB_FX2_USBDevice.ProductID;
	Console.WriteLine("PID {0:X4} e ", PID);
}
//comand read FX2 version
Command[0] = (byte)FX2_Commands.READ_VERSION;
Console.WriteLine("cmd[0] {0:X2} ", cmd[0]);
if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand(ref TE_USB_FX2_USBDevice, ref Command, ref CmdLength, ref Reply, ref ReplyLength, TIMEOUT_MS) == true)
{
	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]);
		Console.WriteLine("Major version: {0}", Reply[0]);
		Console.WriteLine("Minor version: {0}", Reply[1]);
		Console.WriteLine("Device hi: {0}", Reply[2]);
		Console.WriteLine("Device lo: {0}", Reply[3]);
	}
}
else
	//cout << "Error" << endl;
	Console.WriteLine("Error");
	
//If you want use the first Trenz Electronic module use 1
if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open(ref TE_USB_FX2_USBDevice, ref USBdevList, 1) == false) Console.WriteLine("Module is not connected!");
else Console.WriteLine("Module is connected!");
if (TE_USB_FX2_USBDevice == null)
{
	Console.WriteLine("Error,no device is selected");
	return;
}
//byte cmd[64], reply[64];
byte[] Command1 = new byte[64];
byte[] Reply1 = new byte[64];
int CmdLength1 = 64;
int ReplyLength1 = 64;
uint TIMEOUT_MS1 = 1000;
//Here two alternatives to initialize Command1 are shown
byte MB_I2C_ADRESS = 0x3f;
byte I2C_BYTES = 12;
Command1[0] = (byte)FX2_Commands.SET_INTERRUPT;
Command1[1] = MB_I2C_ADRESS;
Command1[2] = I2C_BYTES;
if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand(ref TE_USB_FX2_USBDevice, ref Command1, ref Cmdlength1, ref Reply1, ref ReplyLength1, TIMEOUT_MS) == false)
{
	//cout << "Error" << endl;
	Console.WriteLine("Error Send Command SET INTERRUPT");
	return;
}
Command1[0] = 0xAD;//comand I2C_WRITE
Command1[3] = 0;
Command1[4] = 0;
Command1[5] = 0;
Command1[6] = 1; //get FPGA version
if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand(ref TE_USB_FX2_USBDevice, ref Command1, ref CmdLength1, ref Reply1, ref ReplyLength1, TIMEOUT_MS) == false)
{
	//cout << "Error" << endl;
	Console.WriteLine("Error Send Command Get FPGA Version");
	return;
}
Command1[0] = 0xB1;//comand (byte)FX2_Commands.GET_INTERRUPT
if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand(ref TE_USB_FX2_USBDevice, ref Command1, ref CmdLength1, ref Reply1, ref ReplyLength1, TIMEOUT_MS) == true)
{
	if ((ReplyLength1 > 4) && (Reply1[0] != 0))
	{
		//Console.WriteLine("INT# : {0}", reply[0]);
		Console.WriteLine("Major version: {0}", Reply1[1]);
		Console.WriteLine("Minor version: {0}", Reply1[2]);
		Console.WriteLine("Release version: {0}", Reply1[3]);
		Console.WriteLine("Build version: {0}", Reply1[4]);
	}
}
else Console.WriteLine("Error, GET INTERRUPT"); 
  • No labels