我見過這個問題問了幾次,似乎無法得到我的頭爲什麼這是行不通的。請幫助noob(並且溫柔!)。我只是試圖創建一個類來接受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;
}
}
}
調用代碼包含在我的主要是:
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類。 – 2013-04-09 23:52:59
有兩種類型都叫做Conex?與您在此展示的課程在同一個程序集中進行施工的代碼是? – 2013-04-10 00:00:37
檢查您是否編譯了該項目 - 如果它被「遺漏」,則在配置管理器中取消選中 – NSGaga 2013-04-10 01:27:00