123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using HeidenhainDNCLib;
- using Newtonsoft.Json;
- using RequestServer.HttpServer;
- using ResponseServer.HttpServer;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net.NetworkInformation;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace Fanuc_HttpServer.hedidenain
- {
- class HeidenhainServer
- {
- private int iChannel = 0;
- private string RemotePath = "TNC:\\nc_prog\\ATUO";//ConfigurationManager.AppSettings["RemotePath"];
- private static string ON_LINE_STATE = "在线";
- private Dictionary<String, List<string>> jcIpDict = new Dictionary<String, List<string>>();
-
- //连接设备列表
- public Dictionary<string, DNC_STATE> deviceList { get; set; } = new Dictionary<string, DNC_STATE>();
- private DNC_STATE m_ControlState;
- public static Dictionary<string, JHMachineInProcess> machineList { get; set; } = new Dictionary<string, JHMachineInProcess>();
- public HeidenhainServer()
- {
- List<string> ip1 = new List<string>();
- ip1.Add("\\PLC\\memory\\D\\17600");
- ip1.Add("\\PLC\\memory\\D\\4448");
- jcIpDict.Add("192.168.10.109", ip1);
- List<string> ip2 = new List<string>();
- ip2.Add("\\PLC\\memory\\D\\368");
- ip2.Add("\\PLC\\memory\\D\\5048");
- jcIpDict.Add("192.168.10.101", ip2);
- }
- public ResponseBody requestHttpServer(RequestBody<ToolData> requestBody)
- {
- string ip = requestBody.serverUrl;
- string port = requestBody.port;
- string fun = requestBody.type;
- ResponseBody responseBody = new ResponseBody();
- JHMachineInProcess Machine = null;
- if (fun == ActionTypeEnum.Collect.ToString())
- {
- Ping pingSender = new Ping();
- PingReply reply = pingSender.Send(requestBody.serverUrl);
- if (reply.Status != IPStatus.Success)
- {
- //responseBody.result = false;
- responseBody.msg = "调用失败";
- }
- else
- {
-
- }
- }
- return responseBody;
- }
- private DNC_STATE connect(string connectName)
- {
- DNC_CNC_TYPE CncType;
- IJHConnectionList connectionList = null;
- IJHConnection connection = null;
- try
- {
- JHMachineInProcess Machine = new JHMachineInProcess();
- Machine.ConnectRequest(connectName);
- string sCurrentMachine = Machine.currentMachine;
- // Find out control type
- connectionList = Machine.ListConnections();
- for (int i = 0; i < connectionList.Count; i++)
- {
- connection = connectionList[i];
- if (connection.name == sCurrentMachine)
- {
- CncType = connection.cncType;
- }
- if (connection != null)
- Marshal.ReleaseComObject(connection);
- }
- // //DNC连接正常,加入数组 第一次连接加入数组,以支持多台设备
- machineList.Add(connectName, Machine);
- Thread.Sleep(20);
- return Machine.GetState();
- }
- catch (COMException cex)
- {
- YG.Log.Instance.WriteLogAdd($"海德汉响应结果-cex-->> " + cex.Message);
- return DNC_STATE.DNC_STATE_NOT_INITIALIZED;
- }
- catch (Exception ex)
- {
- YG.Log.Instance.WriteLogAdd($"海德汉响应结果-ex-->> " + ex.Message);
- return DNC_STATE.DNC_STATE_NOT_INITIALIZED;
- }
- finally
- {
- if (connectionList != null)
- Marshal.ReleaseComObject(connectionList);
- if (connection != null)
- Marshal.ReleaseComObject(connection);
- }
- }
- private string GenPath(string part1, string part2)
- {
- string sFullPath = part1;
- switch (part2)
- {
- case ".":
- break;
- case "..":
- if (part1.EndsWith(@"\") && part1.Length > 5)
- part1 = part1.Substring(0, part1.Length - 3);
- int iLastFolderPos = part1.LastIndexOf(@"\");
- if (iLastFolderPos >= 0)
- sFullPath = part1.Substring(0, iLastFolderPos + 1);
- break;
- default:
- if (part1.EndsWith(@"\"))
- sFullPath = part1 + part2;
- else
- sFullPath = part1 + @"\" + part2;
- break;
- }
- return sFullPath;
- }
- }
- }
|