Visual studio 通过串口从FTDI读取数据
我正试图通过串口将实时传感器数据从FTDI读取到C#。我已经执行了这个代码,但是我没有得到任何数据。我已经为串行端口设置了参数:Visual studio 通过串口从FTDI读取数据,visual-studio,ftdi,Visual Studio,Ftdi,我正试图通过串口将实时传感器数据从FTDI读取到C#。我已经执行了这个代码,但是我没有得到任何数据。我已经为串行端口设置了参数: 波特率:115200 数据位:8 停止位:1 真的吗 真的吗 是否需要添加FTDI库来读取数据 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Draw
- 波特率:115200
- 数据位:8
- 停止位:1
- 真的吗
- 真的吗
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.Timers;
using System.IO.Ports;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
double[] a = new double[30];
public Form1()
{
InitializeComponent();
serialPort1.PortName = "COM5";
serialPort1.DataReceived += serialPort1_DataReceived;
}
public void configrations()
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
serialPort1.Open();
}
int x = 0;
int y = 0;
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
int dataLength = serialPort1.BytesToRead;
byte[] dataRecevied = new byte[dataLength];
int nbytes = serialPort1.Read(dataRecevied, 0, dataLength);
string line1 = Convert.ToString(nbytes * 10000);
this.BeginInvoke(new LineReceivedEvent(LineReceived), line1);
}
catch { }
}
private delegate void LineReceivedEvent(string line1);
private void LineReceived(string line1)
{
label1.Text = line1;
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Close();
}
}
}
是的,你需要一个图书馆(如果你还没有的话)。请参阅以获取更多帮助