Unity3d串口通信中遇到的两个问题及解决办法

  1. 关于"using System.IO.Ports;" 问题
    I want to conect with serial port but when I use “using System.IO.Ports;” I take this error I want to conect with serial port but when I use “using System.IO.Ports;” I take this error: I want to conect with serial port but when I use “using System.IO.Ports;” I take this error I want to conect with serial port but when I use “using System.IO.Ports;” I take this error:
    错误 1 The type or namespace name Ports' does not exist in the namespaceSystem.IO’. Are you missing an assembly reference?

The problem is the .net configuration, use the .NET 2.0 (not subset) and will connect.

具体解决方案如下:
Edit>ProjectSettings>Player>ApiCompatibilityLevel> change “.NET 2.0 (subset)” to "NET 2.0"

Then add a new PortControlScript, try it again.

  1. 关于COM Port Name问题。
    I have been using Unity and Arduino to perform serial communication for quite some time. And it has been working fine. Now I changed my Arduino board and thus the COM Port has changed on it. Arduino is communicating perfectly and sending all the right signals when checked in serial monitor. I have noticed to use the same port in Arduino and Unity. But I am getting this error in unity.
    IOException: The port ‘COM3’ does not exist.

具体解决方案如下:
If this is Windows OS then **try to specify the COM port name as:
myPort= new SerialPort("\\.\COM4",9600);
NOTES: This syntax also works for ports COM1 through COM9. Certain boards will let you choose the port names yourself. This syntax works for those names as well.

你可能感兴趣的:(Unity3d,Unity3d串口通信)