Hi !
I send bytes to my arduino (with an interval ) via the serial with unity. All is fine except after some seconds
the framerate fall under 5 fps
I don’t know why here I use the invokerepeating method, I have also use an time interval in the update but the result is the same
the framerate fall…
I am interested in a solution
Thanks in advance !
using UnityEngine;
using System.Collections;
using System.IO.Ports;
using System.IO;
public class Com : MonoBehaviour {
public bool outputToSerial=true;
public byte m1_1=0;
public byte m1_2=0;
public byte m2_1=0;
public byte m2_2=0;
SerialPort sp = new SerialPort("COM6", 9600);
void Start () {
sp.Open();
InvokeRepeating("RepeatingSend", 1, 0.2f);
}
void RepeatingSend () {
SendToSerial((byte) m1_1,(byte) m1_2,(byte) m2_1,(byte) m2_2);
}
void SendToSerial(params byte[] cmd)
{
if (outputToSerial)
{
if (sp.IsOpen){
try {
sp.Write( cmd, 0, cmd.Length );
}
catch (System.Exception ex)
{
Debug.LogWarning(ex);
}
}
}
}
}