Boson
Boson
CC#
Created by Boson on 12/30/2022 in #help
❔ Serial Communication
juat nothing is being read
4 replies
CC#
Created by Boson on 12/30/2022 in #help
❔ Serial Communication
I have checked data is being sent on the COM3 port correctly
4 replies
CC#
Created by Boson on 12/29/2022 in #help
❔ crashing
That’s the original code
15 replies
CC#
Created by Boson on 12/29/2022 in #help
❔ crashing
using UnityEngine;
using System.Collections;
using System.IO.Ports;
using System.IO;
using System;
using System.Linq;
using System.Collections.Generic;

public class Arduino : MonoBehaviour
{
SerialPort sp = new SerialPort("COM3", 9600);

void Start() //called once when the program is run
{
sp.Open();
}

void Update() //called once every frame
{
if (sp.IsOpen)
{
try
{
serialEvent(sp);
}
catch (Exception)
{
throw;
}
}

}

void serialEvent(SerialPort myPort)
{
string myString = myPort.ReadLine();
if (myString != null)
{
Debug.Log("Read " + myString);
}
}
}
using UnityEngine;
using System.Collections;
using System.IO.Ports;
using System.IO;
using System;
using System.Linq;
using System.Collections.Generic;

public class Arduino : MonoBehaviour
{
SerialPort sp = new SerialPort("COM3", 9600);

void Start() //called once when the program is run
{
sp.Open();
}

void Update() //called once every frame
{
if (sp.IsOpen)
{
try
{
serialEvent(sp);
}
catch (Exception)
{
throw;
}
}

}

void serialEvent(SerialPort myPort)
{
string myString = myPort.ReadLine();
if (myString != null)
{
Debug.Log("Read " + myString);
}
}
}
15 replies
CC#
Created by Boson on 12/29/2022 in #help
❔ crashing
Sorry I meant while (true)
15 replies
CC#
Created by Boson on 12/29/2022 in #help
❔ crashing
Any idea how to prevent this code from crashing?
SerialPort sp = new SerialPort("COM3", 9600);
sp.Open();

While true()
{
if (sp.IsOpen)
{
try
{
serialEvent(sp);
}
catch (Exception)
{
throw;
}
}

}

void serialEvent(SerialPort myPort)
{
string myString = myPort.ReadLine();
if (myString != null)
{
Debug.Log("Read " + myString);
}
}
SerialPort sp = new SerialPort("COM3", 9600);
sp.Open();

While true()
{
if (sp.IsOpen)
{
try
{
serialEvent(sp);
}
catch (Exception)
{
throw;
}
}

}

void serialEvent(SerialPort myPort)
{
string myString = myPort.ReadLine();
if (myString != null)
{
Debug.Log("Read " + myString);
}
}
15 replies