Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GUI与单片机的连接_C#_Visual Studio_Embedded_Microcontroller - Fatal编程技术网

C# GUI与单片机的连接

C# GUI与单片机的连接,c#,visual-studio,embedded,microcontroller,C#,Visual Studio,Embedded,Microcontroller,我有一个Infenion XMC RELAXKIT微控制器,我有一个在visual studio(c#)上制作的GUI,我想将GUI与微控制器连接起来。我不知道该怎么做。此控制器只有microusb输入,因此没有串行端口连接 任何帮助或对本教程的任何建议都将不胜感激。请尝试此代码读取数据并在COM3上显示 // Create the serial port with basic settings....You will need to modify SerialPort("COM3",9

我有一个Infenion XMC RELAXKIT微控制器,我有一个在visual studio(c#)上制作的GUI,我想将GUI与微控制器连接起来。我不知道该怎么做。此控制器只有microusb输入,因此没有串行端口连接


任何帮助或对本教程的任何建议都将不胜感激。

请尝试此代码读取数据并在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());
    }
从主板上有两个USB接口;一个连接到主XMC4500,另一个连接到作为片上调试接口的第二个XMC4500。要与应用程序通信,您需要使用连接到主处理器(标记为“X3”)的一个,另一个用于编程和调试设备

USB接口本身不起任何作用;USB需要实现设备类的软件堆栈。要实现的最简单的设备类(因为您的PC操作系统已经有了驱动程序)是CDC/ACM(或虚拟COM端口)。这将允许您使用.NET
System.IO.Ports.SerialPort
类与电路板交换信息

有提到一个USB VCP项目,尽管我找不到提到的代码。也许它包含在开发工具包中,而您已经拥有了它

请注意,如果您确实使用片上USB作为设备,则如果您要分发产品,则需要USB供应商ID,除非Infineon允许开发人员在其示例代码中以商业方式使用VID


请注意,该部件还有一个UART(即一个真正的串行端口),这无疑会更容易工作,并且需要的软件更少。UART的I/O可以映射到一对GPIO引脚,然后您可以连接到该引脚,并将其直接插入PC串行端口。它的优点是不需要自己的视频就可以创建USB连接。

如果微控制器上有USB端口,您可以通过两种方式与PC或任何其他嵌入式设备上运行的GUI通信,您可以使用直接usb电缆,也可以使用COM端口以及usb到UART转换器,该转换器可以是开发板或外部转换器的一部分。如果船上有此转换器,则必须使用微控制器的串行端口

案例1:直接USB-在这种模式下,您需要在PC端安装一个USB库(如libusb/winusb),它可以将您的应用程序与PC USB硬件连接起来。另一方面,在微控制器上应该有usb库,它可以和PC的usb库一样工作


案例2:通过COM端口-安装usb到uart转换器的驱动程序,然后您可以在设备管理器中找到连接的设备,您可以识别端口号。您可以扫描C#应用程序中连接的com端口,或手动插入准确的com端口,并使用串行库与微控制器通信。

当您将USB电缆插入microUSB时,它是如何安装在PC上的?它会自动安装所有驱动程序并获取IDE“Dave”自动安装后,系统上是否已安装COM?“我想将GUI与微控制器连接起来”这是什么意思?这是您制作的GUI还是工具链的一部分。不清楚您是在谈论编程工具还是应用程序。如果IDE是蹩脚的“Dave”,那么它应该是工具链的一部分。如果是这样,我有一个想法:阅读安装说明和手册!我写得很清楚,我用c语言在visual studio上制作了这个GUI;而且,虚拟COM端口不会枚举为COM3。