【发布时间】:2013-04-09 23:50:24
【问题描述】:
我已经看到这个问题被问了几次,但我似乎无法理解为什么这不起作用。请帮助一个菜鸟(并且要温柔!)。我只是想创建一个类来接受 COM 端口的名称,然后在该端口上启动一个串行对象。我不断收到“Conex 不包含接受 1 个参数的构造函数”错误,尽管在我看来这就是它所包含的全部内容。想法?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
namespace Conex_Commands
{
public class Conex
{
string NewLine = "\r";
int BaudRate = 921600, DataBits = 8, ReadTimeout = 100, WriteTimeout = 100;
Parity Parity = Parity.None;
StopBits StopBits = StopBits.One;
public Conex(string PortName)
{
SerialPort Serial = new SerialPort(PortName, BaudRate, Parity, DataBits, StopBits);
Serial.ReadTimeout = ReadTimeout;
Serial.WriteTimeout = WriteTimeout;
Serial.NewLine = NewLine;
}
}
}
我的main中包含的调用代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Conex_Commands;
namespace Tester
{
class Program
{
static void Main(string[] args)
{
Conex abc = new Conex("COM5");
}
}
}
【问题讨论】:
-
请同时显示给您错误的调用代码,而不仅仅是 Conex 类。
-
是否有两种类型都命名为 Conex?与您在此处显示的类在同一程序集中进行构造的代码吗?
-
检查您是否编译了项目 - 如果它被“遗漏”,则在配置管理器中未选中
-
添加了调用 - 它肯定正在编译并在配置管理器中检查。
标签: c# class constructor