public void AwaitResponse()
 {
     while (Comms.com.CommandState == Comms.State.AwaitAck)
     {
         EventUtils.DoEvents();
     }
 }
Esempio n. 2
0
        public static bool Get(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            Comms.com.PurgeQueue();
            SystemInfo.Clear();

            model.Silent = true;

            new Thread(() =>
            {
                res = WaitFor.AckResponse <string>(
                    cancellationToken,
                    response => Process(response),
                    a => model.OnResponseReceived += a,
                    a => model.OnResponseReceived -= a,
                    400, () => Comms.com.WriteCommand(GrblConstants.CMD_GETINFO));
            }).Start();

            while (res == null)
            {
                EventUtils.DoEvents();
            }

            model.Silent = false;

            model.AxisEnabledFlags = AxisFlags;
            model.LatheModeEnabled = LatheModeEnabled;

            return(res == true);
        }
 public void AwaitAck()
 {
     while (Comms.com.CommandState == Comms.State.DataReceived || Comms.com.CommandState == Comms.State.AwaitAck)
     {
         EventUtils.DoEvents();
     }
 }
Esempio n. 4
0
        public static bool Get(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            if (Tools.Count == 0)
            {
                Tools.Add(new Tool(GrblConstants.NO_TOOL));
            }

            if (!GrblParserState.Loaded)
            {
                GrblParserState.Get(model);
            }

            dispatcher    = Dispatcher.CurrentDispatcher;
            dataReceived += process;
            LatheMode     = GrblParserState.LatheMode;

            model.Silent = true;

            Comms.com.PurgeQueue();

            new Thread(() =>
            {
                res = WaitFor.AckResponse <string>(
                    cancellationToken,
                    response => dataReceived(response),
                    a => model.OnResponseReceived += a,
                    a => model.OnResponseReceived -= a,
                    400, () => Comms.com.WriteCommand(GrblConstants.CMD_GETNGCPARAMETERS));
            }).Start();

            while (res == null)
            {
                EventUtils.DoEvents();
            }

            model.Silent  = false;
            dataReceived -= process;

            if (Tools.Count == 1)
            {
                Tools.Add(new Tool("1"));
                Tools.Add(new Tool("2"));
                Tools.Add(new Tool("3"));
                Tools.Add(new Tool("4"));
            }

            GrblParserState.Tool = GrblParserState.Tool; // Add tool to Tools if not in list

            // Reeread parser state since work offset and tool lists are now populated
            Comms.com.WriteCommand(GrblConstants.CMD_GETPARSERSTATE);

            return(res == true);
        }
Esempio n. 5
0
        public void AwaitAck(string command)
        {
            PurgeQueue();
            Reply = string.Empty;
            WriteCommand(command);

            while (Comms.com.CommandState == Comms.State.DataReceived || Comms.com.CommandState == Comms.State.AwaitAck)
            {
                EventUtils.DoEvents();
            }
        }
        public string GetReply(string command)
        {
            Reply = "";
            WriteCommand(command);

            while (state == Comms.State.AwaitAck)
            {
                EventUtils.DoEvents();
            }

            return(Reply);
        }
Esempio n. 7
0
        private TransferState Send(int length)
        {
            TransferState     state             = TransferState.ACK;
            bool?             wait              = null;
            CancellationToken cancellationToken = new CancellationToken();

            Comms.com.PurgeQueue();
            Comms.com.WriteBytes(hdr, 3);
            Comms.com.WriteBytes(payload, length);

            response = NAK;

            new Thread(() =>
            {
                wait = WaitFor.SingleEvent <int>(
                    cancellationToken,
                    s => GetByte(s),
                    a => Comms.com.ByteReceived += a,
                    a => Comms.com.ByteReceived -= a,
                    packetNum == 0 ? 8000 : 2000, () => Comms.com.WriteBytes(crc, 2));
            }).Start();

            while (wait == null)
            {
                EventUtils.DoEvents();
            }

            switch (response)
            {
            case ACK:
                state = TransferState.ACK;
                break;

            case NAK:
                state = TransferState.NAK;
                break;

            case CAN:
                state = TransferState.CAN;
                break;
            }

            if (packetNum == 0) // Read 'C' from input
            {
                Comms.com.ReadByte();
            }

            return(state);
        }
Esempio n. 8
0
        public static bool Get(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            Comms.com.PurgeQueue();

            new Thread(() =>
            {
                res = WaitFor.AckResponse <string>(
                    cancellationToken,
                    response => Process(response),
                    a => model.OnResponseReceived += a,
                    a => model.OnResponseReceived -= a,
                    400, () => Comms.com.WriteCommand(GrblConstants.CMD_GETPARSERSTATE));
            }).Start();

            while (res == null)
            {
                EventUtils.DoEvents();
            }

            return(res == true);
        }
Esempio n. 9
0
        public static bool Get(GrblViewModel model)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();

            settings.Clear();
            Comms.com.PurgeQueue();

            model.Silent = true;

            new Thread(() =>
            {
                res = WaitFor.AckResponse <string>(
                    cancellationToken,
                    response => Process(response),
                    a => model.OnResponseReceived += a,
                    a => model.OnResponseReceived -= a,
                    400, () => Comms.com.WriteCommand(GrblConstants.CMD_GETSETTINGS));
            }).Start();

            while (res == null)
            {
                EventUtils.DoEvents();
            }

            model.Silent = false;

            if (IsGrblHAL && !Resources.ConfigName.StartsWith("hal_"))
            {
                Resources.ConfigName = "hal_" + Resources.ConfigName;
            }

            try
            {
                StreamReader file = new StreamReader(string.Format("{0}{1}", Resources.Path, Resources.ConfigName));

                if (file != null)
                {
                    string line = file.ReadLine();

                    line = file.ReadLine(); // Skip header

                    while (line != null)
                    {
                        string[] columns = line.Split('\t');

                        if (columns.Length >= 6)
                        {
                            DataRow[] rows = settings.Select("Id=" + columns[0]);
                            if (rows.Count() == 1)
                            {
                                rows[0]["Name"]        = columns[1];
                                rows[0]["Unit"]        = columns[2];
                                rows[0]["DataType"]    = columns[3];
                                rows[0]["DataFormat"]  = columns[4];
                                rows[0]["Description"] = columns[5];
                                if (columns.Length >= 7)
                                {
                                    rows[0]["Min"] = dbl.Parse(columns[6]);
                                }
                                if (columns.Length >= 8)
                                {
                                    rows[0]["Max"] = dbl.Parse(columns[7]);
                                }
                                if ((string)rows[0]["DataType"] == "float")
                                {
                                    rows[0]["Value"] = GrblSettings.FormatFloat((string)rows[0]["Value"], (string)rows[0]["DataFormat"]);
                                }
                            }
                        }
                        line = file.ReadLine();
                    }
                    file.Close();
                    file.Dispose();
                }
            }
            catch
            {
            }

            settings.AcceptChanges();

            return(Loaded);
        }