using FANUC; using fanuc采集; using HttpServer; using RequestServer.HttpServer; using ResponseServer.HttpServer; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static fanuc采集.ConDevice; using static HttpServer.Form1; namespace Fanuc_HttpServer.fanuc { class FanucServer { private static string ON_LINE_STATE = "在线"; public static ResponseBody requestHttpServer(RequestBody requestBody) { string ip = requestBody.serverUrl; string port = requestBody.port; string fun = requestBody.type; int ret = 0; ConDevice CIF = new ConDevice(); ResponseBody responseBody = new ResponseBody(); if (fun == ActionTypeEnum.Collect.ToString()) { ConDevice2 CIF2 = new ConDevice2(ip, port); if (CIF2.h > 0) { responseBody.mainProg = CIF2.MainProg(); responseBody.actFeed = CIF2.FeedSpeed(); responseBody.actSpindle = CIF2.ActSpindle(); responseBody.spindleMagnification = CIF2.spindleMagnification(); responseBody.powerOnTime = CIF2.PowerOnTime(); responseBody.feedRateOvr = CIF2.GetFeedrate(); responseBody.deviceState = ON_LINE_STATE; CIF2.freehand(); } else { responseBody.msg = "调用失败"; } } else if (fun == ActionTypeEnum.Upload.ToString()) { try { string prgname = requestBody.prgName; YG.Log.Instance.WriteLogAdd(">>>===上传文件名 : >>>>===" + prgname); ret = CIF.UploadNcProg(ip, port, prgname); if (ret == Fanuc.EW_OK) { responseBody.deviceState = ON_LINE_STATE; } else { responseBody.msg = "上传文件名失败,错误码:" + ret; } } catch (Exception uploadex) { responseBody.msg = "上传文件名" + uploadex.Message; } } else if (fun == ActionTypeEnum.StartNcProgram.ToString()) { try { string prgname = requestBody.prgName; ret = CIF.ReadPmcMarco(ip, port, prgname); if (ret == Fanuc.EW_OK) { responseBody.deviceState = ON_LINE_STATE; } else { responseBody.msg = "调用失败"; } } catch (Exception uploadex) { responseBody.msg = "调用失败" + uploadex.Message; } } else if (fun == ActionTypeEnum.AlmInfo.ToString()) { try { List allAlmList = new List(); ConDevice2 con2 = new ConDevice2(ip, port); //实时报警 List alms = con2.operationAlarm(); //信息履历 List almLL = con2.rdalmhistry5(); if (alms != null && alms.Count() > 0) { allAlmList.AddRange(alms); } if (almLL != null && almLL.Count() > 0) { allAlmList.AddRange(almLL); } responseBody.deviceState = ON_LINE_STATE; con2.freehand(); } catch (Exception ex) { responseBody.msg = "获取报警失败:" + ex.Message; } } return responseBody; } } }