I am attempting to do some force feedback with an arduino and decided to start simply by sending things to it via serial. That on its own gave me problems.
My script:
using UnityEngine;
using System.Collections;
using System.IO.Ports;
public class NewBehaviourScript : MonoBehaviour {
SerialPort sp = new SerialPort(“COM4”, 9600);
// Use this for initialization
void Start () {
sp.Open();
}
// Update is called once per frame
void Update () {
sp.Write(“25”);
}
}
gave me this error:
InvalidOperationException: Specified port is not open.
System.IO.Ports.SerialPort.CheckOpen ()
System.IO.Ports.SerialPort.Write (System.String str)
(wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Write (string)
NewBehaviourScript.Update () (at Assets/Scripts/NewBehaviourScript.cs:16)
tl;dr its telling me that the port isn’t open.
I am using the correct com port and I open the port in the script. I checked that the arduino is in fact on COM4. I have no idea what may be causing this, and I doubt it is something on the arduino side because reading serially from the arduino works perfectly fine when using the Arduino IDEs serial monitor.
To clear up one more thing: yes, i did change the player settings to use .NET 2.0 instead of .NET 2.0 subset.
I know my problem is me doing or missing something extremely stupid, but please bear with me.