Exemplo n.º 1
0
        private void btnOpenJ_Click(object sender, RoutedEventArgs e)
        {
            var openFile = new OpenFileDialog();

            openFile.FileName = CFiles.MotionParams;
            if (openFile.ShowDialog() == true)
            {
                JsonSerializer Jser    = new JsonSerializer();
                StreamReader   sr      = new StreamReader(openFile.FileName);
                JsonReader     Jreader = new JsonTextReader(sr);
                Xparam = Jser.Deserialize <MotionParams_Copy>(Jreader);
                sr.Close();
                CFiles.MotionParams = openFile.FileName;

                Xparam.CopyParams(KM.CoordMotion.MotionParams); // copy the motion parameters to the KM instance
                SetupWindow st1 = new SetupWindow(KM.CoordMotion.MotionParams);
                st1.Show();
            }
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            // create an instance of the KM controller - same instance is used in the entire app
            // ******** VERY IMPORTANT *********
            // inorder to make this work properly
            // the following files needed to be copied to the Debug1/Release1 directories
            // -- and the build output directories need to be changed to Debug1/Release1 - or at least something besides Debug/Release
            // KMotionDLL.dll
            // KMotion_dotNet.dll
            // KMotion_dotNet_Interop.dll
            // GCodeInterpreter.dll
            // KMotionServer.exe
            // TCC67.exe(This is the compiler for their DSP C code)
            // emc.var
            // \DSP_KFLOP Sub directory.
            //
            // also copy the DSP_KFLOP folder into Debug1/Release1
            // reference this wiki page https://www.dynomotion.com/wiki/index.php?title=PC_Example_Applications
            try
            {
                KM = new KMotion_dotNet.KM_Controller();
            }
            catch (Exception e)
            {
                MessageBox.Show("Unable to load KMotion_dotNet Libraries.  Check Windows PATH or .exe location " + e.Message);
                System.Windows.Application.Current.Shutdown();  // and shut down the application...
                return;
            }

            // copy of the motion parameters that the JSON reader can use.
            Xparam = new MotionParams_Copy();
            // get the configuration file names
            CFiles = new ConfigFiles();
            // check if the the config file exists
            if (File.Exists("KTestConfig.json") == true)
            {
                JsonSerializer Jser    = new JsonSerializer();
                StreamReader   sr      = new StreamReader("KTestConfig.json");
                JsonReader     Jreader = new JsonTextReader(sr);
                CFiles = Jser.Deserialize <ConfigFiles>(Jreader);
                sr.Close();
            }
            else
            {
                MessageBox.Show("No configureation file found");
                // what to do here?
                // Initialize the strings to null and save the file for next time
                SaveConfig(CFiles);
            }
            if (File.Exists(CFiles.MotionParams) == true)
            {
                JsonSerializer Jser    = new JsonSerializer();
                StreamReader   sr      = new StreamReader(CFiles.MotionParams);
                JsonReader     Jreader = new JsonTextReader(sr);
                Xparam = Jser.Deserialize <MotionParams_Copy>(Jreader);
                sr.Close();
                Xparam.CopyParams(KM.CoordMotion.MotionParams); // copy the motion parameters to the KM instance
            }

            // add the callbacks
            AddHandlers();

            // start a timer for the status update
            var Timer = new DispatcherTimer();

            Timer.Interval = TimeSpan.FromMilliseconds(100);    // timer tick every 100 ms (1/10 sec)
            Timer.Tick    += dispatchTimer_Tick;
            Timer.Start();
        }