// declare, configure and open port
System.IO.Ports.SerialPort com = new System.IO.Ports.SerialPort();
com.PortName = "COM1";
com.BaudRate = 115200;
com.NewLine = "\n";
com.Open();
//read whole file content to string array
string[] lines = System.IO.File.ReadAllLines("c:\myfile.nc");
//iterate each element of array
foreach (string line in lines)
{
//write on serial line
System.Diagnostic:Debug.Write(line);
com.Write(line);
//wait for response
string rv = com.ReadLine();
System.Diagnostic:Debug.WriteLine(":" + rv);
}
嘿,我正在为 C# 上的 cnc 开发一个简单的 grbl 控制器,我想知道如何通过串行通信发送文件,类似于此
将 g 代码流式传输到 grbl
for line in f:
l = line.strip() # 去除所有 EOL 字符以保持一致性
print ‘Sending: ‘ + l,
s.write(l + ‘\n’) # 发送 g 代码块到 grbl
grbl_out = s. readline() # Wait for grbl response with carriage return
print ‘ : ‘ + grbl_out.strip()
https://github.com/grbl/grbl/blob/master/doc/script/simple_stream.py
我理解代码但是我不知道 C# 的翻译,我会感谢任何帮助或建议