//Get the Program Content from the CNC Machine - Download from CNC Machine
        internal string GetProgramDataNC(string progno, out String ProgramData) //From CNC Machine
        {
            string retStatus = null;

            ProgramData = null;
            //ProgramData = new StringBuilder();
            Focas1.focas_ret retGPL = (Focas1.focas_ret)Focas1.cnc_allclibhndl3(ip, port, timeout, out h);
            if (retGPL == Focas1.focas_ret.EW_OK)
            {
                ProgramReadError(h, 1);
                short        mainprogno     = Convert.ToInt16(progno.Substring(1));
                short        retUploadstart = Focas1.cnc_upstart(h, mainprogno); // Fanuc Controller 32i/Oi-TD/16i-MB/18i-TB/Oi-MC/Oi-TC/Oi-MD/Oi-MC Slim/21i-TB/310iM
                Focas1.ODBUP upld           = new Focas1.ODBUP();
                switch (retUploadstart)
                {
                case 0:
                    retStatus = "Success";
                    short  ret       = 0;
                    ushort len       = 4 + 256;
                    int    LoopCount = 0;
                    //System.Threading.Thread.Sleep(3000);
                    while (ret == 0)
                    {
                        ret = Focas1.cnc_upload(h, upld, ref len);
                        int    a            = upld.data.Length;
                        string retValString = new string(upld.data);
                        if (ret == 10)
                        {
                            len = 256;
                            ret = 0;
                            continue;
                        }
                        else if (ret == 0)
                        {
                            ProgramData += retValString;
                        }
                        else if (ret == 2)
                        {
                            //MessageBox.Show("ret 2 :: Length " + len);
                        }
                        else if (ret == -2)
                        {
                            retStatus = "Error: " + ret;
                            ret       = Focas1.cnc_upend3(h);
                            ProgramReadError(h, 0);
                            break;
                        }
                        else
                        {
                            retStatus = "Else :: Error: " + ret;
                        }

                        if (retValString.Contains('%'))
                        {
                            LoopCount++;
                            if (LoopCount >= 2)
                            {
                                String[] Temp = ProgramData.ToString().Split('%');
                                ProgramData = "%" + Temp[1] + "%";
                                retStatus   = ".Success";
                                ret         = Focas1.cnc_upend3(h);
                                ProgramReadError(h, 0);
                                break;
                            }
                        }
                        else
                        {
                            //retStatus = "Error: " + ret;
                            //MessageBox.Show("Error(cnc_upload4):" + ret);
                        }
                    }
                    ret = Focas1.cnc_upend3(h);
                    ProgramReadError(h, 0);
                    if (LoopCount == 1)
                    {
                        String[] Temp = ProgramData.ToString().Split('%');
                        ProgramData = "%" + Temp[1] + "%";
                    }
                    break;

                case -1:
                    retStatus = "Busy";
                    break;

                case 1:
                    retStatus = "Parameter(No.20,22:Input device) is wrong";
                    break;

                case 7:
                    retStatus = "Write protected on CNC side";
                    break;

                default:
                    retStatus = "cnc_upstart3 :: ErrorNo. :" + retUploadstart;
                    break;
                }
                Focas1.cnc_freelibhndl(h);
            }
            else
            {
                if (retGPL == Focas1.focas_ret.EW_SOCKET)
                {
                    //retValueInt = (int)Focas1.focas_ret.EW_SOCKET;
                    retStatus = "Socket communication error. " + retGPL.ToString();
                }
                else if (retGPL == Focas1.focas_ret.EW_NODLL)
                {
                    //retValueInt = (int)Focas1.focas_ret.EW_NODLL;
                    retStatus = "There is no DLL file for each CNC series . " + retGPL.ToString();
                }
                else if (retGPL == Focas1.focas_ret.EW_HANDLE)
                {
                    //retValueInt = (int)Focas1.focas_ret.EW_HANDLE;
                    retStatus = "Allocation of handle number is failed. " + retGPL.ToString();
                }

                retStatus = retGPL.ToString();
            }
            return(retStatus);
        }
Beispiel #2
0
        public string GetProgramDataNC(string progno, out string ProgramData)
        {
            string str1 = (string)null;

            ProgramData = (string)null;
            Focas1.focas_ret focasRet = (Focas1.focas_ret)Focas1.cnc_allclibhndl3((object)this.ip, this.port, this.timeout, out this.h);
            string           str2;

            switch (focasRet)
            {
            case Focas1.focas_ret.EW_SOCKET:
                str1 = "Socket communication error. " + focasRet.ToString();
                goto default;

            case Focas1.focas_ret.EW_NODLL:
                str1 = "There is no DLL file for each CNC series . " + focasRet.ToString();
                goto default;

            case Focas1.focas_ret.EW_HANDLE:
                str1 = "Allocation of handle number is failed. " + focasRet.ToString();
                goto default;

            case Focas1.focas_ret.EW_OK:
                this.ProgramReadError(this.h, 1);
                short        num1 = Focas1.cnc_upstart(this.h, Convert.ToInt16(progno.Substring(1)));
                Focas1.ODBUP a    = new Focas1.ODBUP();
                switch (num1)
                {
                case -1:
                    str2 = "Busy";
                    break;

                case 0:
                    str2 = "Success";
                    short  num2 = 0;
                    ushort b    = 260;
                    int    num3 = 0;
                    short  num4;
                    while (num2 == (short)0)
                    {
                        num2 = Focas1.cnc_upload(this.h, a, ref b);
                        int    length = a.data.Length;
                        string source = new string(a.data);
                        if (num2 == (short)10)
                        {
                            b    = (ushort)256;
                            num2 = (short)0;
                        }
                        else
                        {
                            if (num2 == (short)0)
                            {
                                ProgramData += source;
                            }
                            else if (num2 != (short)2)
                            {
                                if (num2 == (short)-2)
                                {
                                    str2 = "Error: " + (object)num2;
                                    num4 = Focas1.cnc_upend3(this.h);
                                    this.ProgramReadError(this.h, 0);
                                    break;
                                }
                                str2 = "Else :: Error: " + (object)num2;
                            }
                            if (source.Contains <char>('%'))
                            {
                                ++num3;
                                if (num3 >= 2)
                                {
                                    string[] strArray = ProgramData.ToString().Split('%');
                                    ProgramData = "%" + strArray[1] + "%";
                                    str2        = ".Success";
                                    num4        = Focas1.cnc_upend3(this.h);
                                    this.ProgramReadError(this.h, 0);
                                    break;
                                }
                            }
                        }
                    }
                    num4 = Focas1.cnc_upend3(this.h);
                    this.ProgramReadError(this.h, 0);
                    if (num3 == 1)
                    {
                        string[] strArray = ProgramData.ToString().Split('%');
                        ProgramData = "%" + strArray[1] + "%";
                        break;
                    }
                    break;

                case 1:
                    str2 = "Parameter(No.20,22:Input device) is wrong";
                    break;

                case 7:
                    str2 = "Write protected on CNC side";
                    break;

                default:
                    str2 = "cnc_upstart3 :: ErrorNo. :" + (object)num1;
                    break;
                }
                int num5 = (int)Focas1.cnc_freelibhndl(this.h);
                break;

            default:
                str2 = focasRet.ToString();
                break;
            }
            return(str2);
        }