N
N
NeoLight22021-02-03 21:51:58
C++ / C#
NeoLight2, 2021-02-03 21:51:58

When trying to initialize an object of the SerialPort class, it gives an error, what should I do?

I'm writing a plugin in Unity3D.
I want to receive data from a sensor that is connected via USB to a PC (COM3).

SerialPort port = new SerialPort();
            port.PortName = "COM3";            // assign the port name 
            port.BaudRate = 9600;               // Baudrate = 9600bps
            port.Parity = Parity.None;        // Parity bits = none  
            port.DataBits = 8;                  // No of Data bits = 8
            port.StopBits = StopBits.One;
            port.Open();
            port.Write("gettemp");
            Reference.Tell(args.sender.networkPlayer, $"Temp: {port.ReadLine()}");

But when trying to initialize an object of the SerialPort class, it gives the following error:
Invalid IL code in System.IO.Ports.SerialPort:.ctor() : Method body is Empty.

How to solve this problem?

PS Unity 5.6, .NET 4.0

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question