예제 #1
0
 public VirtualMachine()
 {
     Hotbed              = new HotBed();
     Extruder            = new Extruder();
     _comm               = Serial.Instance;
     _comm.DataReveived += _comm_DataReveived;
     Settings            = new VirtualMachineSettings();
 }
예제 #2
0
        private void ProcessReveivedData(string data)
        {
            string[] args = data.Split(' ').ToArray();

            switch (args[0])
            {
            case "M105":
                M105 m105 = CreateMCommandInstance <M105>(args[0], data);
                WritePort(string.Format(m105.Reply[0], Extruder.CurrentTemp, Extruder.TargetTemp, Hotbed.CurrentTemp, Hotbed.TargetTemp));
                break;

            case "M503":
                M503 m503 = CreateMCommandInstance <M503>(args[0], data);
                WritePort(m503.Reply);
                break;

            case "M92":
                M92 m92 = CreateMCommandInstance <M92>(args[0], data);
                Settings.AxisStepsPerUnit.SetAxisStepsPerUnit(m92);
                WritePort(string.Format(m92.Reply[0], m92.X, m92.Y, m92.Z, m92.E));
                break;

            case "M115":
                M115 m115 = CreateMCommandInstance <M115>(args[0], data);
                WritePort(m115.Reply);
                break;

            case "M114":
                M114 m114 = CreateMCommandInstance <M114>(args[0], data);
                WritePort(string.Format(m114.Reply[0], Extruder.X, Extruder.Y, Extruder.Z));

                break;

            case "M220":

                M220 m220 = CreateMCommandInstance <M220>(args[0], data);
                Settings.FeedRate.SetFeedRatePercent(m220);
                WritePort(string.Format(m220.Reply[0], Settings.FeedRate.FeedRatePercent));
                break;

            case "M221":
                WritePort("E0 Flow: 100%");
                break;

            case "G1":
                if (args.Count() == 1)
                {
                    WritePort("ok");
                }
                double X = 0;
                double Y = 0;
                double Z = 0;

                for (int a = 1; a <= args.Count() - 1; a++)
                {
                    if (args[a].StartsWith("X"))
                    {
                        X += Convert.ToDouble(args[a].Substring(1));
                    }

                    if (args[a].StartsWith("Y"))
                    {
                        Y += Convert.ToDouble(args[a].Substring(1));
                    }

                    if (args[a].StartsWith("Z"))
                    {
                        Z += Convert.ToDouble(args[a].Substring(1));
                    }
                }
                Extruder.MoveExtruder(X, Y, Z);
                WritePort("ok");
                break;

            case "M104":
                M104 m104 = CreateMCommandInstance <M104>(args[0], data);
                Extruder.SetHotEndTargetTemp(m104);
                WritePort("ok");
                break;

            case "M140":
                M140 m140 = CreateMCommandInstance <M140>(args[0], data);
                WritePort(m140.Reply[0]);
                break;

            default:
                WritePort("ok");
                break;
            }
        }