//to sent to cnc //cnc_dwnstart3, cnc_download3, cnc_dwnend3 public static bool UploadProgram(string ipAddress, ushort portNo, string program) { short ret = -20; int len, n; program = File.ReadAllText("D:\\O12345.txt"); ushort focasLibHandle = 0; ret = FocasLib.cnc_allclibhndl3(ipAddress, portNo, 10, out focasLibHandle); if (ret != 0) { Logger.WriteErrorLog("cnc_allclibhndl3() failed. return value is = " + ret); return(false); } ret = FocasLib.cnc_dwnstart3(focasLibHandle, 0); if (ret != 0) { Logger.WriteErrorLog("cnc_dwnstart3() failed. return value is = " + ret); return(false); } if (ret == FocasLib.EW_OK) { len = program.Length; while (len > 0) { n = program.Length; ret = FocasLib.cnc_download3(focasLibHandle, ref n, program); if (ret == 10) //if buffer is empty { continue; } if (ret == -2) // if buffer in reset mode { break; } if (ret != FocasLib.EW_OK) { Logger.WriteErrorLog("cnc_download3() failed. return value is = " + ret); break; } if (ret == FocasLib.EW_OK) { //program += n; //len -= n; program = program.Substring(n, len - n); len -= n; } } ret = FocasLib.cnc_dwnend(focasLibHandle); if (ret != FocasLib.EW_OK) { Logger.WriteErrorLog("cnc_dwnend() failed. return value is = " + ret); } } return(true); }
//to sent to cnc //cnc_dwnstart3, cnc_download3, cnc_dwnend3 public static bool UploadProgramHytech(string ipAddress, ushort portNo, string programContentToSend, string folderPath, bool isProgramFolderSupports) { short ret = -20; int len, n; ushort focasLibHandle = 0; ret = FocasLib.cnc_allclibhndl3(ipAddress, portNo, 10, out focasLibHandle); if (ret != 0) { Logger.WriteErrorLog("cnc_allclibhndl3() failed. return value is = " + ret); return(false); } int count = 0; ret = short.MinValue; while (ret != 0 && count < 100) { if (isProgramFolderSupports == false) { ret = FocasLib.cnc_dwnstart3(focasLibHandle, 0); } else { ret = FocasLib.cnc_dwnstart4(focasLibHandle, 0, folderPath); } count++; if (ret == -1) { Thread.Sleep(200); } } if (ret == -1) { if (isProgramFolderSupports == false) { FocasLib.cnc_dwnend(focasLibHandle); } else { FocasLib.cnc_dwnend4(focasLibHandle); } FocasLib.cnc_freelibhndl(focasLibHandle); Logger.WriteErrorLog("CNC is busy. Please try after some time."); return(false); } if (ret != 0) { Logger.WriteErrorLog("cnc_dwnstart3() failed. return value is = " + ret); FocasLib.cnc_freelibhndl(focasLibHandle); return(false); } if (ret == FocasLib.EW_OK) { len = programContentToSend.Length; while (len > 0) { n = programContentToSend.Length; if (isProgramFolderSupports == false) { ret = FocasLib.cnc_download3(focasLibHandle, ref n, programContentToSend); } else { ret = FocasLib.cnc_download4(focasLibHandle, ref n, programContentToSend); } if (ret == 10) //if buffer is empty { continue; } if (ret == -2) // if buffer in reset mode { break; } if (ret != FocasLib.EW_OK) { Logger.WriteErrorLog("cnc_download3() failed. return value is = " + ret); break; } if (ret == FocasLib.EW_OK) { //program += n; //len -= n; programContentToSend = programContentToSend.Substring(n, len - n); len -= n; } } //Thread.Sleep(4000); if (isProgramFolderSupports == false) { ret = FocasLib.cnc_dwnend(focasLibHandle); } else { ret = FocasLib.cnc_dwnend4(focasLibHandle); } if (ret != FocasLib.EW_OK) { FocasLibBase.ODBERR a = new FocasLibBase.ODBERR(); FocasLib.cnc_getdtailerr(focasLibHandle, a); Logger.WriteErrorLog("cnc_dwnend() failed. return value is = " + ret + " ; Error code : " + a.err_no); FocasLib.cnc_freelibhndl(focasLibHandle); if (ret != 7) { Logger.WriteErrorLog("cnc_dwnend() failed. return value is = " + ret + " ; Error code : " + a.err_no); } if (ret == 7) { Logger.WriteErrorLog("Upload program failed because write protected on CNC side."); } return(false); } FocasLib.cnc_freelibhndl(focasLibHandle); } return(true); }