我在同一行使用下面的代码得到以下两个错误port.WriteLine(gcode);
,我是否需要为列表的每个项目创建一个 for 循环?
'System.IO.Ports.SerialPort.WriteLine(string)' 的最佳重载方法匹配有一些无效参数
参数 1:无法从 'System.Collections.Generic.List' 转换为 'string'
代码:
//Fields
SerialPort port;
string myReceivedLines;
protected override void SolveInstance(IGH_DataAccess DA)
{
List<string> gcode = new List<string>();
DA.GetDataList(0, gcode);
if (!DA.GetDataList(0, gcode))
return;
port = new SerialPort(selectedportname, selectedbaudrate, Parity.None, 8, StopBits.One);
port.DtrEnable = true;
port.Open();
port.DataReceived += this.portdatareceived;
if (gcode == null)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specify a valid GCode");
return;
}
if (connecttodevice == true)
{
DA.SetDataList(0, myReceivedLines);
}
if (sendtoprint == true)
{
port.WriteLine(gcode);
}
}
private void portdatareceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
myReceivedLines = port.ReadExisting();
}