This is the Visual studio Code. When i put a breakpoint on bytestoRed() it finds nothing. When I do it with my Arduino Uno it does find something.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.IO.Ports;
namespace eindwerk
{
class VStoARDUINO
{
private bool _closing;
private bool _kinectConnected;
private bool blnPortcanopen = false;
private bool sendDatabyte = true;
public bool stopReading = false;
public bool stopSending = false;
private SerialPort sp;
public string IncomingData;
private Thread SendThread;
private Thread ReadThread;
public bool bErrorOccured = false;
public List<string> rawdata = new List<string>();
string senddata;
public VStoARDUINO(string comport)
{
sp = new SerialPort(comport,115200, Parity.None, 8, StopBits.One);
}
public void OpenConnection()
{
if (sp != null)
{
if (sp.IsOpen)
{
Console.WriteLine("port already open");
}
else
{
try
{
sp.Open();
blnPortcanopen = true;
}
catch (Exception e)
{
Console.WriteLine(e);
blnPortcanopen = false;
bErrorOccured = true;
}
if (blnPortcanopen)
{
sp.ReadTimeout = 20;
Console.WriteLine("port opend!");
}
}
}
else
{
Console.WriteLine("port == null");
}
}
#region threads
public void startreading()
{
ReadThread = new Thread(threadReading);
ReadThread.Start();
}
public void startSending(string data)
{
senddata = data;
SendThread = new Thread(threadSending);
SendThread.Start();
}
void threadReading()
{
while (!stopReading)
{
if (blnPortcanopen)
{
if (sp.BytesToRead > 0)
{
try
{
IncomingData = sp.ReadLine();
if (IncomingData == "allsend")
{
rawdata.Add("test");
stopReading = true;
}
else
{
string data = IncomingData.Remove(IncomingData.Length - 1);
rawdata.Add(data);
}
}
catch {
bErrorOccured = true;
}
}
}
}
}
void threadSending()
{
while (!stopReading)
{
if (blnPortcanopen)
{
if (sendDatabyte == true)
{
try
{
sp.Write(senddata);
sendDatabyte = false;
}
catch (Exception)
{
bErrorOccured = true;
}
}
}
}
}
#endregion
public void onApplicationQuit()
{
stopReading = true;
blnPortcanopen = false;
sendDatabyte = true;
stopSending = true;
try
{
if (sp != null) sp.Close();
}
catch {
bErrorOccured = true;
}
}
}
}