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;namespace test_serialport
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
SerialPort1.Portname = "COM2";
SerialPort1.BaudRate = "9600"; }
}
}
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;namespace test_serialport
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
SerialPort1.Portname = "COM2";
SerialPort1.BaudRate = "9600"; }
}
}
BaudRate 是 int型
spPTZ.DataBits = 8;
spPTZ.PortName = "Com1";
spPTZ.ReadTimeout = 2000;
spPTZ.StopBits = System.IO.Ports.StopBits.One;没有问题啊。
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;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
spPTZ.BaudRate = 9600;
spPTZ.DataBits = 8;
spPTZ.PortName = "Com1";
spPTZ.ReadTimeout = 2000;
spPTZ.StopBits = System.IO.Ports.StopBits.One;
} private void textBox1_TextChanged(object sender, EventArgs e)
{ }
}
}可是这样提示“当前上下文不存在名称spPTZ”