Aber Vielleicht bleibe ich doch bei RS232. Hier ist mein Code. Hoffentlich weiß jemand, wie ich es verbessern könnte. Ich verwende einen 6 Byte buffer und das Data_Recive Event wird nach 5 empfangenen Bytes ausgelöst.
Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO.Ports; using NationalInstruments; using NationalInstruments.UI; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public static double Messwert; public static int werte = 0; public static double[] dataValues = new double[200]; public Form1() { InitializeComponent(); serialPort1.Open(); } private delegate void SetTextDeleg(double text); public void serialPort1_DataReceived_1(object sender, SerialDataReceivedEventArgs e) { double messval = messen(); this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { messval }); waveformGraph1.PlotY(dataValues, 0, 10, 0, 5); } private void si_DataReceived(double data) { label1.Text = data.ToString(); meter1.Value = data; } public double messen() { string mess = ""; mess = serialPort1.ReadTo("a"); serialPort1.DiscardInBuffer(); try { Messwert = Convert.ToDouble(mess) / 1023 * 5.07*2.794; dataValues[i] = Messwert; i++; } catch { serialPort1.DiscardInBuffer(); } return Messwert; } } }







Zitieren


Lesezeichen