.net - C# SerialPort EventHandler in Unity -


itemprop = "text">

I'm writing C # code for unity, just reading the SerialPort value in the EventHandler problem is that the handler is not called. Here is the code

  using UnityGen; Using System.Collections; Using the system; Using System.IO.Ports; Public Class Main Script: Monobahavik {Public Serial Port Merseyside Port; Public stable float speed = 100; Game Object Cube; Public GUIStyle style; // Initialization Use it for zero start () {cube = GameObject.FindGameObjectWithTag ("cube"); If (mySerialPort.IsOpen) mySerialPort.Close (); MySerialPort = New Serial Port ("com5"); MySerialPort.BaudRate = 9600; MySerialPort.Parity = Equality One; MySerialPort.StopBits = StopBits.None; MySerialPort.DataBits = 8; Messierport Airport Handshake = Handshake.No; MySerialPort.DataReceived + = New SerialDataReceivedEventHandler (DataReceivedHandler); If (mySerialPort.IsOpen == incorrect) mySerialPort.Open (); } Zero onGUI () {GUI.Box (new rect (100,100,100,100), "speed:" + speed, style); } // Update is called the one-time zero update () per speed (// speed = mySerialPort.ReadTo ("\ r"); // Update my view with the new visual cube. Transform.Rotate (Vector3.up * Speed ​​* Time.deltaTime);} Public static zero Datairisevandler (Object Sender, Serial Data Receive Event Eg E) {SerialPort sp = (SerialPort) Sender; Speed ​​= Float.Parse (sp.ReadTo ("\ r")); Print ("Data Received:" + Speed);}} The problem is not in the serial port, when I updated it for unity Read Hnkshn, it reads the correct value, but is a performance issue to update the UI. 

Thank you


Comments