0

From what I've heard it should be possible to run a visual studio compiled C# file on linux by using C# mono. I installed it using apt-get install mono-complete so everything should be included

I do however get some Unhandled Exception errors I do not understand myself and I hope that someone might be able to help me out. I should note that everything works as intended on a windows machine and that I have compensated ports and so on so it should fit linux instead.

My setup looks like :

_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();

and the errors I get are :

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
user3660570
  • 337
  • 1
  • 14

1 Answers1

0

First of all, most probably your VS C# exe is compiled with Windows dependencies and especially when talking about hardware like USB and serial ports, there are tons of differences between platforms. If you have the source code then you can try the suggested approach in this thread How to convert a .NET exe to native Win32 exe?, to compile the code without compiling the native part.

If you do not have the source code and you have just the exe, you need to use the wine approach where you run your code in wine. You can use the following post on how to set the correspondence between linux serial devices and wine ( windows COMXX devices) http://ubuntuforums.org/showthread.php?t=1335098. If you are using a recent linux distribution you will have to allow access to the ttySXX ports for your user by adding the user to the group dialout.

Community
  • 1
  • 1
JD_GRINDER
  • 344
  • 2
  • 6