IOException:端口'\\。\ COM3'不存在

时间:2018-08-15 08:38:07

标签: c# .net unity3d il2cpp

我试图统一打开SerialPort。它正在编辑器和Mono版本中工作。但是当我使用iL2CPP脚本后端构建游戏时。它在消息The port \\.\COM3 does not exist.

中引发异常

这与Unity IL2CPP构建有关吗?

Unity播放器设置:

脚本运行时版本: .Net 4.x等效版本

API兼容性级别: .NET 4.x

public void OpenSerialPort()
{
    try
    {
        string ComPort = @"\\.\COM3"; //I even tried "COM3"
        int BaudRate = 9600;
        // Initialise the serial port
        SerialPort = new SerialPort(ComPort, BaudRate);
        SerialPort.ReadTimeout = ReadTimeout;
        SerialPort.WriteTimeout = WriteTimeout;
        SerialPort.DtrEnable = true;
        SerialPort.RtsEnable = true;
        // Open the serial port
        SerialPort.Open();

        Debug.LogError("SerialPort successfully opened!");
    }
    catch (UnauthorizedAccessException ex)
    {
        // Failed to open com port or start serial thread
        Debug.LogError("UnauthorizedAccessException: " + ex.Message.ToString());
    }
    catch (ArgumentOutOfRangeException ex)
    {
        // Failed to open com port or start serial thread
        Debug.LogError("ArgumentOutOfRangeException: " + ex.Message.ToString());
    }
    catch (ArgumentException ex)
    {
        // Failed to open com port or start serial thread
        Debug.LogError("ArgumentException : " + ex.Message.ToString());
    }
    catch (InvalidOperationException ex)
    {
        // Failed to open com port or start serial thread
        Debug.LogError("ArgumentException : " + ex.Message.ToString());
    }
    catch (IOException ex)
    {
        // Failed to open com port or start serial thread
        Debug.LogError("IOException : " + ex.Message.ToString());
    }
} 

0 个答案:

没有答案