给一个自己在C#下的解析代码,只针对帖子中的G代码功能,其它的陆续改进中:
{
string str=tSource.Text;
string[] sArray = new string[9];
System.IO.StreamReader objFileR = new System.IO.StreamReader(System.AppDomain.CurrentDomain.BaseDirectory +
@"cod.txt", true);//第二个参数用于指明创建文件的方式 false 新建,true 在原文件后插入
//str=str.Replace(" ","");
//str = str.Substring(4, str.Length - 4);
//tSource.Text=str;
//sArray = Regex.Split(str, "Y", RegexOptions.IgnoreCase);
//tXvalue.Text = sArray[0];
//tYvalue.Text = sArray[1];
Bitmap bitmap = new Bitmap(550, 550);
Graphics g = Graphics.FromImage(bitmap);
Pen myPen = new Pen(Color.Green, 2); //创建画笔
Pen bluePen = new Pen(Color.Blue, 2);
g.TranslateTransform(pPrint.Width / 2, pPrint.Height / 2); //坐标平移
g.RotateTransform(-180);
//g.DrawEllipse(bluePen, new Rectangle(-100, -100, 200, 200));
Int32 oldX=0, oldY=0;
do
{
tSource.Text = objFileR.ReadLine();
str = tSource.Text;
//str = str.Substring(4, str.Length - 4);
//tSource.Text = str;
str = str.Replace("X", ",");
str = str.Replace("Y", ",");
str = str.Replace("F", ",");
sArray = Regex.Split(str, ",", RegexOptions.IgnoreCase);
tXvalue.Text = sArray[1];
tYvalue.Text = sArray[2];
if (sArray[0] == "G01")
{
g.DrawLine(myPen, new Point(-1*oldX / 20, oldY / 20), new Point(-1*(Int32)float.Parse(tXvalue.Text) / 20, (Int32)float.Parse(tYvalue.Text) / 20));
}
oldX = (Int32)float.Parse(tXvalue.Text);
oldY = (Int32)float.Parse(tYvalue.Text);
} while (!(objFileR.EndOfStream));
objFileR.Close();
pPrint.Image = bitmap;
}
|