[英] In my C# app. I am reading the CNC program of a remote machine into a byte buffer. How can I read this byte buffer line by line in to a string array?
• csharp我可以用第三方DLL将远程机床的完整数控程序读取到字节缓冲区中.之后,我必须逐行读取字节缓冲区并将其传输到字符串array.(我不想将程序写到文件中,我想在Blazor页面中逐行显示程序行)
我编写了以下代码,将整个缓冲区读入一个字符串.但我不能把它分成几行.我怎么能做到这一点? 我通常应该阅读数控程序,例如:
G0 G603
AAA:
Z=IC(-50)
Z=IC(50)
GOTOB AAA级
M30
但我的代码是将cnc程序作为一行读取.
G0 G603 AAA: Z=IC(-50) Z=IC(50) GOTOB AAA级 M30
public Int32 doNCK_CopyFromNCAlloc(Int32 connnr, Int32 timeout, string path, out string CNC_File_Out)
{
Int32 result = 0;
Byte[] buff = null;
Int32 bufflen = 0;
String filename = path;
CNC_File_Out = "";
result = AGL4.NCK_CopyFromNCAlloc(connnr, filename, out buff, out bufflen, timeout);
if (result == 0)
{
b = buff;
parameter_value_string = BitConverter.ToString(b, 0);
parameter_value_string_UTF8 = System.Text.Encoding.UTF8.GetString(b);
CNC_File_Out= parameter_value_string_UTF8.Replace("\0", string.Empty);
}
Return_Read_CNC_File = result;
return result;
}
更新-1(字节输出如下所示)
47-30-20-47-36-30-33-0D-0A-41-41-41-3A-0D-0A-5A-3D-49-43-28-2D-35-30-29-0D-0A-5A-3D-49-43-28-35-30-29-0D-0A-47-4F-54-4F-42-20-41-41-41-0D-0A-4D-33-30-0D-0A-0D-0A