read from com port
Jeg har problemer med at når min kode når til ReadData = comport.ReadExisting(); så får jeg denne felj nogen der har en løsning på mit problem (An unhandled exception of type 'System.StackOverflowException' occurred in System.dll)public void InitializeBackgroundWorker()
{
backgroundWorker1.WorkerSupportsCancellation = true;
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
e.Result = readstring(worker, e); //Jeg kalder readstring
}
public void openport()
{
//, parity: Parity.Even, dataBits: 8, stopBits: StopBits.One
BaudRateInt = Convert.ToInt32(BaudRate);
comport = new SerialPort(portName: Port, baudRate: BaudRateInt);
//comport.ReadTimeout = 100000;
comport.Handshake = Handshake.None;
//comport.DataReceived += SerialDataReceivedEventHandler(readstring);
comport.Open();
}
string readstring(BackgroundWorker worker, DoWorkEventArgs e)
{
if (worker.CancellationPending)
{
e.Cancel = true;
}
else
{
if (results != "!PA1")
{
try
{
ReadData = comport.ReadExisting();
char[] delimiterChars = { ',' };
string[] words = ReadData.Split(delimiterChars);
data = words[0];
results = data;
readstring(worker, e);
}
catch (TimeoutException)
{
readstring(worker, e);
}
catch (IOException)
{
readstring(worker, e);
}
}
}
return ReadData;
}