版博士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.
 
 
 
 

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