123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- 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<ConDevice.AlmInfo> allAlmList = new List<AlmInfo>();
- ConDevice2 con2 = new ConDevice2(ip, port);
- //实时报警
- List<ConDevice.AlmInfo> alms = con2.operationAlarm();
- //信息履历
- List<ConDevice.AlmInfo> 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;
- }
- }
- }
|