Reputation: 181
I have a Infenion XMC relax kit micro controller, I have a GUI made on visual studio(c#), I want to interface the GUI with the microcontroller. I have no idea how to proceed with this. This controller only has microusb input, so no serial port connection.
Any help will be appreciated or any suggestions for tutorial will be appreciated too.
Upvotes: 2
Views: 1977
Reputation: 35
If you have usb port on microcontroller, you can communicate with GUI running on PC or any other embedded device in two ways, either you use direct usb cable or you use COM port along with usb to UART converter which could be part of either your development board or external converter. If you have this converter on board then a serial port of your microcontroller must have used.
Case1: Direct USB - in this mode you need an usb library (such as libusb/winusb) on PC side which can interface your application with PC usb hardware. On the other hand, there should be usb library running on microcontroller which can do the same as PC usb library.
Case2: through COM port - install driver for usb to uart converter then you can find out your device connected in device manager, you can identify port number. You can scan connected com ports in your C# application or manually insert the exact com port and using serial library you can communicate with microcontroller.
Upvotes: 0
Reputation: 93476
From the documentation the board has two USB connectors; one is connected to the main XMC4500, the other is connected to a second XMC4500 acting as an on-chip debug interface. To communicate with your application you need to use the one connected to the main processor (marked "X3"), the other is for programming and debugging the device.
On its own the USB interface does nothing; USB requires a software stack implementing a device class. The simplest device class to implement (because your PC OS already has drivers for it) is a CDC/ACM (or virtual COM port). This will then allow you to exchange information with the board using the .NET System.IO.Ports.SerialPort
class.
There is mention of an USB VCP project here, though I cannot find the code referred to. Perhaps it is included with the dev kit and you already have it?
Note that if you do use the on-chip USB as a device, you will need a USB Vendor ID if you are going to distribute the product, unless Infineon allow developers to use the VID in their example code commercially.
Note that the part also has a UART (i.e. a real serial port) that would no doubt be simpler to get working and require much less software. The I/O for the UART can be mapped to a pair of GPIO pins then you can connect a TTL UART to USB bridge cable to that, and plug that straight into a PC serial port. This has the advantage of creating a USB connection without needing your own VID.
Upvotes: 2
Reputation: 1556
Try this code to read data and display it coming in on COM3....
// Create the serial port with basic settings....You will need to modify SerialPort("COM3",9600, Parity.None, 8, StopBits.One); to suit your device.
private SerialPort port = new SerialPort("COM3",
9600, Parity.None, 8, StopBits.One);
[STAThread]
static void Main(string[] args)
{
// Instatiate this class
new SerialPortProgram();
}
private SerialPortProgram()
{
Console.WriteLine("Incoming Data:");
// Attach a method to be called when there
// is data waiting in the port's buffer
port.DataReceived += new
SerialDataReceivedEventHandler(port_DataReceived);
// Begin communications
port.Open();
// Enter an application loop to keep this thread alive
int MyInt = System.Convert.ToInt32(Console.ReadLine());
byte[] b = BitConverter.GetBytes(MyInt);
port.Write(b, 0, 4);
Application.Run();
}
private void port_DataReceived(object sender,
SerialDataReceivedEventArgs e)
{
// Show all the incoming data in the port's buffer
Console.WriteLine(port.ReadExisting());
}
Upvotes: 1