Hi Everybody,
I am a newbie in Unity but have experience of 10 years of s/w development. I want to use serial communication in one of my unity project. The data is coming at every 40ms , when i use readline() without any waiting(coroutine) the framerate goes to 3fps, with coroutinethe frame is okay but the serial data get jumbled/ overlapped. has anybody had similar experience? if yes what was the solution that you used.
Thanks
Subhash
This time I am trying SerialDataReceivedEventHandler but there is no output.
I am pasting my code here,
using UnityEngine;
using System.Collections;
using System.IO.Ports;
using System.IO;
public class SerialCom : MonoBehaviour
{
SerialPort MySerial;
float time;
string filePath;
public string comdata = “”;
void Start ()
{
MySerial = new SerialPort (“COM1”, 28800, Parity.None, 8, StopBits.One);
MySerial.DataReceived += new SerialDataReceivedEventHandler (DataReceviedHandler);
// MySerial.DtrEnable = true;
//MySerial.RtsEnable = true;
MySerial.Open ();
}
// Update is called once per frame
void Update ()
{
MySerial.DataReceived += new SerialDataReceivedEventHandler (DataReceviedHandler);
}
void DataReceviedHandler (object sender, SerialDataReceivedEventArgs e)
{
print (“data received”);
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting ();
Debug.Log (“Data Received:” + indata);
}
thanks
Subhash
The same concern. . . I hope someone can reply. .