Exemple #1
0
        private void listenReturnCommunication()
        {
            Stream stm = tcpclnt.GetStream();

            byte[] bc = new byte[1000];
            int    k  = stm.Read(bc, 0, 1000);

            stmElement se = new stmElement();

            se.bc = bc;
            se.k  = k;
            semaphore.Wait();
            stmQueue.Enqueue(se);
            semaphore.Release();
        }
Exemple #2
0
        private void displayPos()
        {
            while (true)
            {
                while (stmQueue.Count == 0)
                {
                    Thread.Sleep(5);
                }


                stmElement se = null;

                semaphore.Wait();
                se = stmQueue.Dequeue();
                semaphore.Release();

                byte[] bc = se.bc;
                int    k  = se.k;

                string str = "";

                for (int i = 0; i < k; i++)
                {
                    str += Convert.ToChar(bc[i]);
                }

                /*
                 * MethodInvoker mi = delegate
                 * {
                 *  returnBox.Text += k + ":    " + str + "\r\n";
                 * };
                 * if (InvokeRequired)
                 *  this.Invoke(mi);
                 */

                if (k == 8)
                {
                    if (bc[0] == 0x0a && bc[1] == 0x08)
                    {
                        string feedPercent = "";
                        if (bc[6] == 0xb0 && bc[7] == 0x04)
                        {
                            feedPercent = "120%";
                        }
                        else if (bc[6] == 0x4c && bc[7] == 0x04)
                        {
                            feedPercent = "110%";
                        }
                        else if (bc[6] == 0xe8 && bc[7] == 0x03)
                        {
                            feedPercent = "100%";
                        }
                        else if (bc[6] == 0x84 && bc[7] == 0x03)
                        {
                            feedPercent = "90%";
                        }
                        else if (bc[6] == 0x20 && bc[7] == 0x03)
                        {
                            feedPercent = "80%";
                        }
                        else if (bc[6] == 0xbc && bc[7] == 0x02)
                        {
                            feedPercent = "70%";
                        }
                        else if (bc[6] == 0x58 && bc[7] == 0x02)
                        {
                            feedPercent = "60%";
                        }
                        else if (bc[6] == 0xf4 && bc[7] == 0x01)
                        {
                            feedPercent = "50%";
                        }
                        else if (bc[6] == 0x90 && bc[7] == 0x01)
                        {
                            feedPercent = "40%";
                        }
                        else if (bc[6] == 0x2c && bc[7] == 0x01)
                        {
                            feedPercent = "30%";
                        }
                        else if (bc[6] == 0xc8 && bc[7] == 0x00)
                        {
                            feedPercent = "20%";
                        }
                        else if (bc[6] == 0x64 && bc[7] == 0x00)
                        {
                            feedPercent = "10%";
                        }
                        else if (bc[6] == 0x32 && bc[7] == 0x00)
                        {
                            feedPercent = "5%";
                        }
                        else if (bc[6] == 0x14 && bc[7] == 0x00)
                        {
                            feedPercent = "2%";
                        }
                        else if (bc[6] == 0x08 && bc[7] == 0x00)
                        {
                            feedPercent = "1%";
                        }
                        else if (bc[6] == 0x00 && bc[7] == 0x00)
                        {
                            feedPercent = "0%";
                        }

                        MethodInvoker mi2 = delegate
                        {
                            feedRatePercentTxtbox.Text = feedPercent;
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }
                    }
                }

                if (k == 12)
                {
                    if (bc[0] == 0x0f)
                    {
                        if (bc[1] == 0x08 && bc[2] == 0x04)
                        {
                            if (lineNum != -1)
                            {
                                lineNum++;
                            }
                            sendLimit += 1.00;

                            if (lineNum == GCodeParser.commandStringArr.Length)
                            {
                                lineNum          = -1;
                                runGCode.Enabled = true;
                            }

                            MethodInvoker mi2 = delegate
                            {
                                //line ended
                                //lineComplete.Text = (int.Parse(lineComplete.Text) + 1).ToString();
                                if (lineNum != -1)
                                {
                                    lineNumberBox.Text  = lineNum.ToString();
                                    currentLineBox.Text = GCodeParser.commandStringArr[lineNum - 1];
                                }
                            };

                            if (InvokeRequired)
                            {
                                this.Invoke(mi2);
                            }
                        }
                    }
                }

                if (k == 26)
                {
                    if (bc[0] == 2 && bc[1] == 8)
                    {
                        //directions
                        if (bc[6] == 1)// x direction
                        {
                            int[] point = new int[8];

                            string txt = Converter.binaryToString(bc, 10);

                            MethodInvoker mi2 = delegate
                            {
                                xBox.Text      = txt;
                                xOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + xOffset));
                            };
                            if (InvokeRequired)
                            {
                                this.Invoke(mi2);
                            }

                            currentX0 = double.Parse(txt);
                            currentX  = currentX0 + xOffset;

                            //dist to go

                            txt = Converter.binaryToString(bc, 18);
                        }

                        if (bc[6] == 2)// y direction
                        {
                            int[] point = new int[8];

                            string txt = Converter.binaryToString(bc, 10);

                            MethodInvoker mi2 = delegate
                            {
                                yBox.Text      = txt;
                                yOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + yOffset));
                            };
                            if (InvokeRequired)
                            {
                                this.Invoke(mi2);
                            }

                            currentY0 = double.Parse(txt);
                            currentY  = currentY0 + yOffset;

                            //dist to go

                            txt = Converter.binaryToString(bc, 18);
                        }


                        if (bc[6] == 4)// z direction
                        {
                            int[] point = new int[8];

                            string txt = Converter.binaryToString(bc, 10);

                            MethodInvoker mi2 = delegate
                            {
                                zBox.Text      = txt;
                                zOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + zOffset + toolHeightOffset));
                            };
                            if (InvokeRequired)
                            {
                                this.Invoke(mi2);
                            }

                            currentZ0 = double.Parse(txt);
                            currentZ  = currentZ0 + zOffset + toolHeightOffset;

                            //dist to go

                            txt = Converter.binaryToString(bc, 18);
                        }
                    }
                    else if (bc[0] == 3 && bc[1] == 8) //spindlespeed
                    {
                        if (bc[6] == 1)                //spindle speed
                        {
                            int[] point = new int[8];
                            for (int i = 0; i < 8; i++)
                            {
                                point[i] = bc[8 + i];
                            }

                            string txt = Converter.binaryToSpindle(point);

                            MethodInvoker mi2 = delegate
                            {
                                sBox.Text = txt;
                            };
                            if (InvokeRequired)
                            {
                                this.Invoke(mi2);
                            }
                        }
                    }
                }

                else if (k == 44)
                {
                    if (bc[6] == 3)// x + y direction
                    {
                        int[] point = new int[8];

                        string txt = Converter.binaryToString(bc, 10);

                        MethodInvoker mi2 = delegate
                        {
                            xBox.Text      = txt;
                            xOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + xOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentX0 = double.Parse(txt);
                        currentX  = currentX0 + xOffset;

                        //dist to go

                        txt = Converter.binaryToString(bc, 18);



                        for (int i = 0; i < 8; i++)
                        {
                            point[i] = bc[28 + i];
                        }

                        txt = Converter.binaryToString(bc, 28);

                        mi2 = delegate
                        {
                            yBox.Text      = txt;
                            yOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + yOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentY0 = double.Parse(txt);
                        currentY  = currentY0 + xOffset;

                        //dist to go

                        txt = Converter.binaryToString(bc, 36);
                    }

                    if (bc[6] == 5)//  z + x direction
                    {
                        int[] point = new int[8];

                        string txt = Converter.binaryToString(bc, 10);

                        MethodInvoker mi2 = delegate
                        {
                            xBox.Text      = txt;
                            xOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + xOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentX0 = double.Parse(txt);
                        currentX  = currentX0 + xOffset;
                        //dist to go

                        txt = Converter.binaryToString(bc, 18);


                        txt = Converter.binaryToString(bc, 28);

                        mi2 = delegate
                        {
                            zBox.Text      = txt;
                            zOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + zOffset + toolHeightOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentZ0 = double.Parse(txt);
                        currentZ  = currentZ0 + zOffset + toolHeightOffset;


                        //dist to go

                        txt = Converter.binaryToString(bc, 36);
                    }

                    if (bc[6] == 6)// z + y direction
                    {
                        int[] point = new int[8];


                        string txt = Converter.binaryToString(bc, 10);

                        MethodInvoker mi2 = delegate
                        {
                            yBox.Text      = txt;
                            yOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + yOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentY0 = double.Parse(txt);
                        currentY  = currentY0 + xOffset;
                        //dist to go

                        txt = Converter.binaryToString(bc, 18);


                        txt = Converter.binaryToString(bc, 28);

                        mi2 = delegate
                        {
                            zBox.Text      = txt;
                            zOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + zOffset + toolHeightOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentZ0 = double.Parse(txt);
                        currentZ  = currentZ0 + zOffset + toolHeightOffset;


                        //dist to go

                        txt = Converter.binaryToString(bc, 36);
                    }
                }


                else if (k == 62)
                {
                    if (bc[6] == 7)// x + y + z direction
                    {
                        string txt = Converter.binaryToString(bc, 10);

                        MethodInvoker mi2 = delegate
                        {
                            xBox.Text      = txt;
                            xOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + xOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentX0 = double.Parse(txt);
                        currentX  = currentX0 + xOffset;

                        //dist to go

                        txt = Converter.binaryToString(bc, 18);



                        txt = Converter.binaryToString(bc, 28);

                        mi2 = delegate
                        {
                            yBox.Text      = txt;
                            yOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + yOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentY0 = double.Parse(txt);
                        currentY  = currentY0 + xOffset;


                        //dist to go

                        txt = Converter.binaryToString(bc, 36);


                        txt = Converter.binaryToString(bc, 46);

                        mi2 = delegate
                        {
                            zBox.Text      = txt;
                            zOffseted.Text = String.Format("{0:0.0000}", (double.Parse(txt) + zOffset + toolHeightOffset));
                        };
                        if (InvokeRequired)
                        {
                            this.Invoke(mi2);
                        }

                        currentZ0 = double.Parse(txt);
                        currentZ  = currentZ0 + zOffset + toolHeightOffset;

                        //dist to go

                        txt = Converter.binaryToString(bc, 54);
                    }
                }
                if (double.IsInfinity(currentX.GetValueOrDefault()))
                {
                    currentX = null;
                }

                if (double.IsInfinity(currentY.GetValueOrDefault()))
                {
                    currentY = null;
                }

                if (double.IsInfinity(currentZ.GetValueOrDefault()))
                {
                    currentZ = null;
                }

                if (double.IsInfinity(currentX0.GetValueOrDefault()))
                {
                    currentX0 = null;
                }

                if (double.IsInfinity(currentY0.GetValueOrDefault()))
                {
                    currentY0 = null;
                }

                if (double.IsInfinity(currentZ0.GetValueOrDefault()))
                {
                    currentZ0 = null;
                }
            }
        }