- Home /
Question by
LeventeXXL · Aug 04, 2018 at 01:28 PM ·
c#arduinoport
Serial Port delay is getting longer
I want to read sensor data through the serial port (from an Arduino) and rotate my objects accordingly. This code works for a few seconds but there is a huge delay and its getting longer the more time it runs. I figured it's the reading and processing which takes so much time. It wouldn't be a bad thing to skip some data from time to time to make it run more smoothly, but I'm not sure how to do that. Any ideas?
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO.Ports;
public class Sensors : MonoBehaviour {
private SerialPort stream = new SerialPort("COM3", 115200);
private string value;
private string[] quat;
private float x, y, z, w;
public GameObject HeadDummy;
// Use this for initialization
void Start () {
stream.Open();
}
// Update is called once per frame
void Update () {
value = stream.ReadLine();
Debug.Log(value);
quat = value.Split('\t');
w = float.Parse(quat[0]);
x = float.Parse(quat[1]);
y = float.Parse(quat[2]);
z = float.Parse(quat[3]);
HeadDummy.transform.rotation = new Quaternion(w, x, y, z);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity and bluetooth? Is it possible w/o plugin? 1 Answer
Read in 2 Different Arduino Values 1 Answer