版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1680 rivejä
69 KiB

  1. using CCWin.SkinClass;
  2. using MaiMuControl.SysStatusMgr.UserMgr;
  3. using Models;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using ToolKits.Ini;
  16. using ToolKits.mAPI;
  17. using ToolKits.PLC;
  18. namespace MaiMuAOI.SysCtrl
  19. {
  20. #region 参数类型
  21. /// <summary>
  22. /// 图片保存参数
  23. /// </summary>
  24. [Serializable]
  25. public class ImageSaveParam
  26. {
  27. /// <summary>
  28. /// 保存路径
  29. /// </summary>
  30. public string SavePath { get; set; }
  31. /// <summary>
  32. /// 自动保存
  33. /// </summary>
  34. public bool AutoSave { get; set; }
  35. /// <summary>
  36. /// 自动删除
  37. /// </summary>
  38. public bool AutoDelete { get; set; }
  39. /// <summary>
  40. /// 自动删除日期
  41. /// </summary>
  42. public double AutoDeleteDays { get; set; }
  43. public ImageSaveParam() {
  44. SavePath = "D:\\AllImageSave";
  45. AutoSave = true;
  46. AutoDelete = true;
  47. AutoDeleteDays = 3;
  48. }
  49. public ImageSaveParam(string path)
  50. {
  51. SavePath = path;
  52. AutoSave = true;
  53. AutoDelete = true;
  54. AutoDeleteDays = 3;
  55. }
  56. }
  57. /// <summary>
  58. /// 镜头对应Z轴高度
  59. /// </summary>
  60. [Serializable]
  61. public class LensAxisZ
  62. {
  63. public double Z_0_58X { get; set; }
  64. //public double Z_0_6X { get; set; }
  65. public double Z_1_0X { get; set; }
  66. public double Z_1_5X { get; set; }
  67. public double Z_2_0X { get; set; }
  68. public double Z_2_5X { get; set; }
  69. public double Z_3_0X { get; set; }
  70. public double Z_3_5X { get; set; }
  71. public double Z_4_0X { get; set; }
  72. public double Z_4_5X { get; set; }
  73. public double Z_5_0X { get; set; }
  74. public double Z_5_5X { get; set; }
  75. public double Z_6_0X { get; set; }
  76. public double Z_6_5X { get; set; }
  77. public double Z_7_0X { get; set; }
  78. public double Z_7_5X { get; set; }
  79. public LensAxisZ()
  80. {
  81. Z_0_58X = 0;
  82. //Z_0_6X = 0;
  83. Z_1_0X = 0;
  84. Z_1_5X = 0;
  85. Z_2_0X = 0;
  86. Z_2_5X = 0;
  87. Z_3_0X = 0;
  88. Z_3_5X = 0;
  89. Z_4_0X = 0;
  90. Z_4_5X = 0;
  91. Z_5_0X = 0;
  92. Z_5_5X = 0;
  93. Z_6_0X = 0;
  94. Z_6_5X = 0;
  95. Z_7_0X = 0;
  96. Z_7_5X = 0;
  97. }
  98. }
  99. [Serializable]
  100. public class SysConfigParams
  101. {
  102. #region 缺陷图
  103. /// <summary>
  104. /// 存图一级路径
  105. /// </summary>
  106. public string AllImages_SavePath { get; set; }
  107. public string Defect_SrcSmall_SavePath { get; set; }
  108. public double Defect_SrcSmall_Thres { get; set; }
  109. /// <summary>
  110. /// 保存所有图片
  111. /// </summary>
  112. public bool SaveAllImg { get; set; }
  113. /// <summary>
  114. /// 缺陷大图
  115. /// </summary>
  116. public ImageSaveParam DefectBigImag { get; set; }
  117. /// <summary>
  118. /// 缺陷原始小图
  119. /// </summary>
  120. public ImageSaveParam DefectSrcSmallImag { get; set; }
  121. /// <summary>
  122. /// 缺陷小图
  123. /// </summary>
  124. public ImageSaveParam DefectSmallImag { get; set; }
  125. /// <summary>
  126. /// 修复台 缺陷图
  127. /// </summary>
  128. public ImageSaveParam DefectRepairImag { get; set; }
  129. /// <summary>
  130. /// 对比大图
  131. /// </summary>
  132. public ImageSaveParam SizeBigImag { get; set; }
  133. /// <summary>
  134. /// 对比未通过
  135. /// </summary>
  136. public ImageSaveParam SizeNGImag { get; set; }
  137. /// <summary>
  138. /// 修复台 对比图
  139. /// </summary>
  140. public ImageSaveParam SizeRepairImag { get; set; }
  141. #endregion
  142. #region 功能
  143. /// <summary>
  144. /// mark报警暂停
  145. /// </summary>
  146. public bool OpenMarkErrorStop { get; set; }
  147. /// <summary>
  148. /// 开启蜂鸣器
  149. /// </summary>
  150. public bool OpenBuzzer { get; set; }
  151. /// <summary>
  152. /// 开启门磁
  153. /// </summary>
  154. public bool OpenDoor { get; set; }
  155. /// <summary>
  156. /// 开启http日志
  157. /// </summary>
  158. public bool OpenHttpLog { get; set; }
  159. /// <summary>
  160. /// 开启软件开启自动回原
  161. /// </summary>
  162. public bool OpenAutoGoHome { get; set; }
  163. /// <summary>
  164. /// 启用缺陷分布功能
  165. /// </summary>
  166. public bool OpenFlawDistribution { get; set; }
  167. /// <summary>
  168. /// 启用X轴校准 2023-12-20
  169. /// </summary>
  170. public bool OpenAxisXCalibration { get; set; }
  171. /// <summary>
  172. /// 产品有无信号关闭
  173. /// </summary>
  174. public bool OpenPdtIsHave { get; set; }
  175. /// <summary>
  176. /// 开启查看功能
  177. /// </summary>
  178. public bool OpenDefectSanp { get; set; }
  179. /// <summary>
  180. /// 开启单边目数计算
  181. /// </summary>
  182. public bool OpenAsideDefect{ get; set; }
  183. /// <summary>
  184. /// 开启工单确认
  185. /// </summary>
  186. public bool OpenOredrCheck { get; set; }
  187. /// <summary>
  188. /// 开启工单数量确认
  189. /// </summary>
  190. public bool OpenOredrCntCheck { get; set; }
  191. /// <summary>
  192. /// 开启显示打标图片
  193. /// </summary>
  194. public bool OpenShowDB { get; set; }
  195. /// <summary>
  196. /// 开启彩色相机使用B通道
  197. /// </summary>
  198. public bool OpenColorB { get; set; }
  199. /// <summary>
  200. /// 开启比对和缺陷去重复
  201. /// </summary>
  202. public bool OpenRemoveDuplicates { get; set; }
  203. #endregion
  204. #region 硬件传感器通信
  205. /// <summary>
  206. /// 光源串口
  207. /// </summary>
  208. //public LightParams LightCfg { get; set; }
  209. public string LightCom { get; set; }
  210. /// <summary>
  211. /// 光源波特率
  212. /// </summary>
  213. public int LightComBaud { get; set; }
  214. /// <summary>
  215. /// 张力传感器串口
  216. /// </summary>
  217. public string TensionCom { get; set; }
  218. /// <summary>
  219. /// 张力传感器波特率
  220. /// </summary>
  221. public int TensionComBaud { get; set; }
  222. /// <summary>
  223. /// 张力偏移值
  224. /// </summary>
  225. public double Tension_Offset = 0;
  226. /// <summary>
  227. /// 镜头电机串口
  228. /// </summary>
  229. public string LensMotorCom { get; set; }
  230. /// <summary>
  231. /// 镜头电机波特率
  232. /// </summary>
  233. public int LensMotorComBaud { get; set; }
  234. /// <summary>
  235. /// 厚度传感器IP
  236. /// </summary>
  237. public string ThicknessIP { get; set; }
  238. /// <summary>
  239. /// 厚度传感器port
  240. /// </summary>
  241. public int ThicknessPort { get; set; }
  242. /// <summary>
  243. /// 测厚安全值
  244. /// </summary>
  245. public double ThicknessSafeValue { get; set; }
  246. /// <summary>
  247. /// 测厚调试偏移值
  248. /// </summary>
  249. public double Thickness_Offset = 0;
  250. #endregion
  251. #region IO/电机/相机
  252. /// <summary>
  253. /// IO驱动名称
  254. /// </summary>
  255. //public IOParams IOCfg { get; set; }
  256. public string IODevName { get; set; }
  257. /// <summary>
  258. /// IO配置文件路径
  259. /// </summary>
  260. public string IOCfgPath { get; set; }
  261. /// <summary>
  262. /// 电机配置文件路径
  263. /// </summary>
  264. public string MotionCfgPath { get; set; }
  265. /// <summary>
  266. /// 前部相机名称
  267. /// </summary>
  268. public string FrontCamName { get; set; }
  269. /// <summary>
  270. /// 前部相机配置文件路径
  271. /// </summary>
  272. public string FrontCamCfgPath { get; set; }
  273. /// <summary>
  274. /// 后部相机名称
  275. /// </summary>
  276. public string BackCamName { get; set; }
  277. /// <summary>
  278. /// 后部相机配置文件路径
  279. /// </summary>
  280. public string BackCamCfgPath { get; set; }
  281. #endregion
  282. #region 禁用
  283. public bool DisableX1 { get; set; }
  284. public bool DisableX2 { get; set; }
  285. public bool DisableY { get; set; }
  286. public bool DisableZ { get; set; }
  287. public bool DisableFrontCam { get; set; }
  288. public bool DisableBackCam { get; set; }
  289. public bool DisableLight { get; set; }
  290. public bool DisableTensor { get; set; }
  291. public bool DisableThickness { get; set; }
  292. public bool DisableLensMotor { get; set; }
  293. #endregion
  294. #region 系统
  295. public string ImageProcessPath { get; set; }
  296. public string ImageProcessDataPath { get; set; }
  297. public string AIModelPath { get; set; }
  298. public string ProductPath { get; set; }
  299. public string HttpServerIP { get; set; }
  300. public int HttpServerPort { get; set; }
  301. public string LogPath { get; set; }
  302. public bool AutoDeleteLog { get; set; }
  303. public double AutoDeleteLogData { get; set; }
  304. /// <summary>
  305. /// 调试:主界面显示复位按钮
  306. /// </summary>
  307. public bool ShowResetBtn { get; set; }
  308. /// <summary>
  309. /// 调试:主界面显示蜂鸣器控制
  310. /// </summary>
  311. public bool ShowBuzz { get; set; }
  312. /// <summary>
  313. /// 调试:主界面显示门磁报警控制
  314. /// </summary>
  315. public bool ShowDoorAlm { get; set; }
  316. /// <summary>
  317. /// 调试:显示分布
  318. /// </summary>
  319. public bool ShowDistribution { get; set; }
  320. /// <summary>
  321. /// 调试:显示尺寸检测禁用和启用
  322. /// </summary>
  323. public bool ShowSizeBtn { get; set; }
  324. /// <summary>
  325. /// 调试:显示缺陷检测禁用和启用
  326. /// </summary>
  327. public bool ShowDefectBtn { get; set; }
  328. /// <summary>
  329. /// 后部相机视野X
  330. /// </summary>
  331. public double DefectCamViewX { get; set; }
  332. /// <summary>
  333. /// 后部相机视野Y
  334. /// </summary>
  335. public double DefectCamViewY { get; set; }
  336. #endregion
  337. #region Http/MES
  338. /// <summary>
  339. /// 开启http上传
  340. /// </summary>
  341. public bool EnableHttp { get; set; }
  342. /// <summary>
  343. /// 上传Http地址
  344. /// </summary>
  345. public string HttpUrl { get; set; }
  346. /// <summary>
  347. /// 上传Json模板路径
  348. /// </summary>
  349. public string HttpTempPath { get; set; }
  350. /// <summary>
  351. /// 返回值Key
  352. /// </summary>
  353. public string HttpReturnKey{ get; set; }
  354. /// <summary>
  355. /// 返回成功value
  356. /// </summary>
  357. public string HttpReturnValue { get; set; }
  358. #endregion
  359. #region MQTT本地云/产品服务器
  360. /// <summary>
  361. /// 开启局域网云端
  362. /// </summary>
  363. public bool OpenCloud { get; set; }
  364. public string CloudThisName { get; set; }
  365. public string CloudServerIP { get; set; }
  366. public int CloudServerPort { get; set; }
  367. public string CloudUser { get; set; }
  368. public string CloudPassword { get; set; }
  369. /// <summary>
  370. /// 开启产品转发
  371. /// </summary>
  372. public bool OpenPdtServer { get; set; }
  373. public string PdtServerIP { get; set; }
  374. public int PdtServerPort { get; set; }
  375. /// <summary>
  376. /// 是否作为服务器还是客户端
  377. /// </summary>
  378. public bool IsPdtServer { get; set; }
  379. #endregion
  380. #region 聚焦
  381. /// <summary>
  382. /// 聚焦对应Z轴位置
  383. /// </summary>
  384. public LensAxisZ LensAxisZPos { get; set; }
  385. #endregion
  386. #region 缺陷分割
  387. //缺陷配置
  388. public Size Defect_CutSize { get; set; }
  389. public Size Defect_ReSize { get; set; }
  390. public float Defect_Thresholds { get; set; }
  391. #endregion
  392. #region BarTender
  393. /// <summary>
  394. /// 开启标签打印
  395. /// </summary>
  396. public bool EnableLabelPrint { get; set; }
  397. /// <summary>
  398. /// 打印机名称
  399. /// </summary>
  400. public string LabelPrinterName { get; set; }
  401. /// <summary>
  402. /// 打印模板路径
  403. /// </summary>
  404. public string LabelTempPath { get; set; }
  405. /// <summary>
  406. /// 打印信息
  407. /// </summary>
  408. public Dictionary<string, string> LabelData { get; set; }
  409. #endregion
  410. #region Excel
  411. /// <summary>
  412. /// 开启Excel打印
  413. /// </summary>
  414. public bool EnableExcelPrint { get; set; }
  415. /// <summary>
  416. /// 打印机名称
  417. /// </summary>
  418. public string ExcelPrinterName { get; set; }
  419. /// <summary>
  420. /// 打印模板路径
  421. /// </summary>
  422. public string ExcelTempPath { get; set; }
  423. /// <summary>
  424. /// 打印信息
  425. /// </summary>
  426. public Dictionary<string, string> ExcelData { get; set; }
  427. #endregion
  428. #region 老流程PT线宽补偿
  429. public double Pt_offset { get; set; }
  430. public double Line_offset { get; set; }
  431. #endregion
  432. #region 左上角比例调整
  433. public double X_per{ get; set; }
  434. public double Y_per { get; set; }
  435. #endregion
  436. #region 缺陷查看
  437. public int LightCH { get; set; }
  438. public int LightLut { get; set; }
  439. public int CamExposureTime { get; set; }
  440. #endregion
  441. #region 其他
  442. /// <summary>
  443. /// 光源通道
  444. /// </summary>
  445. public int LightChannelCnt { get; set; }
  446. /// <summary>
  447. /// 客户名称,不同客户可能存在差异
  448. /// </summary>
  449. public string CustomerName { get; set; }
  450. /// <summary>
  451. /// 缺陷相机分辨率
  452. /// </summary>
  453. public double DefectCamPixel { get; set; }
  454. /// <summary>
  455. /// 自动计算步进偏移
  456. /// </summary>
  457. public double DefectAutoX { get; set; }
  458. /// <summary>
  459. /// 自动计算步进偏移
  460. /// </summary>
  461. public double DefectAutoY { get; set; }
  462. #endregion
  463. public SysConfigParams()
  464. {
  465. AllImages_SavePath = "D:\\Image";
  466. DefectBigImag = new ImageSaveParam("D:\\Image\\缺陷大图");
  467. DefectSrcSmallImag = new ImageSaveParam("D:\\Image\\缺陷原始小图");
  468. DefectSmallImag = new ImageSaveParam("D:\\Image\\缺陷小图");
  469. DefectRepairImag = new ImageSaveParam("D:\\Image\\缺陷压缩大图(修复台)");
  470. SizeBigImag = new ImageSaveParam("D:\\Image\\尺寸图");
  471. SizeNGImag = new ImageSaveParam("D:\\Image\\比对未通过图片");
  472. SizeRepairImag = new ImageSaveParam("D:\\Image\\比对未通过打标图片");
  473. OpenMarkErrorStop = true;
  474. OpenBuzzer = true;
  475. OpenDoor = true;
  476. OpenHttpLog = false;
  477. OpenPdtIsHave = true;
  478. OpenDefectSanp = false;
  479. OpenAsideDefect = true;
  480. OpenOredrCheck = false;
  481. OpenOredrCntCheck = false;
  482. OpenShowDB = false;
  483. //LightCfg = new LightParams();
  484. //IOCfg = new IOParams();
  485. IODevName = "PCI-1730,BID#0";
  486. IOCfgPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\IOCard_default.xml"); ;
  487. LightCom = "COM2";
  488. LightComBaud = 9600;
  489. LensMotorCom = "COM1";
  490. LensMotorComBaud = 9600;
  491. TensionCom = "COM3";
  492. TensionComBaud = 2400;
  493. ThicknessIP = "192.168.0.50";
  494. ThicknessPort = 64000;
  495. ThicknessSafeValue = 10;
  496. FrontCamCfgPath = "";
  497. BackCamCfgPath = "C:\\Program Files (x86)\\Common Files\\MVS\\Runtime\\Win64_x64\\MvFGProducerCXP.cti";
  498. MotionCfgPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\Axis_default.cfg"); ;
  499. SaveAllImg = true;
  500. DisableX1 = false;
  501. DisableX2 = false;
  502. DisableY = false;
  503. DisableZ = false;
  504. DisableFrontCam = false;
  505. DisableBackCam = false;
  506. DisableLight = false;
  507. DisableLensMotor = false;
  508. DisableTensor = false;
  509. DisableThickness = false;
  510. ImageProcessPath = "C:\\Users\\user\\AppData\\Local\\Programs\\MVTec\\HALCON-21.05-Progress\\procedures\\general";
  511. ImageProcessDataPath = "C:\\Users\\PC\\AppData\\Local\\Programs\\MVTec\\HALCON-21.05-Progress\\procedures\\User_Data\\HomMat2D1M2CCDpose";
  512. AIModelPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\onnxFiles");
  513. ProductPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles\\Project");
  514. HttpServerIP = "192.168.123.100";
  515. HttpServerPort = 18082;
  516. LogPath = Path.Combine(Directory.GetCurrentDirectory(), "LogFiles");
  517. AutoDeleteLog = false;
  518. AutoDeleteLogData = 0;
  519. ShowResetBtn = true;
  520. ShowBuzz = false;
  521. ShowDoorAlm = false;
  522. ShowDistribution = false;
  523. ShowSizeBtn = false;
  524. ShowDefectBtn = false;
  525. DefectCamViewX = 35.5;
  526. DefectCamViewY = 26.5;
  527. EnableHttp = false;
  528. HttpUrl = "";
  529. HttpTempPath = "";
  530. HttpReturnKey = "";
  531. HttpReturnValue = "";
  532. LensAxisZPos = new LensAxisZ();
  533. //缺陷配置
  534. Defect_CutSize = new Size(592, 532);
  535. Defect_ReSize = new Size(224, 224);
  536. Defect_Thresholds = 0.4f;
  537. EnableLabelPrint = false;
  538. LabelPrinterName = "";
  539. LabelTempPath = "";
  540. LabelData = new Dictionary<string, string>();
  541. EnableExcelPrint = false;
  542. ExcelPrinterName = "";
  543. ExcelTempPath = "";
  544. ExcelData = new Dictionary<string, string>();
  545. OpenCloud = false;
  546. CloudThisName = "Test";
  547. CloudServerIP = "127.0.0.1";
  548. CloudServerPort = 1883;
  549. CloudUser = "";
  550. CloudPassword = "";
  551. OpenPdtServer = false;
  552. PdtServerIP = "127.0.0.1";
  553. PdtServerPort = 10573;
  554. IsPdtServer = true;
  555. Pt_offset = 0;
  556. Line_offset = 0;
  557. X_per = 0.1;
  558. Y_per = 0.1;
  559. LightCH = 2;
  560. LightLut = 255;
  561. CamExposureTime = 8000;
  562. LightChannelCnt = 4;
  563. CustomerName = "";
  564. DefectCamPixel = 0.002515;
  565. }
  566. }
  567. #endregion
  568. #region 尺寸检测参数
  569. public class SizeItemParam
  570. {
  571. /// <summary>
  572. /// 名称
  573. /// </summary>
  574. public string Name { get; set; }
  575. /// <summary>
  576. /// 代码
  577. /// </summary>
  578. public string Code { get; set; }
  579. /// <summary>
  580. /// 测试点数
  581. /// </summary>
  582. public int PointCnt { get; set; }
  583. /// <summary>
  584. /// 处理代码
  585. /// </summary>
  586. public int[] DefectIndex { get; set; }
  587. /// <summary>
  588. /// RGB颜色代码
  589. /// </summary>
  590. public int[] RGBcolor { get; set; }
  591. /// <summary>
  592. /// 显示单位 0:程序默认 1:mm 2:um
  593. /// </summary>
  594. public int mmOrum { get; set; }
  595. /// <summary>
  596. /// 显示小数点后位数 0:默认4位。
  597. /// </summary>
  598. public int dataLen { get; set; }
  599. }
  600. #endregion
  601. #region 缺陷检测参数
  602. public class DefectItemParam
  603. {
  604. /// <summary>
  605. /// 名称
  606. /// </summary>
  607. public string Name { get; set; }
  608. /// <summary>
  609. /// 代码
  610. /// </summary>
  611. public string Code { get; set; }
  612. /// <summary>
  613. /// 序号
  614. /// </summary>
  615. public int Index { get; set; }
  616. /// <summary>
  617. /// 默认分值
  618. /// </summary>
  619. public double Threshold { get; set; }
  620. /// <summary>
  621. /// RGB颜色代码
  622. /// </summary>
  623. public int[] RGBcolor { get; set; }
  624. /// <summary>
  625. /// 对应类型
  626. /// </summary>
  627. public string Type { get; set; }
  628. /// <summary>
  629. /// 尺寸
  630. /// </summary>
  631. public float Size { get; set; }
  632. /// <summary>
  633. /// 最大允许缺陷数量
  634. /// </summary>
  635. public int MaxDefectCount { get; set; }
  636. /// <summary>
  637. /// 显示
  638. /// </summary>
  639. public int Show { get; set; }
  640. }
  641. #endregion
  642. /// <summary>
  643. /// 设备参数
  644. /// </summary>
  645. public class ConfMgr
  646. {
  647. #region 实例化
  648. /// <summary>
  649. /// 实例
  650. /// </summary>
  651. private static ConfMgr _instance;
  652. private static readonly object _lock = new object();
  653. public static ConfMgr Instance
  654. {
  655. get
  656. {
  657. if (_instance == null)
  658. {
  659. lock (_lock)
  660. {
  661. if (_instance == null)
  662. {
  663. _instance = new ConfMgr();
  664. }
  665. }
  666. }
  667. return _instance;
  668. }
  669. }
  670. #endregion
  671. #region 私有字段
  672. private readonly string _rootPath;
  673. private readonly string _configFile;
  674. private readonly string _projectDir;
  675. private readonly string _pointsPath;
  676. private readonly string _markPicPath;
  677. private readonly string _sizeItemsPath;
  678. private readonly string _defectItemsPath;
  679. private readonly string _sizeCompItemsPath;
  680. #endregion
  681. private ConfMgr()
  682. {
  683. _rootPath = Path.Combine(Directory.GetCurrentDirectory(), "ConfigFiles");
  684. _configFile = Path.Combine(_rootPath, "SysParamsConfig.ini");
  685. _devConfigPath = Path.Combine(_rootPath, "DevParamsConfig.ini");
  686. _projectDir = Path.Combine(_rootPath, "Project");
  687. _pointsPath = Path.Combine(_rootPath, "PointsConfig.ini");
  688. _markPicPath = Path.Combine(_rootPath, "MarkPic");
  689. _specificationPath = Path.Combine(_rootPath, "版博士软件操作说明.docx");
  690. _sizeItemsPath = Path.Combine(_rootPath, "尺寸测试项.json");
  691. _defectItemsPath = Path.Combine(_rootPath, "缺陷测试项.json");
  692. _sizeCompItemsPath = Path.Combine(_rootPath, "比对测试项.json");
  693. DBConStr = "server = localhost; Database = ProductionDB; Uid = root; Pwd = " + ConteolUserDB.GetSqlDBCode() + "; AllowLoadLocalInfile = true;";
  694. }
  695. #region 公开字段
  696. //DB
  697. //有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
  698. //如果用到bulkCopy需要加: AllowLoadLocalInfile=true
  699. //public static string dbMysqlCon = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456;";
  700. public string DBConStr = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  701. /// <summary>
  702. /// 系统配置参数
  703. /// </summary>
  704. public SysConfigParams SysConfigParams { get; set; }
  705. private string _devConfigPath;
  706. /// <summary>
  707. /// 获取驱动配制文件路径
  708. /// </summary>
  709. public string DevConfigPath { get { return _devConfigPath; } }
  710. //public string ProjectDir { get { return _projectDir; } }
  711. public string ProjectDir { get { return SysConfigParams.ProductPath; } }
  712. public string MarkPicPath { get { return _markPicPath; } }
  713. /// <summary>
  714. /// 说明书路径
  715. /// </summary>
  716. public string SpecificationPath { get { return _specificationPath; } }
  717. private string _specificationPath;
  718. /// <summary>
  719. /// 上料位X1
  720. /// </summary>
  721. public double LoadPoint_X1 { get; set; }
  722. /// <summary>
  723. /// 上料位X2
  724. /// </summary>
  725. public double LoadPoint_X2 { get; set; }
  726. /// <summary>
  727. /// 上料位Y
  728. /// </summary>
  729. public double LoadPoint_Y { get; set; }
  730. /// <summary>
  731. /// 上料位Z
  732. /// </summary>
  733. public double LoadPoint_Z { get; set; }
  734. /// <summary>
  735. /// 测厚气缸到位等待时间
  736. /// </summary>
  737. public int HeightDoWait { get; set; }
  738. /// <summary>
  739. /// 加紧气缸到位等待时间
  740. /// </summary>
  741. public int ProductDoWait { get; set; }
  742. #endregion
  743. #region 公开文件操作
  744. #region 点位配置
  745. public void WritePointsAndTime(double x1, double x2, double y, double z, int ht, int pt)
  746. {
  747. //XmlHelper.Serialize<SysConfParams>(_configFile, sysConfParams);
  748. IniHelper iniHelper = new IniHelper(_pointsPath);
  749. iniHelper.WriteDouble("LoadPoint", "X1", x1);
  750. iniHelper.WriteDouble("LoadPoint", "X2", x2);
  751. iniHelper.WriteDouble("LoadPoint", "Y", y);
  752. iniHelper.WriteDouble("LoadPoint", "Z", z);
  753. iniHelper.WriteInteger("WaitTime", "HeightDoWait", ht);
  754. iniHelper.WriteInteger("WaitTime", "ProductDoWait", pt);
  755. LoadPoint_X1 = x1;
  756. LoadPoint_X2 = x2;
  757. LoadPoint_Y = y;
  758. LoadPoint_Z = z;
  759. HeightDoWait = ht;
  760. ProductDoWait = pt;
  761. }
  762. public void ReadPointsAndTime()
  763. {
  764. IniHelper iniHelper = new IniHelper(_pointsPath);
  765. double dValue = 0;
  766. int iValue = 0;
  767. iniHelper.ReadDouble("LoadPoint", "X1", out dValue);
  768. LoadPoint_X1 = dValue;
  769. iniHelper.ReadDouble("LoadPoint", "X2", out dValue);
  770. LoadPoint_X2 = dValue;
  771. iniHelper.ReadDouble("LoadPoint", "Y", out dValue);
  772. LoadPoint_Y = dValue;
  773. iniHelper.ReadDouble("LoadPoint", "Z", out dValue);
  774. LoadPoint_Z = dValue;
  775. iniHelper.ReadInteger("WaitTime", "HeightDoWait", out iValue);
  776. HeightDoWait = iValue;
  777. iniHelper.ReadInteger("WaitTime", "ProductDoWait", out iValue);
  778. ProductDoWait = iValue;
  779. }
  780. #endregion
  781. #region 系统配置参数
  782. /// <summary>
  783. /// 写入ini
  784. /// </summary>
  785. /// <param name="SocketParams"></param>
  786. public void WriteSysConfParams(SysConfigParams SysParams)
  787. {
  788. //XmlHelper.Serialize<SysConfParams>(_configFile, sysConfParams);
  789. IniHelper iniHelper = new IniHelper(_configFile);
  790. iniHelper.WriteString("ImagesPath", "AllImages_SavePath", SysParams.AllImages_SavePath);
  791. iniHelper.WriteString("DefectSrcSmallImag", "Defect_SrcSmall_SavePath", SysParams.Defect_SrcSmall_SavePath);
  792. iniHelper.WriteDouble("DefectSrcSmallImag", "Defect_SrcSmall_Thres", SysParams.Defect_SrcSmall_Thres);
  793. iniHelper.WriteBool("SaveAllImg", "SaveAllImg", SysParams.SaveAllImg);
  794. iniHelper.WriteString("DefectBigImag", "SavePath", SysParams.DefectBigImag.SavePath);
  795. iniHelper.WriteBool("DefectBigImag", "AutoSave", SysParams.DefectBigImag.AutoSave);
  796. iniHelper.WriteBool("DefectBigImag", "AutoDelete", SysParams.DefectBigImag.AutoDelete);
  797. iniHelper.WriteDouble("DefectBigImag", "AutoDeleteDays", SysParams.DefectBigImag.AutoDeleteDays);
  798. iniHelper.WriteString("DefectSrcSmallImag", "SavePath", SysParams.DefectSrcSmallImag.SavePath);
  799. iniHelper.WriteBool("DefectSrcSmallImag", "AutoSave", SysParams.DefectSrcSmallImag.AutoSave);
  800. iniHelper.WriteBool("DefectSrcSmallImag", "AutoDelete", SysParams.DefectSrcSmallImag.AutoDelete);
  801. iniHelper.WriteDouble("DefectSrcSmallImag", "AutoDeleteDays", SysParams.DefectSrcSmallImag.AutoDeleteDays);
  802. iniHelper.WriteString("DefectSmallImag", "SavePath", SysParams.DefectSmallImag.SavePath);
  803. iniHelper.WriteBool("DefectSmallImag", "AutoSave", SysParams.DefectSmallImag.AutoSave);
  804. iniHelper.WriteBool("DefectSmallImag", "AutoDelete", SysParams.DefectSmallImag.AutoDelete);
  805. iniHelper.WriteDouble("DefectSmallImag", "AutoDeleteDays", SysParams.DefectSmallImag.AutoDeleteDays);
  806. iniHelper.WriteString("DefectRepairImag", "SavePath", SysParams.DefectRepairImag.SavePath);
  807. iniHelper.WriteBool("DefectRepairImag", "AutoSave", SysParams.DefectRepairImag.AutoSave);
  808. iniHelper.WriteBool("DefectRepairImag", "AutoDelete", SysParams.DefectRepairImag.AutoDelete);
  809. iniHelper.WriteDouble("DefectRepairImag", "AutoDeleteDays", SysParams.DefectRepairImag.AutoDeleteDays);
  810. iniHelper.WriteString("SizeBigImag", "SavePath", SysParams.SizeBigImag.SavePath);
  811. iniHelper.WriteBool("SizeBigImag", "AutoSave", SysParams.SizeBigImag.AutoSave);
  812. iniHelper.WriteBool("SizeBigImag", "AutoDelete", SysParams.SizeBigImag.AutoDelete);
  813. iniHelper.WriteDouble("SizeBigImag", "AutoDeleteDays", SysParams.SizeBigImag.AutoDeleteDays);
  814. iniHelper.WriteString("SizeNGImag", "SavePath", SysParams.SizeNGImag.SavePath);
  815. iniHelper.WriteBool("SizeNGImag", "AutoSave", SysParams.SizeNGImag.AutoSave);
  816. iniHelper.WriteBool("SizeNGImag", "AutoDelete", SysParams.SizeNGImag.AutoDelete);
  817. iniHelper.WriteDouble("SizeNGImag", "AutoDeleteDays", SysParams.SizeNGImag.AutoDeleteDays);
  818. iniHelper.WriteString("SizeRepairImag", "SavePath", SysParams.SizeRepairImag.SavePath);
  819. iniHelper.WriteBool("SizeRepairImag", "AutoSave", SysParams.SizeRepairImag.AutoSave);
  820. iniHelper.WriteBool("SizeRepairImag", "AutoDelete", SysParams.SizeRepairImag.AutoDelete);
  821. iniHelper.WriteDouble("SizeRepairImag", "AutoDeleteDays", SysParams.SizeRepairImag.AutoDeleteDays);
  822. iniHelper.WriteString("Log", "SavePath", SysParams.LogPath);
  823. iniHelper.WriteBool("Log", "AutoDelete", SysParams.AutoDeleteLog);
  824. iniHelper.WriteDouble("Log", "AutoDeleteDays", SysParams.AutoDeleteLogData);
  825. iniHelper.WriteBool("SysFunction", "OpenMarkErrorStop", SysParams.OpenMarkErrorStop);
  826. iniHelper.WriteBool("SysFunction", "OpenBuzzer", SysParams.OpenBuzzer);
  827. iniHelper.WriteBool("SysFunction", "OpenDoor", SysParams.OpenDoor);
  828. iniHelper.WriteBool("SysFunction", "OpenHttpLog", SysParams.OpenHttpLog);
  829. iniHelper.WriteBool("SysFunction", "OpenAutoGoHome", SysParams.OpenAutoGoHome);
  830. iniHelper.WriteBool("SysFunction", "OpenFlawDistribution", SysParams.OpenFlawDistribution);
  831. iniHelper.WriteBool("SysFunction", "OpenAxisXCalibration", SysParams.OpenAxisXCalibration);
  832. iniHelper.WriteBool("SysFunction", "OpenPdtIsHave", SysParams.OpenPdtIsHave);
  833. iniHelper.WriteBool("SysFunction", "OpenDefectSanp", SysParams.OpenDefectSanp);
  834. iniHelper.WriteBool("SysFunction", "OpenAsideDefect", SysParams.OpenAsideDefect);
  835. iniHelper.WriteBool("SysFunction", "OpenOredrCheck", SysParams.OpenOredrCheck);
  836. iniHelper.WriteBool("SysFunction", "OpenOredrCntCheck", SysParams.OpenOredrCntCheck);
  837. iniHelper.WriteBool("SysFunction", "OpenShowDB", SysParams.OpenShowDB);
  838. iniHelper.WriteBool("SysFunction", "OpenColorB", SysParams.OpenColorB);
  839. iniHelper.WriteBool("SysFunction", "OpenRemoveDuplicates", SysParams.OpenRemoveDuplicates);
  840. iniHelper.WriteString("Dev", "LightCom", SysParams.LightCom);
  841. iniHelper.WriteInteger("Dev", "LightComBaud", SysParams.LightComBaud);
  842. iniHelper.WriteString("Dev", "TensionCom", SysParams.TensionCom);
  843. iniHelper.WriteInteger("Dev", "TensionComBaud", SysParams.TensionComBaud);
  844. iniHelper.WriteDouble("Dev", "Tension_Offset", SysParams.Tension_Offset);
  845. iniHelper.WriteString("Dev", "LensMotorCom", SysParams.LensMotorCom);
  846. iniHelper.WriteInteger("Dev", "LensMotorComBaud", SysParams.LensMotorComBaud);
  847. iniHelper.WriteString("Dev", "ThicknessIP", SysParams.ThicknessIP);
  848. iniHelper.WriteInteger("Dev", "ThicknessPort", SysParams.ThicknessPort);
  849. iniHelper.WriteDouble("Dev", "ThicknessSafeValue", SysParams.ThicknessSafeValue);
  850. iniHelper.WriteDouble("Dev", "Thickness_Offset", SysParams.Thickness_Offset);
  851. iniHelper.WriteString("Dev", "IODevName", SysParams.IODevName);
  852. iniHelper.WriteString("Dev", "IOCfgPath", SysParams.IOCfgPath);
  853. iniHelper.WriteString("Dev", "MotionCfgPath", SysParams.MotionCfgPath);
  854. iniHelper.WriteString("Dev", "FrontCamName", SysParams.FrontCamName);
  855. iniHelper.WriteString("Dev", "FrontCamCfgPath", SysParams.FrontCamCfgPath);
  856. iniHelper.WriteString("Dev", "BackCamName", SysParams.BackCamName);
  857. iniHelper.WriteString("Dev", "BackCamCfgPath", SysParams.BackCamCfgPath);
  858. iniHelper.WriteBool("Disable", "DisableX1", SysParams.DisableX1);
  859. iniHelper.WriteBool("Disable", "DisableX2", SysParams.DisableX2);
  860. iniHelper.WriteBool("Disable", "DisableY", SysParams.DisableY);
  861. iniHelper.WriteBool("Disable", "DisableZ", SysParams.DisableZ);
  862. iniHelper.WriteBool("Disable", "DisableFrontCam", SysParams.DisableFrontCam);
  863. iniHelper.WriteBool("Disable", "DisableBackCam", SysParams.DisableBackCam);
  864. iniHelper.WriteBool("Disable", "DisableLight", SysParams.DisableLight);
  865. iniHelper.WriteBool("Disable", "DisableThickness", SysParams.DisableThickness);
  866. iniHelper.WriteBool("Disable", "DisableTensor", SysParams.DisableTensor);
  867. iniHelper.WriteBool("Disable", "DisableLensMotor", SysParams.DisableLensMotor);
  868. iniHelper.WriteString("Sys", "ImageProcessPath", SysParams.ImageProcessPath);
  869. iniHelper.WriteString("Sys", "ImageProcessDataPath", SysParams.ImageProcessDataPath);
  870. iniHelper.WriteString("Sys", "AIModelPath", SysParams.AIModelPath);
  871. iniHelper.WriteString("Sys", "ProductPath", SysParams.ProductPath);
  872. iniHelper.WriteString("Sys", "HttpServerIP", SysParams.HttpServerIP);
  873. iniHelper.WriteInteger("Sys", "HttpServerPort", SysParams.HttpServerPort);
  874. iniHelper.WriteBool("ShowMainWin", "ShowResetBtn", SysParams.ShowResetBtn);
  875. iniHelper.WriteBool("ShowMainWin", "ShowBuzz", SysParams.ShowBuzz);
  876. iniHelper.WriteBool("ShowMainWin", "ShowDoorAlm", SysParams.ShowDoorAlm);
  877. iniHelper.WriteBool("ShowMainWin", "ShowDistribution", SysParams.ShowDistribution);
  878. iniHelper.WriteBool("ShowMainWin", "ShowSizeBtn", SysParams.ShowSizeBtn);
  879. iniHelper.WriteBool("ShowMainWin", "ShowDefectBtn", SysParams.ShowDefectBtn);
  880. iniHelper.WriteDouble("CamView", "DefectCamViewX", SysParams.DefectCamViewX);
  881. iniHelper.WriteDouble("CamView", "DefectCamViewY", SysParams.DefectCamViewY);
  882. iniHelper.WriteBool("CloudAndMES", "EnableHttp", SysParams.EnableHttp);
  883. iniHelper.WriteString("CloudAndMES", "HttpUrl", SysParams.HttpUrl);
  884. iniHelper.WriteString("CloudAndMES", "HttpTempPath", SysParams.HttpTempPath);
  885. iniHelper.WriteString("CloudAndMES", "HttpReturnKey", SysParams.HttpReturnKey);
  886. iniHelper.WriteString("CloudAndMES", "HttpReturnValue", SysParams.HttpReturnValue);
  887. iniHelper.WriteBool("CloudAndMES", "OpenCloud", SysParams.OpenCloud);
  888. iniHelper.WriteString("CloudAndMES", "CloudThisName", SysParams.CloudThisName);
  889. iniHelper.WriteString("CloudAndMES", "CloudServerIP", SysParams.CloudServerIP);
  890. iniHelper.WriteInteger("CloudAndMES", "CloudServerPort", SysParams.CloudServerPort);
  891. iniHelper.WriteString("CloudAndMES", "CloudUser", SysParams.CloudUser);
  892. iniHelper.WriteString("CloudAndMES", "CloudPassword", SysParams.CloudPassword);
  893. iniHelper.WriteBool("CloudAndMES", "OpenPdtServer", SysParams.OpenPdtServer);
  894. iniHelper.WriteString("CloudAndMES", "PdtServerIP", SysParams.PdtServerIP);
  895. iniHelper.WriteInteger("CloudAndMES", "PdtServerPort", SysParams.PdtServerPort);
  896. iniHelper.WriteBool("CloudAndMES", "IsPdtServer", SysParams.IsPdtServer);
  897. iniHelper.WriteDouble("LensZ", "Z_0_58X", SysParams.LensAxisZPos.Z_0_58X);
  898. //iniHelper.WriteDouble("LensZ", "Z_0_6X", SysParams.LensAxisZPos.Z_0_6X);
  899. iniHelper.WriteDouble("LensZ", "Z_1_0X", SysParams.LensAxisZPos.Z_1_0X);
  900. iniHelper.WriteDouble("LensZ", "Z_1_5X", SysParams.LensAxisZPos.Z_1_5X);
  901. iniHelper.WriteDouble("LensZ", "Z_2_0X", SysParams.LensAxisZPos.Z_2_0X);
  902. iniHelper.WriteDouble("LensZ", "Z_2_5X", SysParams.LensAxisZPos.Z_2_5X);
  903. iniHelper.WriteDouble("LensZ", "Z_3_0X", SysParams.LensAxisZPos.Z_3_0X);
  904. iniHelper.WriteDouble("LensZ", "Z_3_5X", SysParams.LensAxisZPos.Z_3_5X);
  905. iniHelper.WriteDouble("LensZ", "Z_4_0X", SysParams.LensAxisZPos.Z_4_0X);
  906. iniHelper.WriteDouble("LensZ", "Z_4_5X", SysParams.LensAxisZPos.Z_4_5X);
  907. iniHelper.WriteDouble("LensZ", "Z_5_0X", SysParams.LensAxisZPos.Z_5_0X);
  908. iniHelper.WriteDouble("LensZ", "Z_5_5X", SysParams.LensAxisZPos.Z_5_5X);
  909. iniHelper.WriteDouble("LensZ", "Z_6_0X", SysParams.LensAxisZPos.Z_6_0X);
  910. iniHelper.WriteDouble("LensZ", "Z_6_5X", SysParams.LensAxisZPos.Z_6_5X);
  911. iniHelper.WriteDouble("LensZ", "Z_7_0X", SysParams.LensAxisZPos.Z_7_0X);
  912. iniHelper.WriteDouble("LensZ", "Z_7_5X", SysParams.LensAxisZPos.Z_7_5X);
  913. iniHelper.WriteBool("LabelPrint", "EnableLabelPrint", SysParams.EnableLabelPrint);
  914. iniHelper.WriteString("LabelPrint", "LabelPrinterName", SysParams.LabelPrinterName);
  915. iniHelper.WriteString("LabelPrint", "LabelTempPath", SysParams.LabelTempPath);
  916. iniHelper.WriteString("LabelPrint", "LabelData", JsonConvert.SerializeObject(SysParams.LabelData));
  917. iniHelper.WriteBool("ExcelPrint", "EnableExcelPrint", SysParams.EnableExcelPrint);
  918. iniHelper.WriteString("ExcelPrint", "ExcelPrinterName", SysParams.ExcelPrinterName);
  919. iniHelper.WriteString("ExcelPrint", "ExcelTempPath", SysParams.ExcelTempPath);
  920. iniHelper.WriteString("ExcelPrint", "ExcelData", JsonConvert.SerializeObject(SysParams.ExcelData));
  921. iniHelper.WriteDouble("Offset", "Pt_offset", SysParams.Pt_offset);
  922. iniHelper.WriteDouble("Offset", "Line_offset", SysParams.Line_offset);
  923. iniHelper.WriteDouble("Offset", "X_per", SysParams.X_per);
  924. iniHelper.WriteDouble("Offset", "Y_per", SysParams.Y_per);
  925. iniHelper.WriteInteger("DefectSnap", "LightCH", SysParams.LightCH);
  926. iniHelper.WriteInteger("DefectSnap", "LightLut", SysParams.LightLut);
  927. iniHelper.WriteInteger("DefectSnap", "CamExposureTime", SysParams.CamExposureTime);
  928. iniHelper.WriteInteger("SysOther", "LightChannelCnt", SysParams.LightChannelCnt);
  929. iniHelper.WriteString("SysOther", "CustomerName", SysParams.CustomerName);
  930. iniHelper.WriteDouble("SysOther", "DefectCamPixel", SysParams.DefectCamPixel);
  931. iniHelper.WriteDouble("SysOther", "DefectAutoX", SysParams.DefectAutoX);
  932. iniHelper.WriteDouble("SysOther", "DefectAutoY", SysParams.DefectAutoY);
  933. SysConfigParams = SysParams;
  934. }
  935. /// <summary>
  936. /// 读取ini
  937. /// </summary>
  938. /// <returns></returns>
  939. public SysConfigParams ReadSysConfParams()
  940. {
  941. //return XmlHelper.Deserialize<SysConfParams>(_configFile);
  942. SysConfigParams sysParams = new SysConfigParams();
  943. IniHelper iniHelper = new IniHelper(_configFile);
  944. string sValue = "";
  945. int iValue = 0;
  946. double dValue = 0;
  947. bool bValue = false;
  948. iniHelper.ReadString("ImagesPath", "AllImages_SavePath", out sValue);
  949. sysParams.AllImages_SavePath = sValue;
  950. iniHelper.ReadString("DefectSrcSmallImag", "Defect_SrcSmall_SavePath", out sValue);
  951. sysParams.Defect_SrcSmall_SavePath = sValue;
  952. iniHelper.ReadDouble("DefectSrcSmallImag", "Defect_SrcSmall_Thres", out dValue);
  953. sysParams.Defect_SrcSmall_Thres = dValue;
  954. iniHelper.ReadBool("SaveAllImg", "SaveAllImg", out bValue);
  955. sysParams.SaveAllImg = bValue;
  956. iniHelper.ReadString("DefectBigImag", "SavePath", out sValue);
  957. sysParams.DefectBigImag.SavePath = sValue.Replace("\0", "");
  958. iniHelper.ReadBool("DefectBigImag", "AutoSave", out bValue);
  959. sysParams.DefectBigImag.AutoSave = bValue;
  960. iniHelper.ReadBool("DefectBigImag", "AutoDelete", out bValue);
  961. sysParams.DefectBigImag.AutoDelete = bValue;
  962. iniHelper.ReadDouble("DefectBigImag", "AutoDeleteDays", out dValue);
  963. sysParams.DefectBigImag.AutoDeleteDays = dValue;
  964. iniHelper.ReadString("DefectSrcSmallImag", "SavePath", out sValue);
  965. sysParams.DefectSrcSmallImag.SavePath = sValue.Replace("\0", "");
  966. iniHelper.ReadBool("DefectSrcSmallImag", "AutoSave", out bValue);
  967. sysParams.DefectSrcSmallImag.AutoSave = bValue;
  968. iniHelper.ReadBool("DefectSrcSmallImag", "AutoDelete", out bValue);
  969. sysParams.DefectSrcSmallImag.AutoDelete = bValue;
  970. iniHelper.ReadDouble("DefectSrcSmallImag", "AutoDeleteDays", out dValue);
  971. sysParams.DefectSrcSmallImag.AutoDeleteDays = dValue;
  972. iniHelper.ReadString("DefectSmallImag", "SavePath", out sValue);
  973. sysParams.DefectSmallImag.SavePath = sValue.Replace("\0", "");
  974. iniHelper.ReadBool("DefectSmallImag", "AutoSave", out bValue);
  975. sysParams.DefectSmallImag.AutoSave = bValue;
  976. iniHelper.ReadBool("DefectSmallImag", "AutoDelete", out bValue);
  977. sysParams.DefectSmallImag.AutoDelete = bValue;
  978. iniHelper.ReadDouble("DefectSmallImag", "AutoDeleteDays", out dValue);
  979. sysParams.DefectSmallImag.AutoDeleteDays = dValue;
  980. iniHelper.ReadString("DefectRepairImag", "SavePath", out sValue);
  981. sysParams.DefectRepairImag.SavePath = sValue.Replace("\0", "");
  982. iniHelper.ReadBool("DefectRepairImag", "AutoSave", out bValue);
  983. sysParams.DefectRepairImag.AutoSave = bValue;
  984. iniHelper.ReadBool("DefectRepairImag", "AutoDelete", out bValue);
  985. sysParams.DefectRepairImag.AutoDelete = bValue;
  986. iniHelper.ReadDouble("DefectRepairImag", "AutoDeleteDays", out dValue);
  987. sysParams.DefectRepairImag.AutoDeleteDays = dValue;
  988. iniHelper.ReadString("SizeBigImag", "SavePath", out sValue);
  989. sysParams.SizeBigImag.SavePath = sValue.Replace("\0", "");
  990. iniHelper.ReadBool("SizeBigImag", "AutoSave", out bValue);
  991. sysParams.SizeBigImag.AutoSave = bValue;
  992. iniHelper.ReadBool("SizeBigImag", "AutoDelete", out bValue);
  993. sysParams.SizeBigImag.AutoDelete = bValue;
  994. iniHelper.ReadDouble("SizeBigImag", "AutoDeleteDays", out dValue);
  995. sysParams.SizeBigImag.AutoDeleteDays = dValue;
  996. iniHelper.ReadString("SizeNGImag", "SavePath", out sValue);
  997. sysParams.SizeNGImag.SavePath = sValue.Replace("\0", "");
  998. iniHelper.ReadBool("SizeNGImag", "AutoSave", out bValue);
  999. sysParams.SizeNGImag.AutoSave = bValue;
  1000. iniHelper.ReadBool("SizeNGImag", "AutoDelete", out bValue);
  1001. sysParams.SizeNGImag.AutoDelete = bValue;
  1002. iniHelper.ReadDouble("SizeNGImag", "AutoDeleteDays", out dValue);
  1003. sysParams.SizeNGImag.AutoDeleteDays = dValue;
  1004. iniHelper.ReadString("SizeRepairImag", "SavePath", out sValue);
  1005. sysParams.SizeRepairImag.SavePath = sValue.Replace("\0", "");
  1006. iniHelper.ReadBool("SizeRepairImag", "AutoSave", out bValue);
  1007. sysParams.SizeRepairImag.AutoSave = bValue;
  1008. iniHelper.ReadBool("SizeRepairImag", "AutoDelete", out bValue);
  1009. sysParams.SizeRepairImag.AutoDelete = bValue;
  1010. iniHelper.ReadDouble("SizeRepairImag", "AutoDeleteDays", out dValue);
  1011. sysParams.SizeRepairImag.AutoDeleteDays = dValue;
  1012. iniHelper.ReadString("Log", "SavePath", out sValue);
  1013. sysParams.LogPath = sValue.Replace("\0", "");
  1014. iniHelper.ReadBool("Log", "AutoDelete", out bValue);
  1015. sysParams.AutoDeleteLog = bValue;
  1016. iniHelper.ReadDouble("Log", "AutoDeleteDays", out dValue);
  1017. sysParams.AutoDeleteLogData = dValue;
  1018. iniHelper.ReadBool("SysFunction", "OpenMarkErrorStop", out bValue);
  1019. sysParams.OpenMarkErrorStop = bValue;
  1020. iniHelper.ReadBool("SysFunction", "OpenBuzzer", out bValue);
  1021. sysParams.OpenBuzzer = bValue;
  1022. iniHelper.ReadBool("SysFunction", "OpenDoor", out bValue);
  1023. sysParams.OpenDoor = bValue;
  1024. iniHelper.ReadBool("SysFunction", "OpenHttpLog", out bValue);
  1025. sysParams.OpenHttpLog = bValue;
  1026. iniHelper.ReadBool("SysFunction", "OpenAutoGoHome", out bValue);
  1027. sysParams.OpenAutoGoHome = bValue;
  1028. iniHelper.ReadBool("SysFunction", "OpenFlawDistribution", out bValue);
  1029. sysParams.OpenFlawDistribution = bValue;
  1030. iniHelper.ReadBool("SysFunction", "OpenAxisXCalibration", out bValue);
  1031. sysParams.OpenAxisXCalibration = bValue;
  1032. iniHelper.ReadBool("SysFunction", "OpenPdtIsHave", out bValue);
  1033. sysParams.OpenPdtIsHave = bValue;
  1034. iniHelper.ReadBool("SysFunction", "OpenDefectSanp", out bValue);
  1035. sysParams.OpenDefectSanp = bValue;
  1036. iniHelper.ReadBool("SysFunction", "OpenAsideDefect", out bValue);
  1037. sysParams.OpenAsideDefect = bValue;
  1038. iniHelper.ReadBool("SysFunction", "OpenOredrCheck", out bValue);
  1039. sysParams.OpenOredrCheck = bValue;
  1040. iniHelper.ReadBool("SysFunction", "OpenOredrCntCheck", out bValue);
  1041. sysParams.OpenOredrCntCheck = bValue;
  1042. iniHelper.ReadBool("SysFunction", "OpenShowDB", out bValue);
  1043. sysParams.OpenShowDB = bValue;
  1044. iniHelper.ReadBool("SysFunction", "OpenColorB", out bValue);
  1045. sysParams.OpenColorB = bValue;
  1046. iniHelper.ReadBool("SysFunction", "OpenRemoveDuplicates", out bValue);
  1047. sysParams.OpenRemoveDuplicates = bValue;
  1048. iniHelper.ReadString("Dev", "LightCom", out sValue);
  1049. sysParams.LightCom = sValue.Replace("\0", "");
  1050. iniHelper.ReadInteger("Dev", "LightComBaud", out iValue);
  1051. sysParams.LightComBaud = iValue;
  1052. iniHelper.ReadString("Dev", "TensionCom", out sValue);
  1053. sysParams.TensionCom = sValue.Replace("\0", "");
  1054. iniHelper.ReadInteger("Dev", "TensionComBaud", out iValue);
  1055. sysParams.TensionComBaud = iValue;
  1056. iniHelper.ReadDouble("Dev", "Tension_Offset", out dValue);
  1057. sysParams.Tension_Offset = dValue;
  1058. iniHelper.ReadString("Dev", "LensMotorCom", out sValue);
  1059. sysParams.LensMotorCom = sValue.Replace("\0", "");
  1060. iniHelper.ReadInteger("Dev", "LensMotorComBaud", out iValue);
  1061. sysParams.LensMotorComBaud = iValue;
  1062. iniHelper.ReadString("Dev", "ThicknessIP", out sValue);
  1063. sysParams.ThicknessIP = sValue.Replace("\0", "");
  1064. iniHelper.ReadInteger("Dev", "ThicknessPort", out iValue);
  1065. sysParams.ThicknessPort = iValue;
  1066. iniHelper.ReadDouble("Dev", "ThicknessSafeValue", out dValue);
  1067. sysParams.ThicknessSafeValue = dValue;
  1068. iniHelper.ReadDouble("Dev", "Thickness_Offset", out dValue);
  1069. sysParams.Thickness_Offset = dValue;
  1070. iniHelper.ReadString("Dev", "IODevName", out sValue);
  1071. sysParams.IODevName = sValue.Replace("\0", "");
  1072. iniHelper.ReadString("Dev", "IOCfgPath", out sValue);
  1073. sysParams.IOCfgPath = sValue.Replace("\0", "");
  1074. iniHelper.ReadString("Dev", "FrontCamName", out sValue);
  1075. sysParams.FrontCamName = sValue.Replace("\0", "");
  1076. iniHelper.ReadString("Dev", "FrontCamCfgPath", out sValue);
  1077. sysParams.FrontCamCfgPath = sValue.Replace("\0", "");
  1078. iniHelper.ReadString("Dev", "BackCamName", out sValue);
  1079. sysParams.BackCamName = sValue.Replace("\0", "");
  1080. iniHelper.ReadString("Dev", "BackCamCfgPath", out sValue);
  1081. sysParams.BackCamCfgPath = sValue.Replace("\0", "");
  1082. iniHelper.ReadString("Dev", "MotionCfgPath", out sValue);
  1083. sysParams.MotionCfgPath = sValue.Replace("\0", "");
  1084. iniHelper.ReadBool("Disable", "DisableX1", out bValue);
  1085. sysParams.DisableX1 = bValue;
  1086. iniHelper.ReadBool("Disable", "DisableX2", out bValue);
  1087. sysParams.DisableX2 = bValue;
  1088. iniHelper.ReadBool("Disable", "DisableY", out bValue);
  1089. sysParams.DisableY = bValue;
  1090. iniHelper.ReadBool("Disable", "DisableZ", out bValue);
  1091. sysParams.DisableZ = bValue;
  1092. iniHelper.ReadBool("Disable", "DisableFrontCam", out bValue);
  1093. sysParams.DisableFrontCam = bValue;
  1094. iniHelper.ReadBool("Disable", "DisableBackCam", out bValue);
  1095. sysParams.DisableBackCam = bValue;
  1096. iniHelper.ReadBool("Disable", "DisableLight", out bValue);
  1097. sysParams.DisableLight = bValue;
  1098. iniHelper.ReadBool("Disable", "DisableTensor", out bValue);
  1099. sysParams.DisableTensor = bValue;
  1100. iniHelper.ReadBool("Disable", "DisableThickness", out bValue);
  1101. sysParams.DisableThickness = bValue;
  1102. iniHelper.ReadBool("Disable", "DisableLensMotor", out bValue);
  1103. sysParams.DisableLensMotor = bValue;
  1104. iniHelper.ReadString("Sys", "ImageProcessPath", out sValue);
  1105. sysParams.ImageProcessPath = sValue.Replace("\0", "");
  1106. iniHelper.ReadString("Sys", "ImageProcessDataPath", out sValue);
  1107. sysParams.ImageProcessDataPath = sValue.Replace("\0", "");
  1108. iniHelper.ReadString("Sys", "AIModelPath", out sValue);
  1109. sysParams.AIModelPath = sValue.Replace("\0", "");
  1110. iniHelper.ReadString("Sys", "ProductPath", out sValue);
  1111. sysParams.ProductPath = sValue.Replace("\0", "");
  1112. iniHelper.ReadString("Sys", "HttpServerIP", out sValue);
  1113. sysParams.HttpServerIP = sValue.Replace("\0", "");
  1114. iniHelper.ReadInteger("Sys", "HttpServerPort", out iValue);
  1115. sysParams.HttpServerPort = iValue;
  1116. iniHelper.ReadBool("ShowMainWin", "ShowResetBtn", out bValue);
  1117. sysParams.ShowResetBtn = bValue;
  1118. iniHelper.ReadBool("ShowMainWin", "ShowBuzz", out bValue);
  1119. sysParams.ShowBuzz = bValue;
  1120. iniHelper.ReadBool("ShowMainWin", "ShowDoorAlm", out bValue);
  1121. sysParams.ShowDoorAlm = bValue;
  1122. iniHelper.ReadBool("ShowMainWin", "ShowDistribution", out bValue);
  1123. sysParams.ShowDistribution = bValue;
  1124. iniHelper.ReadBool("ShowMainWin", "ShowSizeBtn", out bValue);
  1125. sysParams.ShowSizeBtn = bValue;
  1126. iniHelper.ReadBool("ShowMainWin", "ShowDefectBtn", out bValue);
  1127. sysParams.ShowDefectBtn = bValue;
  1128. iniHelper.ReadDouble("CamView", "DefectCamViewX", out dValue);
  1129. sysParams.DefectCamViewX = dValue;
  1130. iniHelper.ReadDouble("CamView", "DefectCamViewY", out dValue);
  1131. sysParams.DefectCamViewY = dValue;
  1132. iniHelper.ReadBool("CloudAndMES", "EnableHttp", out bValue);
  1133. sysParams.EnableHttp = bValue;
  1134. iniHelper.ReadString("CloudAndMES", "HttpUrl", out sValue);
  1135. sysParams.HttpUrl = sValue;
  1136. iniHelper.ReadString("CloudAndMES", "HttpTempPath", out sValue);
  1137. sysParams.HttpTempPath = sValue;
  1138. iniHelper.ReadString("CloudAndMES", "HttpReturnKey", out sValue);
  1139. sysParams.HttpReturnKey = sValue;
  1140. iniHelper.ReadString("CloudAndMES", "HttpReturnValue", out sValue);
  1141. sysParams.HttpReturnValue = sValue;
  1142. iniHelper.ReadBool("CloudAndMES", "OpenCloud", out bValue);
  1143. sysParams.OpenCloud = bValue;
  1144. iniHelper.ReadString("CloudAndMES", "CloudThisName", out sValue);
  1145. sysParams.CloudThisName = sValue.Replace("\0", string.Empty);
  1146. iniHelper.ReadString("CloudAndMES", "CloudServerIP", out sValue);
  1147. sysParams.CloudServerIP = sValue;
  1148. iniHelper.ReadInteger("CloudAndMES", "CloudServerPort", out iValue);
  1149. sysParams.CloudServerPort = iValue;
  1150. iniHelper.ReadString("CloudAndMES", "CloudUser", out sValue);
  1151. sysParams.CloudUser = sValue;
  1152. iniHelper.ReadString("CloudAndMES", "CloudPassword", out sValue);
  1153. sysParams.CloudPassword = sValue;
  1154. iniHelper.ReadBool("CloudAndMES", "OpenPdtServer", out bValue);
  1155. sysParams.OpenPdtServer = bValue;
  1156. iniHelper.ReadString("CloudAndMES", "PdtServerIP", out sValue);
  1157. sysParams.PdtServerIP = sValue;
  1158. iniHelper.ReadInteger("CloudAndMES", "PdtServerPort", out iValue);
  1159. sysParams.PdtServerPort = iValue;
  1160. iniHelper.ReadBool("CloudAndMES", "IsPdtServer", out bValue);
  1161. sysParams.IsPdtServer = bValue;
  1162. iniHelper.ReadDouble("LensZ", "Z_0_58X", out dValue);
  1163. sysParams.LensAxisZPos.Z_0_58X = dValue;
  1164. //iniHelper.ReadDouble("LensZ", "Z_0_6X", out dValue);
  1165. //sysParams.LensAxisZPos.Z_0_6X = dValue;
  1166. iniHelper.ReadDouble("LensZ", "Z_1_0X", out dValue);
  1167. sysParams.LensAxisZPos.Z_1_0X = dValue;
  1168. iniHelper.ReadDouble("LensZ", "Z_1_5X", out dValue);
  1169. sysParams.LensAxisZPos.Z_1_5X = dValue;
  1170. iniHelper.ReadDouble("LensZ", "Z_2_0X", out dValue);
  1171. sysParams.LensAxisZPos.Z_2_0X = dValue;
  1172. iniHelper.ReadDouble("LensZ", "Z_2_5X", out dValue);
  1173. sysParams.LensAxisZPos.Z_2_5X = dValue;
  1174. iniHelper.ReadDouble("LensZ", "Z_3_0X", out dValue);
  1175. sysParams.LensAxisZPos.Z_3_0X = dValue;
  1176. iniHelper.ReadDouble("LensZ", "Z_3_5X", out dValue);
  1177. sysParams.LensAxisZPos.Z_3_5X = dValue;
  1178. iniHelper.ReadDouble("LensZ", "Z_4_0X", out dValue);
  1179. sysParams.LensAxisZPos.Z_4_0X = dValue;
  1180. iniHelper.ReadDouble("LensZ", "Z_4_5X", out dValue);
  1181. sysParams.LensAxisZPos.Z_4_5X = dValue;
  1182. iniHelper.ReadDouble("LensZ", "Z_5_0X", out dValue);
  1183. sysParams.LensAxisZPos.Z_5_0X = dValue;
  1184. iniHelper.ReadDouble("LensZ", "Z_5_5X", out dValue);
  1185. sysParams.LensAxisZPos.Z_5_5X = dValue;
  1186. iniHelper.ReadDouble("LensZ", "Z_6_0X", out dValue);
  1187. sysParams.LensAxisZPos.Z_6_0X = dValue;
  1188. iniHelper.ReadDouble("LensZ", "Z_6_5X", out dValue);
  1189. sysParams.LensAxisZPos.Z_6_5X = dValue;
  1190. iniHelper.ReadDouble("LensZ", "Z_7_0X", out dValue);
  1191. sysParams.LensAxisZPos.Z_7_0X = dValue;
  1192. iniHelper.ReadDouble("LensZ", "Z_7_5X", out dValue);
  1193. sysParams.LensAxisZPos.Z_7_5X = dValue;
  1194. iniHelper.ReadBool("LabelPrint", "EnableLabelPrint", out bValue);
  1195. sysParams.EnableLabelPrint = bValue;
  1196. iniHelper.ReadString("LabelPrint", "LabelPrinterName", out sValue);
  1197. sysParams.LabelPrinterName = sValue;
  1198. iniHelper.ReadString("LabelPrint", "LabelTempPath", out sValue);
  1199. sysParams.LabelTempPath = sValue;
  1200. iniHelper.ReadString("LabelPrint", "LabelData", out sValue);
  1201. if (string.IsNullOrEmpty(sValue))
  1202. sysParams.LabelData = new Dictionary<string, string>();
  1203. else
  1204. sysParams.LabelData = JsonConvert.DeserializeObject<Dictionary<string, string>>(sValue);
  1205. iniHelper.ReadBool("ExcelPrint", "EnableExcelPrint", out bValue);
  1206. sysParams.EnableExcelPrint = bValue;
  1207. iniHelper.ReadString("ExcelPrint", "ExcelPrinterName", out sValue);
  1208. sysParams.ExcelPrinterName = sValue;
  1209. iniHelper.ReadString("ExcelPrint", "ExcelTempPath", out sValue);
  1210. sysParams.ExcelTempPath = sValue;
  1211. iniHelper.ReadString("ExcelPrint", "ExcelData", out sValue);
  1212. if (string.IsNullOrEmpty(sValue))
  1213. sysParams.ExcelData = new Dictionary<string, string>();
  1214. else
  1215. sysParams.ExcelData = JsonConvert.DeserializeObject<Dictionary<string, string>>(sValue);
  1216. iniHelper.ReadDouble("Offset", "Pt_offset", out dValue);
  1217. sysParams.Pt_offset = dValue;
  1218. iniHelper.ReadDouble("Offset", "Line_offset", out dValue);
  1219. sysParams.Line_offset = dValue;
  1220. iniHelper.ReadDouble("Offset", "X_per", out dValue);
  1221. if (dValue > 1)
  1222. sysParams.X_per = 0.9;
  1223. else if (dValue <= 0)
  1224. sysParams.X_per = 0.1;
  1225. else
  1226. sysParams.X_per = dValue;
  1227. iniHelper.ReadDouble("Offset", "Y_per", out dValue);
  1228. if (dValue > 1)
  1229. sysParams.Y_per = 0.9;
  1230. else if (dValue <= 0)
  1231. sysParams.Y_per = 0.1;
  1232. else
  1233. sysParams.Y_per = dValue;
  1234. iniHelper.ReadInteger("DefectSnap", "LightCH", out iValue);
  1235. sysParams.LightCH = iValue;
  1236. iniHelper.ReadInteger("DefectSnap", "LightLut", out iValue);
  1237. sysParams.LightLut = iValue;
  1238. iniHelper.ReadInteger("DefectSnap", "CamExposureTime", out iValue);
  1239. sysParams.CamExposureTime = iValue;
  1240. iniHelper.ReadInteger("SysOther", "LightChannelCnt", out iValue);
  1241. sysParams.LightChannelCnt = iValue;
  1242. iniHelper.ReadString("SysOther", "CustomerName", out sValue);
  1243. sysParams.CustomerName = sValue;
  1244. iniHelper.ReadDouble("SysOther", "DefectCamPixel", out dValue);
  1245. sysParams.DefectCamPixel = dValue;
  1246. if(sysParams.DefectCamPixel == 0)
  1247. sysParams.DefectCamPixel = 0.002515;
  1248. iniHelper.ReadDouble("SysOther", "DefectAutoX", out dValue);
  1249. sysParams.DefectAutoX = dValue;
  1250. iniHelper.ReadDouble("SysOther", "DefectAutoY", out dValue);
  1251. sysParams.DefectAutoY = dValue;
  1252. SysConfigParams = sysParams;
  1253. return sysParams;
  1254. }
  1255. /// <summary>
  1256. /// 写入系统默认配置
  1257. /// </summary>
  1258. public void WriteDefaultSystemConfig()
  1259. {
  1260. SysConfigParams = new SysConfigParams();
  1261. WriteSysConfParams(SysConfigParams);
  1262. }
  1263. /// <summary>
  1264. /// 加载系统配置
  1265. /// </summary>
  1266. /// <returns></returns>
  1267. public bool LoadSystemConfig()
  1268. {
  1269. bool ret = false;
  1270. if (!Directory.Exists(_rootPath))
  1271. {
  1272. Directory.CreateDirectory(_rootPath);
  1273. }
  1274. if (!Directory.Exists(_projectDir))
  1275. {
  1276. Directory.CreateDirectory(_projectDir);
  1277. }
  1278. if (File.Exists(_pointsPath))
  1279. {
  1280. ReadPointsAndTime();
  1281. }
  1282. else
  1283. {
  1284. // write default value
  1285. WritePointsAndTime(0, 0, 0, 0, 1000, 1000);
  1286. ret = true;
  1287. }
  1288. if (File.Exists(_configFile))
  1289. {
  1290. SysConfigParams = ReadSysConfParams();
  1291. if (null != SysConfigParams)
  1292. {
  1293. ret = true;
  1294. }
  1295. }
  1296. else
  1297. {
  1298. // write default value
  1299. WriteDefaultSystemConfig();
  1300. ret = true;
  1301. }
  1302. return ret;
  1303. }
  1304. #endregion
  1305. #region 文件选择
  1306. /// <summary>
  1307. /// 选择目录
  1308. /// </summary>
  1309. /// <returns></returns>
  1310. public static string SelectFolder(string defaultPath = "")
  1311. {
  1312. FolderBrowserDialog dlg = new FolderBrowserDialog();
  1313. dlg.SelectedPath = (defaultPath != "" ? defaultPath : Path.GetFullPath("."));
  1314. if (dlg.ShowDialog() == DialogResult.OK)
  1315. return dlg.SelectedPath;
  1316. return "";
  1317. }
  1318. /// <summary>
  1319. /// 选择文件
  1320. /// </summary>
  1321. /// <param name="filter">如 图像文件|*.jpg|图像文件|*.png|所有文件|*.*</param>
  1322. /// <returns></returns>
  1323. public static string SelectFile(string filter = "所有文件|*.*", string defaultPath = "")
  1324. {
  1325. OpenFileDialog fie = new OpenFileDialog();
  1326. fie.Title = "选择文件";
  1327. //fie.InitialDirectory = (defaultPath != "" ? defaultPath : Path.GetFullPath("."));
  1328. fie.Filter = filter; //设置文件类型
  1329. if (fie.ShowDialog() == DialogResult.OK)
  1330. return fie.FileName;
  1331. return "";
  1332. }
  1333. /// <summary>
  1334. /// 删除指定目录下文件
  1335. /// </summary>
  1336. /// <param name="defaultPath"></param>
  1337. /// <param name="fileExtend"></param>
  1338. /// <returns></returns>
  1339. public static bool DelFilesInFolder(string FolderPath, string fileExtend = "*")
  1340. {
  1341. if (!Directory.Exists(FolderPath))
  1342. return false;
  1343. string[] files = Directory.GetFiles(FolderPath, fileExtend, SearchOption.TopDirectoryOnly);
  1344. foreach (string file in files)
  1345. API.DeleteFile(file);
  1346. return true;
  1347. }
  1348. /// <summary>
  1349. /// 另存为
  1350. /// </summary>
  1351. /// <param name="defaultFileName">默认文件名</param>
  1352. /// <param name="filter">如 图像文件|*.jpg|图像文件|*.png|所有文件|*.*</param>
  1353. /// <returns></returns>
  1354. public static string SaveAsFile(string defaultFileName, string filter = "所有文件|*.*")
  1355. {
  1356. SaveFileDialog s = new SaveFileDialog();
  1357. s.Title = "保存文件";
  1358. s.Filter = filter; //"图像文件|*.jpg|图像文件|*.png|所有文件|*.*";
  1359. //s.DefaultExt = "图像文件|*.jpg"; //默认扩展名
  1360. //s.InitialDirectory = @"C:\Users\Administrator\Desktop"; //保存的初始目录
  1361. s.FileName = defaultFileName;//默认文件名
  1362. if (s.ShowDialog() == DialogResult.OK)
  1363. return s.FileName;
  1364. return "";
  1365. }
  1366. #endregion
  1367. #region json操作
  1368. public static void addKey(JObject obj, string key, JToken value)
  1369. {
  1370. if (obj.ContainsKey(key))
  1371. obj[key] = value;
  1372. else
  1373. obj.Add(key, value);
  1374. }
  1375. #endregion
  1376. #region enum名称
  1377. public static ArrayList GetArrayList<T>()
  1378. {
  1379. ArrayList list = new ArrayList();
  1380. Type type = typeof(T);
  1381. //list.Add(new DictionaryEntry("start", "启动按钮"));
  1382. foreach (int value in Enum.GetValues(type))
  1383. {
  1384. string strName = Enum.GetName(type, value);//获取名称
  1385. list.Add(new DictionaryEntry(value, strName));
  1386. }
  1387. return list;
  1388. }
  1389. #endregion
  1390. #region 生产数据记录
  1391. public bool SetDailyOutputAdd(out int tDailyOutput)
  1392. {
  1393. bool ret = true;
  1394. try
  1395. {
  1396. //读取数据
  1397. string tempFile = Path.Combine(_rootPath, "DailyOutput.ini");
  1398. IniHelper iniHelper = new IniHelper(tempFile);
  1399. int iValue = 0;
  1400. iniHelper.ReadInteger("TempData", "DailyOutput", out iValue);
  1401. tDailyOutput = iValue;
  1402. iniHelper.ReadInteger("TempData", "Date", out iValue);
  1403. int dateNum = iValue;
  1404. int nowDateNum = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
  1405. if (dateNum == nowDateNum)
  1406. {
  1407. //同一天,生产数量+1
  1408. tDailyOutput++;
  1409. }
  1410. else if(dateNum < nowDateNum)
  1411. {
  1412. //昨天数据,为1
  1413. tDailyOutput = 1;
  1414. }
  1415. //重新记录
  1416. iniHelper.WriteInteger("TempData", "DailyOutput", tDailyOutput);
  1417. iniHelper.WriteInteger("TempData", "Date", nowDateNum);
  1418. }
  1419. catch (Exception ex)
  1420. {
  1421. tDailyOutput = 0;
  1422. ret = false;
  1423. string tempFile = Path.Combine(_rootPath, "DailyOutput.ini");
  1424. IniHelper iniHelper = new IniHelper(tempFile);
  1425. int nowDateNum = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
  1426. //重新记录
  1427. iniHelper.WriteInteger("TempData", "DailyOutput", tDailyOutput);
  1428. iniHelper.WriteInteger("TempData", "Date", nowDateNum);
  1429. }
  1430. return ret;
  1431. }
  1432. public bool GetDailyOutput(out int tDailyOutput)
  1433. {
  1434. bool ret = true;
  1435. try
  1436. {
  1437. //读取数据
  1438. string tempFile = Path.Combine(_rootPath, "DailyOutput.ini");
  1439. IniHelper iniHelper = new IniHelper(tempFile);
  1440. int iValue = 0;
  1441. iniHelper.ReadInteger("TempData", "DailyOutput", out iValue);
  1442. tDailyOutput = iValue;
  1443. iniHelper.ReadInteger("TempData", "Date", out iValue);
  1444. int dateNum = iValue;
  1445. int nowDateNum = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
  1446. if (dateNum == nowDateNum)
  1447. {
  1448. //同一天,生产数量+1
  1449. //tDailyOutput++;
  1450. }
  1451. else if (dateNum < nowDateNum)
  1452. {
  1453. //昨天数据,为1
  1454. tDailyOutput = 0;
  1455. }
  1456. }
  1457. catch (Exception ex)
  1458. {
  1459. tDailyOutput = 0;
  1460. ret = false;
  1461. }
  1462. return ret;
  1463. }
  1464. #endregion
  1465. #region 尺寸检测项
  1466. public List<SizeItemParam> SizeItemParamsList = new List<SizeItemParam>();
  1467. public void ReadSizeDefectItems()
  1468. {
  1469. string str = File.ReadAllText(_sizeItemsPath);
  1470. SizeItemParamsList = JsonConvert.DeserializeObject<List<SizeItemParam>>(str);
  1471. }
  1472. #endregion
  1473. #region 缺陷检测项
  1474. public List<DefectItemParam> DefectItemParamsList = new List<DefectItemParam>();
  1475. public void ReadDefectItems()
  1476. {
  1477. string str = File.ReadAllText(_defectItemsPath);
  1478. DefectItemParamsList = JsonConvert.DeserializeObject<List<DefectItemParam>>(str);
  1479. }
  1480. #endregion
  1481. #region 比对检测项
  1482. public List<DefectItemParam> SizeCompItemParamsList = new List<DefectItemParam>();
  1483. public void ReadSizeCompItems()
  1484. {
  1485. if (File.Exists(_sizeCompItemsPath))
  1486. {
  1487. string str = File.ReadAllText(_sizeCompItemsPath);
  1488. SizeCompItemParamsList = JsonConvert.DeserializeObject<List<DefectItemParam>>(str);
  1489. }
  1490. else
  1491. {
  1492. SizeCompItemParamsList.Add(new DefectItemParam()
  1493. {
  1494. Code = "wtg",
  1495. Name = "未通过",
  1496. Show = 1,
  1497. Type = "0",
  1498. });
  1499. }
  1500. }
  1501. #endregion
  1502. #endregion
  1503. }
  1504. }