- Home /
Question by
andrezatrum · Jul 30, 2017 at 04:31 PM ·
system.ioserialportioexception
error with system.io.ports
Good morning greetings from America Latina
I have this code and I get error when I run, I'm working with virtual reality and I want to pass the sensor data to unity ... (sorry for my english if it's bad)
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
public class Mputest : MonoBehaviour {
private float AmountToMove;
public float y;
public float z;
public float x;
public float q;
SerialPort serial = new SerialPort("COM4", 9600);
//Parity.None,8,StopBits.One
// Use this for initialization
void Start () {
serial.Open ();
serial.ReadTimeout = 20000;
}
// Update is called once per frame
void Update () {
if (!serial.IsOpen)
serial.Open (); //Here comes error
serial.Write ("a");
float AcX = int.Parse (serial.ReadLine ());
serial.Write ("b");
float AcY = int.Parse (serial.ReadLine ());
serial.Write ("c");
float AcZ = int.Parse (serial.ReadLine ());
serial.Write ("d");
float GyX = int.Parse (serial.ReadLine ());
serial.Write ("e");
float GyY = int.Parse (serial.ReadLine ());
serial.Write ("f");
float GyZ = int.Parse (serial.ReadLine ());
z = AcY/-200;
y = GyZ/146;
x = GyY/172;
/*x = AcX/300;
y += GyY/30000;
z += GyX/4000;
-2400 184 4777 86 -73 39
Data is printed as: acelX acelY acelZ giroX giroY giroZ*/
transform.localEulerAngles = new Vector3 (-x, -y, -z);
}
}
Comment
Your answer
Follow this Question
Related Questions
OnPostProcessBuild IOException 2 Answers
System.IO.Ports missing for Unity with .NET 4.x 3 Answers
File.Move wont work , error. IOException: Win32 IO returned ERROR_ALREADY_EXISTS. Path: 1 Answer
System.IO.FileInfo 1 Answer
How to check if File in streamingassets has exact same name as another variable/gameobject? 0 Answers