이 질문을 몇 번 본 적이 있는데 왜 이것이 작동하지 않는지 내 머리를 터지게 할 수 없습니다. 멍청한 놈 도와주세요! COM 포트의 이름을 받아들이고 해당 포트에서 직렬 객체를 시작하는 클래스를 만들려고합니다. "Conex에는 하나의 인수를 허용하는 생성자가 포함되어 있지 않습니다."라는 오류가 계속 발생합니다. 생각? 내 주에 포함(아마도) 간단한 설명 - 생성자 정의 및 인수
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 클래스뿐만 아니라 오류를 발생시키는 호출 코드도 표시하십시오. –
Conex라는 두 가지 유형이 있습니까? 당신이 여기에 보여주는 수업과 같은 어셈블리에서 코드를 작성합니까? –
프로젝트를 컴파일했는지 확인하십시오. '빠져있다'면 구성 관리자 – NSGaga