gpt4 book ai didi

c# - 在linux上使用mono运行VS编译的C#(串行连接)文件

转载 作者:太空宇宙 更新时间:2023-11-04 03:41:03 24 4
gpt4 key购买 nike

据我所知,应该可以使用 C# mono 在 Linux 上运行 Visual Studio 编译的 C# 文件。我使用 apt-get install mono-complete 安装了它,所以所有内容都应该包含在内

但是,我确实遇到了一些未处理的异常错误,我自己也不明白,我希望有人能够帮助我。我应该注意到,一切都在 Windows 机器上按预期工作,并且我已经补偿了端口等,因此它应该适合 Linux。

我的设置如下:

_serialPort = new SerialPort();
_serialPort.PortName = SetPortName(_serialPort.PortName);
_serialPort.BaudRate = 115200;
_serialPort.StopBits = StopBits.One;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.Handshake = 0;
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();

我得到的错误是:

System.IO.IOException: Invalid argument
at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000] in <filename unknown>:0
at System.IO.Ports.SerialPortStream.SetSignal (SerialSignal signal, Boolean value) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:SetSignal (System.IO.Ports.SerialSignal,bool)
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at TivaCOM.setup () [0x00000] in <filename unknown>:0
at TivaCOM.Main () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Invalid argument
at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000] in <filename unknown>:0
at System.IO.Ports.SerialPortStream.SetSignal (SerialSignal signal, Boolean value) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:SetSignal (System.IO.Ports.SerialSignal,bool)
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at TivaCOM.setup () [0x00000] in <filename unknown>:0
at TivaCOM.Main () [0x00000] in <filename unknown>:0

If someone could help me out I would be very grateful

最佳答案

首先,您的 VS C# exe 很可能是使用 Windows 依赖项编译的,尤其是在谈论 USB 和串行端口等硬件时,平台之间存在大量差异。如果您有源代码,那么您可以尝试此线程 How to convert a .NET exe to native Win32 exe? 中建议的方法,编译代码而不编译原生部分。

如果您没有源代码并且只有 exe,则需要使用 wine 方法在 wine 中运行代码。关于如何设置linux串口设备和wine(windows COMXX设备)的对应关系可以引用下面的帖子http://ubuntuforums.org/showthread.php?t=1335098 。如果您使用的是最新的 Linux 发行版,则必须通过将用户添加到拨出组来允许用户访问 ttySXX 端口。

关于c# - 在linux上使用mono运行VS编译的C#(串行连接)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29623342/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com