MitCom.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Data.Common;
  7. using System.IO;
  8. using Common;
  9. using EZNCAUTLib;
  10. using RequestServer.HttpServer;
  11. namespace EZSockets
  12. {
  13. /// <summary>
  14. /// 封装的三菱的通讯类
  15. /// </summary>
  16. public class MitCom
  17. {
  18. private EZNCAUTLib.DispEZNcCommunication EZNcCom;//通讯库变量
  19. private EZNCAUTLib.DispEZNcCommunication EZNcCom106;
  20. private EZNCAUTLib.DispEZNcCommunication EZNcCom107;
  21. public static Dictionary<string, DispEZNcCommunication> deviceList { get; set; } = new Dictionary<string, DispEZNcCommunication>();
  22. private int lResult=1;
  23. private int lSystemType;
  24. private string szMessage;
  25. public event Common.MyDelegate<string, string> AlarmData;//声明事件
  26. Random x = new Random();
  27. public MitCom(string ipAdress)
  28. {
  29. // EZNcCom = deviceList.Where(m => m.Key == ipAdress).FirstOrDefault().Value;
  30. }
  31. /// <summary>
  32. /// 连接三菱设备
  33. /// </summary>
  34. public void GetSimConnect(string nCTypeCmb,string nCCardNo,string timeOut,string ipAdress)
  35. {
  36. int lResultOpen = -1;
  37. int lResultClose = -1;
  38. int lMachine;
  39. int lTimeOut;
  40. string strHostName;
  41. if (EZNcCom == null)
  42. {
  43. EZNcCom = new EZNCAUTLib.DispEZNcCommunication();
  44. switch (nCTypeCmb)
  45. {
  46. case "MAGIC64":
  47. lSystemType = (int)sysType.EZNC_SYS_MAGICCARD64;
  48. break;
  49. case "M6x5M":
  50. lSystemType = (int)sysType.EZNC_SYS_MELDAS6X5M;
  51. break;
  52. case "M6x5L":
  53. lSystemType = (int)sysType.EZNC_SYS_MELDAS6X5L;
  54. break;
  55. case "C6/C64":
  56. lSystemType = (int)sysType.EZNC_SYS_MELDASC6C64;
  57. break;
  58. case "M700M":
  59. lSystemType = (int)sysType.EZNC_SYS_MELDAS700M;
  60. break;
  61. case "M700L":
  62. lSystemType = (int)sysType.EZNC_SYS_MELDAS700L;
  63. break;
  64. case "M800M":
  65. lSystemType = (int)sysType.EZNC_SYS_MELDAS800M;
  66. break;
  67. case "M800L":
  68. lSystemType = (int)sysType.EZNC_SYS_MELDAS800L;
  69. break;
  70. case "M80B":
  71. break;
  72. default:
  73. MessageBox.Show("三菱NC 类型选取错误!");
  74. return;
  75. }
  76. lMachine = Convert.ToInt32(nCCardNo);
  77. lTimeOut = Convert.ToInt32(timeOut);
  78. if (string.IsNullOrEmpty(ipAdress))
  79. {
  80. strHostName = "EZNC_LOCALHOST";
  81. }
  82. else
  83. {
  84. if (ipAdress == "连接前请设定")
  85. {
  86. strHostName = "EZNC_LOCALHOST";
  87. }
  88. else
  89. {
  90. strHostName = ipAdress;
  91. }
  92. }
  93. if (lSystemType == (int)sysType.EZNC_SYS_MELDASC6C64 || lSystemType == (int)sysType.EZNC_SYS_MELDAS700M ||
  94. lSystemType == (int)sysType.EZNC_SYS_MELDAS700L || lSystemType == (int)sysType.EZNC_SYS_MELDAS800M ||
  95. lSystemType == (int)sysType.EZNC_SYS_MELDAS800L)
  96. {
  97. if (lSystemType == (int)sysType.EZNC_SYS_MELDASC6C64)
  98. {
  99. lResult = EZNcCom.SetTCPIPProtocol(strHostName, 64758);
  100. //64758
  101. }
  102. else
  103. {
  104. lResult = EZNcCom.SetTCPIPProtocol(strHostName, 683);
  105. //683
  106. }
  107. ErrorCheck("SetTCPIPProtocol");
  108. if (lResult == 0)
  109. {
  110. lResultOpen = EZNcCom.Open2(lSystemType, lMachine, lTimeOut, "EZNC_LOCALHOST");//EZNC_LOCALHOST
  111. lResult = lResultOpen;
  112. // deviceList.Add(ipAdress, EZNcCom);
  113. ErrorCheck("Open");
  114. }
  115. }
  116. else
  117. {
  118. lResultOpen = EZNcCom.Open2(lSystemType, lMachine, lTimeOut, strHostName);
  119. ErrorCheck("Open");
  120. }
  121. }
  122. else
  123. {
  124. lResult = EZNcCom.Close();
  125. ErrorCheck("Close");
  126. EZNcCom = null;
  127. }
  128. }
  129. public void SimClose()
  130. {
  131. if(EZNcCom != null)
  132. {
  133. lResult = EZNcCom.Close();
  134. ErrorCheck("Close");
  135. }
  136. EZNcCom = null;
  137. }
  138. /// <summary>
  139. /// 获取版本号
  140. /// IAxistNo:设置轴号(从轴1 =从1)
  141. /// lIndex:设置参数编号。
  142. /*lIndex=0: NC系统S / W编号,名称和PLC版本取决于系统规格。
  143. lIndex=1控制单元,扩展单元取决于系统规格。
  144. lIndex=2 RIO单元,终端RIO单元轴设置仅适用于C70。取决于系统规格。*/
  145. /* 以UNICODE字符串形式获取各种NC系统软件版本信息。
  146. 0:获取NC系统的系统S / W编号,名称和PLC版本。 字符串数据的格式如下:
  147. NC系统软件编号\ tNC系统名称\ t可编程控制器系统编号\ 0在NC系统编号和NC系统的S / W名称之间插入TAB代码。数据的末尾变成NULL代码。输出示例:“BND-2005W000-A0三菱CNC 830WM”
  148. 如果没有项目,将会出现一个TAB代码。如果终止项不存在,则为NULL.代码将遵循TAB代码。
  149. 1:获取控制单元和扩展单元版本。
  150. 字符串数据的格式如下。
  151. 控制单元号\ t扩展单元号\ 0
  152. 在控制单元号码和分机号码之间插入一个TAB代码。
  153. 数据的末尾变成NULL代码。
  154. 2:获取RIO单元和终端RIO单元版本。
  155. 字符串数据的格式如下。
  156. RIO单元号\ tTerminal RIO单元号\ 0
  157. M700有RIO单元1 \ t RIO单元2 \ t ... \ 0有24个项目。
  158. M700 / M800系列有RIO单元1¥RIO单元2¥t5 ...¥0最多32项(*)。
  159. *确认与MTB的RIO单元的数量。
  160. 在RIO单元号码和终端RIO单元号码之间插入TAB代码。
  161. 数据的末尾变成NULL代码。
  162. 由于在本产品中分配字符串区域内存,使用VC ++的客户端需要
  163. 用CoTaskMemFree()显式释放字符串区域内存。*/
  164. /// </summary>
  165. public void GetSimVersion(int lAxistNo, int lIndex, out string version)
  166. {
  167. version = "";
  168. try
  169. {
  170. if (EZNcCom != null)
  171. {
  172. lResult = EZNcCom.System_GetVersion(lAxistNo, lIndex, out version);//系统号码,名称,控制S/W版本取得
  173. ErrorCheck("GetVersion");
  174. }
  175. }
  176. catch
  177. {
  178. ErrorCheck("通讯已关闭");
  179. version = "";
  180. }
  181. }
  182. /// <summary>
  183. /// 获取自动运行状态:
  184. /// lindex=0:刀具测量。plStatus=0:刀具未测量;=1:已测量
  185. /// lindex=1:在自动运行模式下:获取系统自动运行的状态指示。plStatus=0:无自动运行;=1:自动运行
  186. /// lindex=2:自动运行开始:获取系统自动运行的状态指示,并且正在执行移动命令或M,S,T,B进程. 。plStatus=0:没有开始自动运行;=1:开始自动运行
  187. /// lindex=3:自动运行暂停:在执行移动指令或其他自动操作指令时,获取表示自动操作暂停的状态。plStatus=0:无暂停;=1:暂停
  188. /// 函数说明:
  189. /// 获取运行状态。自动运行暂停功能仅在M700 / M800系列中有效。指示PLC接口自动运行状态的信号包括“自动运行”,“自动运行启动”和“自动运行暂停”。
  190.   /// 在每个状态下这三个信号的ON / OFF状态如下所示。
  191. /// </summary>
  192. public void GetRunStatus(int lindex,out int plStatus)
  193. {
  194. plStatus = 0;
  195. try
  196. {
  197. if (EZNcCom != null)
  198. {
  199. lResult = EZNcCom.Status_GetRunStatus(lindex, out plStatus);
  200. ErrorCheck("GetRunStatus");
  201. }
  202. }
  203. catch
  204. {
  205. ErrorCheck("通讯已关闭");
  206. }
  207. }
  208. #region 轴坐标
  209. double dPosition = 0.0f;
  210. /* //注意这里的库用的是表示度为14的,下方有表示度282的另一个方法。别用错库。*/
  211. /// <summary>
  212. /// 获取机械坐标
  213. /// </summary>
  214. public void GetAxisPosition(int axistno,out Communicationcs<string ,string> DataContainer )
  215. {
  216. DataContainer = new Communicationcs<string, string>();
  217. try
  218. {
  219. if (EZNcCom != null)
  220. {
  221. for (int i = 1; i <= axistno; i++)
  222. {
  223. #region 获取剩余行程
  224. lResult = EZNcCom.Position_GetDistance2(i, out dPosition, 0);
  225. ErrorCheck("GetDisTance");
  226. if (lResult == 0)
  227. {
  228. DataContainer.simDisPos.Add(dPosition.ToString("#0.000"));
  229. }
  230. #endregion
  231. #region 获取当前坐标(相对坐标)
  232. lResult = EZNcCom.Position_GetCurrentPosition(i, out dPosition);
  233. ErrorCheck("GetCurrentPosition");
  234. if (lResult == 0)
  235. {
  236. DataContainer.simCurPos.Add(dPosition.ToString("#0.000"));
  237. }
  238. #endregion
  239. #region 获取工件坐标
  240. lResult = EZNcCom.Position_GetWorkPosition(i, out dPosition, 0);
  241. ErrorCheck("GetWorkPosition");
  242. if (lResult == 0)
  243. {
  244. DataContainer.simWorkPos.Add(dPosition.ToString("#0.000"));
  245. }
  246. #endregion
  247. #region 获取机械坐标
  248. lResult = EZNcCom.Position_GetMachinePosition(1, out dPosition, 0);
  249. ErrorCheck("GetMachinePosition");
  250. if (lResult == 0)
  251. {
  252. DataContainer.simMaPos.Add(dPosition.ToString("#0.000"));
  253. }
  254. #endregion
  255. }
  256. }
  257. }
  258. catch
  259. {
  260. ErrorCheck("通讯已关闭" );
  261. }
  262. }
  263. #endregion
  264. /// <summary>
  265. /// 获取主轴信息
  266. /// </summary>
  267. public void GetSpindleInfo(int index,int lspindle,out int pldata, out string loadstr)
  268. {
  269. #region 接口描述
  270. /*** 主轴监视
  271. * lIndex:设置主轴的参数编号。
  272. * lIndex 描述数据 范围 备注
  273. * 0 增益。 主轴位置回路增益。 单位:1 / s
  274. * 1 下垂。 位置偏差量。 单位:L
  275. * 2 主轴(SR,SF)转速。 主轴电机转速。 包括进给。 0[RPM]
  276. * 3 负载。 主轴电机负载。 0 [%]
  277. * 4 LED显示屏。 驱动器上有7段LED显示屏。 从“00 \ 0”到“FF \ 0”输出一个3位数的字符串。
  278. * 5 报警1。 最多3个字母数字字符
  279. * 6 报警2 同上
  280. * 7 报警3 同上
  281. * 8 报警4 同上 M700/M800 series onl
  282. * 10 周期计数器。
  283. * 11 控制输入1。
  284. * 12
  285. * 13
  286. * 14
  287. * 15 控制输出1。
  288. * 16
  289. * 17
  290. * 18
  291. * 19
  292. * **lSpindle:设定主轴编号。
  293. * ** plData:返回主轴状态。
  294. * ** lppwszBuffer:获取主轴信息作为UNICODE字符串。
  295. * ***/
  296. /*** 主轴诊断
  297. * AxisNo:设置轴号(从轴1 = 1)
  298. * lIndex:设置诊断信息。
  299. * lIndex 描述数据 范围 备注
  300. * 0 工作时长
  301. * 1 报警记录1(报警号码)。 上一个主轴报警号码
  302. * 2 2(报警号码)。
  303. * 3 3(报警号码)。
  304. * 4 4(报警号码)。
  305. * 5 5(报警号码)。
  306. * 6 6(报警号码)。
  307. * 7 7(报警号码)。
  308. * 8 8(报警号码)。
  309. * 11 报警记录1(时间)。 上一个主轴报警时间
  310. * 12 2(时间)。
  311. * 13 3(时间)。
  312. * 14 4(时间)。
  313. * 15 5(时间)。
  314. * 16 6(时间)。
  315. * 17 7(时间)。
  316. * 18 8(时间)。
  317. * ***/
  318. #endregion
  319. pldata=-1;
  320. loadstr="";
  321. try
  322. {
  323. if (EZNcCom != null)
  324. {
  325. lResult = EZNcCom.Monitor_GetSpindleMonitor(index, lspindle, out pldata, out loadstr);
  326. ErrorCheck("GetSpindleMonitor");
  327. }
  328. }
  329. catch
  330. {
  331. ErrorCheck("通讯已关闭");
  332. }
  333. }
  334. /// <summary>
  335. /// 获取伺服轴信息
  336. /// lAxisNo: Sets the axis No. (From Axis 1 = from 1)
  337. ///lindex:设置在所述一组系统中设定轴号的参数号。
  338. /******************
  339. * lIndex Description Data range Remarks
  340. * 0 获得:位置增益回路显示 1/s
  341. * 1 下垂:跟踪延迟 i
  342. * 2 实际的电机速度 rpm
  343. * 3 负载电流,电机电流(停机时转换为连续电流显示)。 %
  344. * 4 最大电流1 %
  345. * 5 最大电流2 %
  346. * 6 超负荷 %
  347. * 7 重新加载,再生负载 %
  348. * 10 周期计数器 pulse
  349. * 101 报警1 输出一个3位数字字符串。
  350. * ****************/
  351. ///plData:返回轴的状态。
  352. ///lppwszBuffer:输出数据(返回值)作为UNICODE字符串,当任何100到104为lIndex设置。
  353. ///对于M700 / M800系列,当lIndex设置为11到15,18到20或100到104中的任意一个时,将数据(返回值)作为UNICODE字符串输出。
  354. ///获取设定零件系统中设定轴号的伺服监控信息。当索引表中的数据范围为[单位:指令单位]时,需要根据三菱CNC的指令单位进行转换。 设定单位请参照三菱CNC的规格
  355. /// </summary>
  356. public void GetServoInfo(int lAxisNo,int index,out int plData,out string loaStr,string alarmCode)
  357. {
  358. plData = -1;
  359. loaStr = "";
  360. try
  361. {
  362. if (EZNcCom != null)
  363. {
  364. lResult = EZNcCom.Monitor_GetServoMonitor(lAxisNo, index, out plData, out loaStr);
  365. ErrorCheck(alarmCode);
  366. }
  367. }
  368. catch
  369. {
  370. ErrorCheck("通讯已关闭");
  371. }
  372. }
  373. /// <summary>
  374. /// Group: 设置参数的组号。这个似乎对读取数据没影响
  375. /// item:参数号
  376. /// Size:设置读取参数的数量。 范围从1开始。最多可取5个
  377. /// lAxis:设置要获取参数的轴。除非需要获取的参数取决于轴,否则不需要设置该参数
  378. ///
  379. /// </summary>
  380. public void GetParaValue(int lGroup, int lItem, int lSize, int lAxis, out string overValue)
  381. {
  382. object pvValue=null;
  383. overValue = "";
  384. try
  385. {
  386. if (EZNcCom != null)
  387. {
  388. if (lGroup == 3)
  389. {
  390. for (int i = 1; i <= lAxis; i++)
  391. {
  392. lResult = EZNcCom.Parameter_GetData3(lGroup, lItem, lSize, i, out pvValue);
  393. }
  394. }
  395. else
  396. {
  397. lResult = EZNcCom.Parameter_GetData3(lGroup, lItem, lSize, 1, out pvValue);
  398. }
  399. ErrorCheck("GetParameterData");
  400. var value = pvValue as string[];
  401. if (value != null&&value .Count() >=0)
  402. {
  403. overValue = value[0];
  404. }
  405. }
  406. }
  407. catch
  408. {
  409. ErrorCheck("通讯已关闭");
  410. }
  411. }
  412. /// <summary>
  413. /// 获取进给速递
  414. ///FeedSpeedType:进给速度类型,设置要获得的进给速度的类型。
  415. /*FeedSpeedType=0;指令进给速度(FA)
  416. =1;手动有效进给速度(FM)
  417. =2;同步进给速度(FS)
  418. =3;攻丝(FE)
  419. pdspeed:返回指定系统的进给速度。*/
  420. /// </summary>
  421. public void GetFeedSpeed(int lFeedType,out double pdSpeed,string alarmMsg)
  422. {
  423. pdSpeed = 0.0;
  424. try
  425. {
  426. if (EZNcCom != null)
  427. {
  428. lResult = EZNcCom.Position_GetFeedSpeed(lFeedType, out pdSpeed);
  429. ErrorCheck(alarmMsg);
  430. }
  431. }
  432. catch
  433. {
  434. ErrorCheck("通讯已关闭");
  435. }
  436. }
  437. /// <summary>
  438. /// 获取报警消息
  439. /// lMessageNumber:设置要获取的消息的数量。 值:1至10(最大)
  440. /// lAlarmType:设置要获取的警报类型
  441. /// M_ALM_NC_ALARM: NC报警
  442. /// M_ALM_STOP_CODEL:停止代码
  443. /// M_ALM_PLC_ALARM :PLC报警消息
  444. /// M_ALM_OPE_MSG:操作员消息
  445. /// M_ALM_ALL_ALARM:不区分报警类型
  446. /// lppwszBuffer:以UNICODE字符串形式获取报警信息。消息格式包括CR,LF代码来区分消息。 此外,在消息的末尾插入NULL。
  447. ///获取设定NC控制单元中当前产生的报警的报警信息。该报警信息的语言符合NC参数(#1043 lang)。
  448. ///消息按重要性降序排列。由于在本产品中分配字符串区域内存,使用VC ++的客户端需要用CoTaskMemFree()显式释放字符串区域内存。
  449. ///M800系列不支持此功能。 (EZ_ERR_NOT_SUPPORT返回plRet。)
  450. /// </summary>
  451. public void GetAlarm(out string[] AlarmMsg)
  452. {
  453. AlarmMsg = new string[3];
  454. int[] lRes = new int[3];
  455. int tmp = 0;
  456. try
  457. {
  458. if (EZNcCom != null)
  459. {
  460. if (lSystemType == (int)sysType.EZNC_SYS_MELDAS6X5M || lSystemType == (int)sysType.EZNC_SYS_MELDASC6C64)
  461. {
  462. lRes[0] = EZNcCom.System_GetAlarm2(3, (int)alarmType.M_ALM_NC_ALARM, out AlarmMsg[0]);
  463. lResult = lRes[0];
  464. ErrorCheck("GetAlarm");
  465. lRes[1] = EZNcCom.System_GetAlarm2(3, (int)alarmType.M_ALM_PLC_ALARM, out AlarmMsg[1]);
  466. lResult = lRes[1];
  467. ErrorCheck("GetAlarm");
  468. lRes[2] = EZNcCom.System_GetAlarm2(3, (int)alarmType.M_ALM_OPE_MSG, out AlarmMsg[2]);
  469. lResult = lRes[2];
  470. ErrorCheck("GetAlarm");
  471. if (lRes[0] + lRes[1] + lRes[2] == 0)
  472. {
  473. for (int K = 0; K < 3; K++)
  474. {
  475. if (!string.IsNullOrEmpty(AlarmMsg[K]))
  476. {
  477. }
  478. }
  479. }
  480. }
  481. if (lSystemType == (int)sysType.EZNC_SYS_MAGICBOARD64 || lSystemType == (int)sysType.EZNC_SYS_MELDAS700M ||
  482. lSystemType == (int)sysType.EZNC_SYS_MELDAS700L || lSystemType == (int)sysType.EZNC_SYS_MELDAS800M ||
  483. lSystemType == (int)sysType.EZNC_SYS_MELDAS800L || lSystemType == (int)sysType.EZNC_SYS_MELDAS6X5L)
  484. {
  485. lResult = EZNcCom.System_GetAlarm2(10, (int)alarmType.M_ALM_ALL_ALARM, out AlarmMsg[0]);
  486. ErrorCheck("GetAlarm");
  487. }
  488. }
  489. }
  490. catch
  491. {
  492. ErrorCheck("通讯已关闭");
  493. }
  494. }
  495. /// <summary>
  496. /// 获取自动运行时间
  497. /// /plTime:返回自动运行开始的总处理时间(小时,分钟,秒),使用内存(磁带)或MDI模式到M02 / M30的终止或复位操作。
  498. ///值:0到99995959
  499. ///输出示例:9999:59:59 = 99995959
  500. ///从存储器(磁带)开始的自动运行开始或MDI模式到M02 / M30的终止或复位操作获取总处理时间(小时,分钟,秒)。当值达到最大值时停止积分,并保持最大值。
  501. /// </summary>
  502. public void GetRunTime(out int plTime)
  503. {
  504. plTime = 0;
  505. try
  506. {
  507. if (EZNcCom != null)
  508. {
  509. lResult = EZNcCom.Time_GetRunTime(out plTime);
  510. ErrorCheck("Time_GetRunTime");
  511. }
  512. }
  513. catch
  514. {
  515. ErrorCheck("通讯已关闭");
  516. }
  517. }
  518. /// <summary>
  519. /// 读取PLC参数
  520. /// </summary>
  521. public void GetPLCPar(int lindex,out int value)
  522. {
  523. value = 0;
  524. try
  525. {
  526. if (EZNcCom != null)
  527. {
  528. lResult = EZNcCom.Parameter_GetPlcParameter(lindex, out value);
  529. }
  530. }
  531. catch
  532. {
  533. ErrorCheck("通讯已关闭");
  534. }
  535. }
  536. /// <summary>
  537. /// 读取程序号
  538. ///lProgramType:设置程序类型。
  539. ///EZNC_MAINPRG::主程序//EZNC_SUBPRG子程序
  540. ///ppwszProgramNo:返回已完成搜索的程序的编号.目前以UNICODE字符串自动运行。 程序编号作为M700 / M800系列的程序文件名。
  541. ///自动返回已完成搜索或当前搜索的程序的编号
  542. /// </summary>
  543. /// <param name="szPrgNo"></param>
  544. public void GetProgramNumber(out string PrgNo)
  545. {
  546. string szPrgNo;
  547. int szPrg;
  548. PrgNo=null ;
  549. try
  550. {
  551. if (EZNcCom != null)
  552. {
  553. if (lSystemType == (int)sysType.EZNC_SYS_MELDAS700M || lSystemType == (int)sysType.EZNC_SYS_MELDAS700L || lSystemType == (int)sysType.EZNC_SYS_MELDAS800L)
  554. {
  555. lResult = EZNcCom.Program_GetProgramNumber2((int)progType.EZNC_MAINPRG, out szPrgNo);
  556. ErrorCheck("GetProgramNumber2");
  557. if (lResult == 0)
  558. {
  559. PrgNo = szPrgNo;
  560. }
  561. }
  562. else
  563. {
  564. lResult = EZNcCom.Program_GetProgramNumber((int)progType.EZNC_MAINPRG, out szPrg);
  565. ErrorCheck("GetProgramNumber");
  566. if (lResult == 0)
  567. {
  568. PrgNo = szPrg.ToString ();
  569. }
  570. }
  571. }
  572. else
  573. {
  574. ErrorCheck("获取GetProgramNumber2失败");
  575. }
  576. }
  577. catch
  578. {
  579. ErrorCheck("通讯已关闭");
  580. }
  581. }
  582. /// <summary>
  583. /// 程序序列号取得
  584. /// </summary>
  585. public void GetSequenceNo(out int lSequenceNo)
  586. {
  587. lSequenceNo = 0;
  588. int sequenceNo = 0;
  589. try
  590. {
  591. if (EZNcCom != null)
  592. {
  593. lResult = EZNcCom.Program_GetSequenceNumber((int)progType.EZNC_MAINPRG, out sequenceNo);
  594. ErrorCheck("GetsequenceNumber");
  595. if (lResult == 0)
  596. {
  597. lSequenceNo = sequenceNo;
  598. }
  599. else
  600. {
  601. ErrorCheck("获取GetProgramNumber2失败");
  602. }
  603. }
  604. else
  605. {
  606. ErrorCheck("通讯对象未建立");
  607. }
  608. }
  609. catch
  610. {
  611. ErrorCheck("通讯已关闭");
  612. }
  613. }
  614. /// <summary>
  615. ///获取当前正在运行程序
  616. ///当前块读出
  617. ///lBlockNumber:设置要获取的块数。 值:1到10
  618. ///lppwszProgramData:以UNICODE字符串的形式获取程序块。 分开程序块,CR,LF代码插入它们之间。 另外,在NULL处插入NULL结束。
  619. ///plCurrentBlockNo:返回得到的块中正在执行的块号。
  620. ///0未运行
  621. ///1第一块
  622. ///2第二块
  623. ///获取已经完成操作搜索的程序或正在执行的程序。 读取正在运行的程序段或者运行中的程序段。
  624. /// </summary>
  625. public void GetProgram(out string PrgData)
  626. {
  627. string szPrgData = null;
  628. PrgData = "null";
  629. int lCurrentBlkNo;
  630. try
  631. {
  632. if (EZNcCom != null)
  633. {
  634. lResult = EZNcCom.Program_CurrentBlockRead(10, out szPrgData, out lCurrentBlkNo);
  635. ErrorCheck("CurrentBlockRead");
  636. if (lResult == 0)
  637. {
  638. PrgData = szPrgData;
  639. }
  640. else
  641. {
  642. ErrorCheck("获取GetProgramNumber2失败");
  643. }
  644. }
  645. else
  646. {
  647. ErrorCheck("通讯对象未建立");
  648. }
  649. }
  650. catch
  651. {
  652. ErrorCheck("通讯已关闭");
  653. }
  654. }
  655. /// <summary>
  656. /// 获取刀具偏置组数
  657. /// 返回设定零件系统的刀具偏置组数。组数由NC规格决定。值含义:200 = 200 [sets]
  658. /// </summary>
  659. public void GetToolSetSize(out int toolSetSize)
  660. {
  661. int toolCount;
  662. toolSetSize = 0;
  663. try
  664. {
  665. if (EZNcCom != null)
  666. {
  667. lResult = EZNcCom.Tool_GetToolSetSize(out toolCount);
  668. ErrorCheck("Tool_GetToolSetSize");
  669. if (lResult == 0)
  670. {
  671. toolSetSize = toolCount;
  672. }
  673. else
  674. {
  675. ErrorCheck("Tool_GetToolSetSize失败");
  676. }
  677. }
  678. }
  679. catch
  680. {
  681. ErrorCheck("通讯已关闭");
  682. }
  683. }
  684. /// <summary>
  685. ///获取刀补信息
  686. ///lType:设置刀具补偿类型。 请参阅参数表。
  687. ///lKind:设置刀具补偿量的类型。 请参阅参数表。
  688. ///lToolSetNo:设置刀具偏置组号。可以通过GetToolSetSize()获取组数。
  689. ///pdOffset:返回刀具偏置量。 请参阅参数表。
  690. ///plNo:返回假想的刀尖点数。 请参阅参数表。仅L系统类型。 除L系统类型外,不返回任何内容。
  691. ///Function:获取设定零件系统/轴号的刀具偏置量。参数表中显示的范围因三菱CNC的英制,公制等指令单位而异。 有关详细信息,请参阅每个三菱CNC的安装手册。
  692. /// </summary>
  693. public void GetToolOffSet(int lType,int lKind,int lToolSetNo,out double offSet,out int no)
  694. {
  695. offSet = -1;
  696. no = -1;
  697. double pdOffSet;
  698. int plNo;
  699. try
  700. {
  701. if (EZNcCom != null)
  702. {
  703. lResult = EZNcCom.Tool_GetOffset(lType, lKind, lToolSetNo, out pdOffSet, out plNo);
  704. ErrorCheck("GetOffset");
  705. if (lResult == 0)
  706. {
  707. offSet = pdOffSet;
  708. no = plNo;
  709. }
  710. else
  711. {
  712. ErrorCheck("获取GetOffset失败");
  713. }
  714. }
  715. else
  716. {
  717. ErrorCheck("通讯对象未建立");
  718. }
  719. }
  720. catch
  721. {
  722. ErrorCheck("通讯已关闭");
  723. }
  724. }
  725. #region 文件相关
  726. /// <summary>
  727. /// 驱动信息取得
  728. ///lppwszDriveInfo:以UNICODE字符串形式获取驱动器信息。
  729. ///驱动器信息的格式如下所示:
  730. ///驱动器名称:CRLFDrive名称:CRLF ...驱动器名称:CRLF \ 0
  731. ///要分隔驱动器名称,将在它们之间插入CR,LF代码。 数据的结尾
  732. ///成为CR,LF代码和NULL代码。 数据的末尾变成NULL代码。
  733. /// </summary>
  734. public void GetDriveInfomation(out string driveInfo)
  735. {
  736. string lppwszDriveInfo;
  737. driveInfo = null;
  738. try
  739. {
  740. if (EZNcCom != null)
  741. {
  742. lResult = EZNcCom.File_GetDriveInformation(out lppwszDriveInfo);
  743. if (lResult != 0)
  744. {
  745. driveInfo = lppwszDriveInfo;
  746. }
  747. else
  748. {
  749. ErrorCheck(" When a drive does not exist");
  750. }
  751. }
  752. }
  753. catch
  754. {
  755. ErrorCheck("通讯已关闭");
  756. }
  757. }
  758. /// <summary>
  759. /// 目录检索
  760. /// lpcwszDirectryName:将目录名称设置为UNICODE字符串。
  761. ///使用绝对路径指定目录,如下所示:
  762. ///驱动器名称+“:”+ \目录名称\文件名称... 获取设置的文件名称信息。 (注1)
  763. ///驱动器名称+“:”+“\ Directory name”... 获取设置的目录名称信息。 (注1)
  764. ///驱动器名称+“:”+ \目录名称\ ... 获取设置的目录信息。
  765. ///(注1)该设置适用于M700 / M800系列。
  766. ///FileType:设置要读取的数据的类型和格式。以下内容也可以用管道(|)设置。 当设置NULL时,读取文件信息。
  767. ///值含义
  768. ////EZNC_DISK_DIRTYPE 读取目录信息
  769. ///EZNC_DISK_COMMENT 读取的注释信息(仅在NC控制单元一侧)
  770. ///EZNC_DISK_DATE 读取日期信息(仅在个人计算机端)
  771. ///EZNC_DISK_SIZE 读取大小信息
  772. ///lppwszFileInfo:以UNICODE字符串的形式获取文件信息。
  773. ///文件信息的格式如下所示:文件名\大小\日期\评论\ 0.一个TAB代码插入文件名,大小,日期和评论之间。数据的末尾变成NULL代码。
  774. ///plRet:返回是否读取文件信息或返回错误代码。 (在自动化时,使用返回值。)
  775. ///0:当没有文件信息时
  776. ///1或更多:当存在文件信息时
  777. ///EZNC_FILE_DIR_DATASIZE:超出了最大数据大小
  778. ///EZNC_FILE_DIR_NOTOPEN:未打开
  779. ///EZNC_FILE_DIR_READ:文件信息读取错误
  780. ///EZNC_FILE_DIR_ALREADYOPENED:不同的目录已经打开
  781. ///EZNC_FILE_DIR_NODRIVE:驱动器不存在
  782. ///EZNC_FILE_DIR_NODIR:目录不存在
  783. ///(注2)如果个人计算机发生错误,错误代码EZNC_FILE_ ...将变为EZNC_PCFILE_...
  784. ///Function 说明:
  785. ///搜索目录。
  786. ///在FindDir2()中,可以通过读取一次来读取一个文件的信息。要不断获取目录信息,可以通过重复调用FindNextDir2()来获取设置目录中的文件名列表。要存储在由lpszFileInfo指示的区域中的文件信息的格式如下:
  787. ///文件名\ tSize \ tDate \ tComment \ 0
  788. ///TAB代码插入文件名称,大小,日期和注释之间。数据的末尾变成NULL代码。仅存储在读取类型中设置的文件名后面的信息。例如,如果设置了“EZNC_DISK_COMMENT | EZNC_DISK_DATE”,则信息如下:
  789. ///文件名\ tDate \ tComment \ 0
  790. ///如果为注释不能注释的文件设置了“EZNC_DISK_SIZE | EZNC_DISK_COMMENT”
  791. ///被添加,注释信息将不会被输出,注释将如下所示:文件名\ tSize \ t \ 0
  792. ///对于日期无法获取的文件,设置“EZNC_DISK_SIZE | EZNC_DISK_DATE | EZNC_DISK_COMMENT“变成如下,没有日期信息输出。文件名\ tSize \ t \ tComment \ 0
  793. ///*日期无法获得的文件是指NC控制单元上的文件侧。
  794. ///由于字符串区域内存在本产品中分配,使用VC ++的客户端需要
  795. ///用CoTaskMemFree()显式释放字符串区域内存。
  796. ///(注1)读取NC侧紧凑型闪存(M700系列)的目录大小信息不支持SD卡(M800系列)。读取的目录大小信息无效。
  797. ///(注2)对于C70,指定个人计算机上的文件并指定0lFileType,\ t被添加到文件信息的结尾(文件名\ t \ 0)。要使用获取的文件信息,请在使用前删除\ t。
  798. ///说明:
  799. ///当使用FindDir2()时,在执行ResetDir()之前,不能执行FindDir2(),OpenFile3(),OpenNcFile2()。
  800. ///执行时,出现“EZNC_FILE_DIR_ALREADYOPENED(0x80030101)不同目录已经打开”的错误。 使用它时,在执行FindDir2()后立即执行ResetDir()。
  801. /// </summary>
  802. public void GetFindDir(string item,out string dirInfo)
  803. {
  804. item = null;
  805. dirInfo = null;
  806. try
  807. {
  808. if (EZNcCom != null)
  809. {
  810. lResult = EZNcCom.File_FindDir2(item, (int)fileDir.EZNC_DISK_SIZE, out dirInfo);
  811. }
  812. }
  813. catch
  814. {
  815. ErrorCheck("通讯已关闭");
  816. }
  817. // lResult = EZNcCom.File_FindNextDir( out sss);
  818. }
  819. /// <summary>
  820. /// 目录检索结束
  821. /// 终止目录搜索。要再次搜索目录,请执行FindDir2()。
  822. /// </summary>
  823. public void ResertDir()
  824. {
  825. try
  826. {
  827. if (EZNcCom != null)
  828. {
  829. lResult = EZNcCom.File_ResetDir();
  830. }
  831. }
  832. catch
  833. {
  834. ErrorCheck("通讯已关闭");
  835. }
  836. }
  837. /// <summary>
  838. /// 空余容量取得
  839. /// 单位bit
  840. /// </summary>
  841. public void GetDriveSize(string path, out int driveInfo)
  842. {
  843. int lppwszDriveInfo;
  844. driveInfo = 0;
  845. try
  846. {
  847. if (EZNcCom != null)
  848. {
  849. lResult = EZNcCom.File_GetDriveSize(path, out lppwszDriveInfo);
  850. if (lResult == 0)
  851. {
  852. driveInfo = lppwszDriveInfo;
  853. }
  854. else
  855. {
  856. ErrorCheck("GetDriveInformation失败");
  857. }
  858. }
  859. }
  860. catch
  861. {
  862. ErrorCheck("通讯已关闭");
  863. }
  864. }
  865. /// <summary>
  866. /// 开放式加工程序专用文件
  867. /// 打开NC程序
  868. /// lpcwszFileName:将包含路径的文件名设置为UNICODE字符串。
  869. /// lMode:设置打开模式。
  870. /// 以下路径以外的路径不能使用。
  871. /// M700系列
  872. /// M01:\ PRG \ USER \加工程序编号
  873. ///M01:\ PRG \ UMACRO \加工程序编号
  874. ///M01:\ PRG \ MMACRO \加工程序编号
  875. ///M01:\ PRG \ FIX \加工程序编号
  876. ///M01:\ PRG \ MDI \加工程序编号
  877. ///M800系列
  878. ///M01:\ PRG \ USER \加工程序名称(32或更少的字母数字字符包括扩展名)
  879. ///M01:\ PRG \ MMACRO \加工程序号(100010000-199999999)
  880. ///M01:\ PRG \ FIX \加工程序号(100000010 -100009999)
  881. ///M01:\ PRG\ MDI\ MDI.PRG
  882. ///function
  883. ///在设定模式下打开加工程序文件。 创建临时文件的目录按以下优先级顺序创建:
  884. ///使用环境变量TMP指定的目录
  885. ///安装产品的目录
  886. ///临时文件名称是“MELDASn”。 一个数字被放置在n中。
  887. ///OpenFile3()不能同时使用。 C70不支持此功能。 (EZ_ERR_NOT_SUPPORT返回到plRet。)
  888. ///(注1)确保使用CloseNCFile2()(或AbortNCFile2())关闭打开的文件。 如果CloseNCFile2()未使用,临时文件将保留。
  889. ///(注2)对于M700 / M800系列,在NC控制单元自动运行期间,可以执行写入或覆盖操作,除非正在执行用于操作的文件的自动操作。 读取操作可以在NC控制单元的自动操作期间执行。
  890. /// </summary>
  891. public void OpenNCFile(string fileName)
  892. {
  893. try
  894. {
  895. if (EZNcCom != null)
  896. {
  897. lResult = EZNcCom.File_OpenNCFile2(fileName, (int)openFileMode.EZNC_FILE_OVERWRITE);
  898. }
  899. }
  900. catch
  901. {
  902. ErrorCheck("通讯已关闭");
  903. }
  904. }
  905. /// <summary>
  906. /// Nc程序文件关闭
  907. /// 关闭加工程序文件。C70不支持此功能。 (EZ_ERR_NOT_SUPPORT返回到plRet。)
  908. ///(注1)对于M700 / M800系列,除非正在执行用于操作的文件的自动操作,否则可以在NC控制单元的自动操作期间执行操作。
  909. ///(注2)使用OpenNCFile2()打开文件时,确保将其关闭CloseNCFile2()(或AborNCtFile2())。
  910. /// </summary>
  911. public void CloseNCFile()
  912. {
  913. try
  914. {
  915. if (EZNcCom != null)
  916. {
  917. lResult = EZNcCom.File_CloseNCFile2();
  918. }
  919. }
  920. catch
  921. {
  922. ErrorCheck("通讯已关闭");
  923. }
  924. }
  925. /// <summary>
  926. /// 读取NC程序
  927. /// 长度:以字节数设置一次读取的数据大小。
  928. /// vData:返回VARIANT中的读取字节数据数组。
  929. ///数据从用OpenNCFile2()打开的加工程序文件中读取。 要读取的数据返回一个字节数据数组及其字节数。 当pdwNumRead小于dwLength时,确定文件结束。
  930. ///设置一次读取的数据大小。 读取大文件时,可以分多个部分读取。 该文件可以按顺序读取,直到执行CloseNCFile2()。
  931. ///C70不支持此功能。 (EZ_ERR_NOT_SUPPORT返回到plRet。)
  932. /// </summary>
  933. public void ReadNcFile(int lLength,out string vData,string filename)
  934. {
  935. object Data = null;
  936. vData = null;
  937. try
  938. {
  939. if (EZNcCom != null)
  940. {
  941. lResult = EZNcCom.File_OpenNCFile2(filename, (int)openFileMode.EZNC_FILE_READ);
  942. lResult = EZNcCom.File_ReadNCFile2(lLength, out Data);
  943. if (lResult == 0)
  944. {
  945. var value = Data as string[];
  946. if (value != null && value.Count() >= 0)
  947. {
  948. vData = value[0];
  949. }
  950. }
  951. else
  952. {
  953. ErrorCheck("ReadNCFile失败");
  954. }
  955. EZNcCom.File_CloseNCFile2();
  956. }
  957. else
  958. {
  959. ErrorCheck("通讯对象未建立");
  960. }
  961. }
  962. catch
  963. {
  964. ErrorCheck("通讯已关闭");
  965. }
  966. }
  967. /// <summary>
  968. /// 写入NC程序
  969. /// 自动化的说法:
  970. ///vData:创建要写入字节数组的数据,并将其替换为vData(VARIANT类型),如下例所示。
  971. ///例)Dim vWriteFile As Variant
  972. ///Dim byteWrite()As Byte
  973. ///vWriteFile = byteWrite
  974. ///function说明
  975. ///数据被写入用OpenNCFile2()打开的加工程序文件中。 要写入的数据是字节数组中的数据。
  976. ///设置一次写入数据的大小。 当写入大量的数据时,它可以被写入多个部分。 数据可以按顺序写入,直到执行CloseNCFile2()。
  977. ///C70不支持此功能。 (EZ_ERR_NOT_SUPPORT返回到plRet。)
  978. ///(注)对于M700 / M800系列,当编辑锁定B(#8105)参数为1时,不能写入程序8000至9999。 当编辑锁定C(#1121)参数为1时,程序9000至9999无法写入。
  979. /// </summary>
  980. public void WriteNcFile(string filename,string data)
  981. {
  982. object vata = data;
  983. try
  984. {
  985. if (EZNcCom != null)
  986. {
  987. lResult = EZNcCom.File_OpenNCFile2(filename, (int)openFileMode.EZNC_FILE_READ);
  988. lResult = EZNcCom.File_WriteNCFile(vata);
  989. EZNcCom.File_CloseNCFile2();
  990. }
  991. }
  992. catch
  993. {
  994. ErrorCheck("通讯已关闭");
  995. }
  996. }
  997. #endregion
  998. public void SetPrograme()
  999. {
  1000. //try
  1001. //{
  1002. string targetPath = "T1.NC";
  1003. lResult = EZNcCom.Operation_Search(targetPath,0,0);
  1004. // EZNcCom.File_OpenNCFile2(targetPath, (int)openFileMode.EZNC_FILE_OVERWRITE);
  1005. EZNcCom.Operation_Run();
  1006. // OpenNCFile(targetPath);
  1007. if (EZNcCom != null)
  1008. {
  1009. lResult = EZNcCom.File_CloseNCFile2();
  1010. }
  1011. //}
  1012. //catch(Exception ex)
  1013. //{
  1014. //}
  1015. //return true;
  1016. }
  1017. /// <summary>
  1018. ///
  1019. /// </summary>
  1020. /// <param name="filename"></param>
  1021. /// <returns></returns>
  1022. /// ///M800系列
  1023. ///M01:\ PRG \ USER \加工程序名称(32或更少的字母数字字符包括扩展名)
  1024. ///M01:\ PRG \ MMACRO \加工程序号(100010000-199999999)
  1025. ///M01:\ PRG \ FIX \加工程序号(100000010 -100009999)
  1026. ///M01:\ PRG\ MDI\ MDI.PRG
  1027. public bool UpdateNCPrgToCNC(string filename)
  1028. {
  1029. string ErrorMsg = "";
  1030. int ErrorCode;
  1031. try
  1032. {
  1033. if (filename == "")
  1034. {
  1035. ErrorMsg = "程序名不能为空.";
  1036. ErrorCode = -1;
  1037. return false;
  1038. }
  1039. if (!File.Exists(filename))
  1040. {
  1041. ErrorMsg = "指定程序不存在.";
  1042. ErrorCode = -1;
  1043. return false;
  1044. };
  1045. //if (!isConnectCNC)
  1046. //{
  1047. // ReConnected();
  1048. //}
  1049. // ReConnected();
  1050. //Data update cnc program from PC to cnc
  1051. //***************************************************************************
  1052. //File_Copy2(lpcwszSrcFileName, lpcwszDstFileName)
  1053. //lResult = dispEZNc_Com.File_Copy2("E:\\TEMP\\9005", "M01:\\PRG\\USER\\9005");
  1054. int index = filename.LastIndexOf("\\") + 1;
  1055. string ncfileName = filename.Substring(index, (filename.Length - index));
  1056. string targetPath = "M01:\\PRG\\USER\\" + ncfileName;
  1057. object content = "";
  1058. //int nRet = EZNcCom.File_Copy2(targetPath, "d:\\test123.NC");
  1059. //targetPath = "M01:\\PRG\\USER\\TEST.NC";
  1060. //string line;
  1061. //StringBuilder sb = new StringBuilder();
  1062. //// 创建一个 StreamReader 的实例来读取文件 ,using 语句也能关闭 StreamReader
  1063. //using (System.IO.StreamReader sr = new System.IO.StreamReader(filename))
  1064. //{
  1065. // // 从文件读取并显示行,直到文件的末尾
  1066. // while ((line = sr.ReadLine()) != null)
  1067. // {
  1068. // //Console.WriteLine(line);
  1069. // sb.Append(line);
  1070. // }
  1071. //}
  1072. //line = sb.ToString();
  1073. //EZNcCom.File_OpenNCFile2(targetPath, (int)openFileMode.EZNC_FILE_OVERWRITE);
  1074. //EZNcCom.File_WriteNCFile(line);
  1075. //EZNcCom.File_CloseNCFile2();
  1076. EZNcCom.File_Delete2(targetPath);
  1077. int nRet = EZNcCom.File_Copy2(filename, targetPath);
  1078. if (nRet == 0)
  1079. {
  1080. ErrorMsg = "";
  1081. ErrorCode = 0;
  1082. return true;
  1083. }
  1084. else
  1085. {
  1086. long retCode = (long)nRet;
  1087. //switch (retCode)
  1088. //{
  1089. // case EZNcCom.EZNC_FILE_COPY_BUSY:
  1090. // ErrorMsg = "Copy is disabled (during operation)";
  1091. // ErrorCode = nRet;
  1092. // break;
  1093. // case EZNcErr.EZNC_FILE_COPY_ENTRYOVER:
  1094. // ErrorMsg = "Registration limit exceeded";
  1095. // ErrorCode = nRet;
  1096. // break;
  1097. // case EZNcErr.EZNC_FILE_COPY_FILEEXIST:
  1098. // ErrorMsg = "Copy destination file already exists";
  1099. // ErrorCode = nRet;
  1100. // break;
  1101. // case EZNcErr.EZNC_FILE_COPY_FILESYSTEM:
  1102. // ErrorMsg = "File system error";
  1103. // ErrorCode = nRet;
  1104. // break;
  1105. // case EZNcErr.EZNC_FILE_COPY_ILLEGALNAME:
  1106. // ErrorMsg = "Invalid file name format";
  1107. // ErrorCode = nRet;
  1108. // break;
  1109. // case EZNcErr.EZNC_FILE_COPY_MEMORYOVER:
  1110. // ErrorMsg = "Memory capacity exceeded";
  1111. // ErrorCode = nRet;
  1112. // break;
  1113. // case EZNcErr.EZNC_FILE_COPY_NODIR:
  1114. // ErrorMsg = "Directory does not exist";
  1115. // ErrorCode = nRet;
  1116. // break;
  1117. // case EZNcErr.EZNC_FILE_COPY_NODRIVE:
  1118. // ErrorMsg = "Drive does not exist";
  1119. // ErrorCode = nRet;
  1120. // break;
  1121. // case EZNcErr.EZNC_FILE_COPY_NOFILE:
  1122. // ErrorMsg = "File does not exist";
  1123. // ErrorCode = nRet;
  1124. // break;
  1125. // case EZNcErr.EZNC_FILE_COPY_PLCRUN:
  1126. // ErrorMsg = "Copy is disabled (programmable controller in operation)";
  1127. // ErrorCode = nRet;
  1128. // break;
  1129. // case EZNcErr.EZNC_FILE_COPY_READ:
  1130. // ErrorMsg = "Transfer source file is not readable";
  1131. // ErrorCode = nRet;
  1132. // break;
  1133. // case EZNcErr.EZNC_FILE_COPY_WRITE:
  1134. // ErrorMsg = "Transfer destination file is not writable";
  1135. // ErrorCode = nRet;
  1136. // break;
  1137. // case EZNcErr.EZNC_FILE_COPY_PROTECT:
  1138. // ErrorMsg = "Copying is disabled (protected)";
  1139. // ErrorCode = nRet;
  1140. // break;
  1141. // case EZNcErr.EZNC_PCFILE_COPY_CREATE:
  1142. // ErrorMsg = "File cannot be created (PC only)";
  1143. // ErrorCode = nRet;
  1144. // break;
  1145. // case EZNcErr.EZNC_PCFILE_COPY_OPEN:
  1146. // ErrorMsg = "File cannot be opened (personal computer only)";
  1147. // ErrorCode = nRet;
  1148. // break;
  1149. // default:
  1150. // ErrorMsg = "UpdateNCPrgToCNC Error";
  1151. // ErrorCode = -1;
  1152. // break;
  1153. //}
  1154. return false;
  1155. }
  1156. }
  1157. catch (Exception ex)
  1158. {
  1159. ErrorMsg = ex.Message + ex.StackTrace;
  1160. return false;
  1161. }
  1162. finally
  1163. {
  1164. // FreeConnected();
  1165. }
  1166. }
  1167. /// <summary>
  1168. /// 错误代码提示
  1169. /// </summary>
  1170. /// <param name="szMethod"></param>
  1171. private void ErrorCheck(string szMethod)
  1172. {
  1173. if (EZNcCom != null)
  1174. {
  1175. if (lResult != 0)
  1176. {
  1177. szMessage = szMethod + " Failed. " + "0x" + Convert.ToString(lResult, 16) + szMessage + "\r\n";
  1178. }
  1179. else
  1180. {
  1181. szMessage = szMethod + "通讯正常";
  1182. }
  1183. }
  1184. else
  1185. {
  1186. szMessage = szMethod;
  1187. }
  1188. //发布事件
  1189. if (AlarmData != null&&szMessage!=""&&szMessage!=null)
  1190. {
  1191. AlarmData(szMessage);
  1192. }
  1193. szMessage = "";
  1194. }
  1195. }
  1196. }