版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

348 строки
15 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using AssistClient.Utils;
  11. using Newtonsoft.Json;
  12. using Newtonsoft.Json.Linq;
  13. namespace AssistClient
  14. {
  15. public class Config
  16. {
  17. public static Models.User loginUser;
  18. public static Dictionary<string, string> dicDevType = new Dictionary<string, string>();
  19. //
  20. public static string appBasePath = "";
  21. //跳过检测设备
  22. public static bool SkipAxis0, SkipAxis1, SkipAxis2,SkipAxis3;
  23. public static bool SkipLight, SkipScannerGL, SkipScannerCC, SkipSmallAxis;
  24. //DEV
  25. public static int[] Axis_PulseOutMode=new int[4];
  26. public static int[] Axis_MM2PulseNum = new int[4] { 1000, 1000, 1000, 1000};//1mm对应脉冲数
  27. public static int[] Axis_HomeMode = new int[4];
  28. public static int[] Axis_HomeDir = new int[4];//回Home方向
  29. //回HOME速度
  30. public static JArray Axis_HomeVelLow = new JArray();
  31. public static JArray Axis_HomeVelHigh = new JArray();
  32. public static JArray Axis_HomeAcc = new JArray();
  33. public static JArray Axis_HomeDec = new JArray();
  34. //回JOG速度
  35. public static JArray Axis_JogVelLow = new JArray();
  36. public static JArray Axis_JogVelHigh = new JArray();
  37. public static JArray Axis_JogAcc = new JArray();
  38. public static JArray Axis_JogDec = new JArray();
  39. public static string IOCard_DeviceNum = "PCI-1730,BID#0";
  40. public static int Light_PortNum = 1;//COM端口号
  41. public static string SmallAxis_ComName = "COM2";//COM端口号
  42. public static string Scanner_GENTL_CTI = "ScannerRuntime\\Win64_x64\\MvFGProducerCXP.cti";
  43. public static string SizeEnginePath;
  44. public static string SizeBmp_Path, Defect_SavePath;
  45. public static string SizeRepairTablePath;
  46. //尺寸配置
  47. //public static string Size_LoadPath, Size_FileName;
  48. //
  49. public static Dictionary<CMDName, JObject> CMDProcess;
  50. //DB
  51. //有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
  52. //如果用到bulkCopy需要加: AllowLoadLocalInfile=true
  53. //public static string dbMysqlCon = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456;";
  54. public static string DBConStr = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  55. public static string ServerIP = "";
  56. public static int ServerPort = 18082;
  57. //LOG
  58. public static string LogPath;
  59. //WEBAPI
  60. public static string baseUrl="";
  61. public static ShowType FrmShowType = ShowType.All;
  62. //==========位置 初始位 上料位 下料位(下料位不存在时使用上料位)
  63. public static JObject joPTSetting = new JObject()
  64. {
  65. { "initPT", null },
  66. { "upPT", null},
  67. { "downPT", null}
  68. };
  69. public static void LoadAllConfig()
  70. {
  71. InitDevDic();
  72. ReadDefectItems();
  73. LoadSysConfig();
  74. LoadPTConfig();
  75. DeleteFiles(Config.SizeBmp_Path, -2);
  76. //
  77. string lsCmdPath = appBasePath + "\\CMDProcess\\";
  78. if(!Directory.Exists(lsCmdPath))
  79. Directory.CreateDirectory(lsCmdPath);
  80. string fileName;
  81. CMDProcess = new Dictionary<CMDName, JObject>();
  82. foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
  83. {
  84. //string name = Enum.GetName(typeof(CMDName), item);//获取名称
  85. fileName = lsCmdPath + item + ".json";
  86. if (File.Exists(fileName))
  87. CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
  88. //else
  89. // CMDProcess.Add((CMDName)item, null);
  90. }
  91. }
  92. public static void LoadSysConfig()
  93. {
  94. if (string.IsNullOrWhiteSpace(appBasePath))
  95. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  96. string configPath = appBasePath + "\\SysConfig.ini";
  97. string lsTmp = "";
  98. DBConStr = Util.ReadIniValue(configPath, "Server", "DBConStr");
  99. ServerIP = Util.ReadIniValue(configPath, "Server", "ServerIP");
  100. lsTmp = Util.ReadIniValue(configPath, "Server", "ServerPort");
  101. if (Util.IsNumber(lsTmp)) ServerPort = Convert.ToInt32(lsTmp);
  102. //Skip
  103. SkipAxis0 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis0") == "1";
  104. SkipAxis1 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis1") == "1";
  105. SkipAxis2 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis2") == "1";
  106. SkipAxis3 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis3") == "1";
  107. SkipLight = Util.ReadIniValue(configPath, "SKIP", "SkipLight") == "1";
  108. SkipScannerGL = Util.ReadIniValue(configPath, "SKIP", "SkipScannerGL") == "1";
  109. SkipScannerCC = Util.ReadIniValue(configPath, "SKIP", "SkipScannerCC") == "1";
  110. SkipSmallAxis = Util.ReadIniValue(configPath, "SKIP", "SkipSmallAxis") == "1";
  111. //DEV
  112. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_PulseOutMode");
  113. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[0] = Convert.ToInt32(lsTmp);
  114. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_PulseOutMode");
  115. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[1] = Convert.ToInt32(lsTmp);
  116. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_PulseOutMode");
  117. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[2] = Convert.ToInt32(lsTmp);
  118. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_PulseOutMode");
  119. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[3] = Convert.ToInt32(lsTmp);
  120. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_HomeMode");
  121. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[0] = Convert.ToInt32(lsTmp);
  122. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_HomeMode");
  123. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[1] = Convert.ToInt32(lsTmp);
  124. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_HomeMode");
  125. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[2] = Convert.ToInt32(lsTmp);
  126. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_HomeMode");
  127. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[3] = Convert.ToInt32(lsTmp);
  128. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_HomeDir");
  129. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[0] = Convert.ToInt32(lsTmp);
  130. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_HomeDir");
  131. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[1] = Convert.ToInt32(lsTmp);
  132. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_HomeDir");
  133. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[2] = Convert.ToInt32(lsTmp);
  134. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_HomeDir");
  135. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[3] = Convert.ToInt32(lsTmp);
  136. //HOME速度
  137. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeVelLow");
  138. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeVelLow = JArray.Parse(lsTmp);
  139. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeVelHigh");
  140. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeVelHigh = JArray.Parse(lsTmp);
  141. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeAcc");
  142. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeAcc = JArray.Parse(lsTmp);
  143. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeDec");
  144. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeDec = JArray.Parse(lsTmp);
  145. //JOG速度
  146. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogVelLow");
  147. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogVelLow = JArray.Parse(lsTmp);
  148. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogVelHigh");
  149. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogVelHigh = JArray.Parse(lsTmp);
  150. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogAcc");
  151. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogAcc = JArray.Parse(lsTmp);
  152. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogDec");
  153. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogDec = JArray.Parse(lsTmp);
  154. //
  155. lsTmp = Util.ReadIniValue(configPath, "DEV", "Light_PortNum");
  156. if (Util.IsNumber(lsTmp)) Config.Light_PortNum = Convert.ToInt32(lsTmp);
  157. IOCard_DeviceNum = Util.ReadIniValue(configPath, "DEV", "IOCard_DeviceNum");
  158. SizeEnginePath = Util.ReadIniValue(configPath, "DEV", "SizeEnginePath");
  159. SizeBmp_Path = Util.ReadIniValue(configPath, "DEV", "SizeBmp_Path");
  160. SizeRepairTablePath = Util.ReadIniValue(configPath, "DEV", "SizeRepairTablePath");
  161. //LOG
  162. LogPath = Util.ReadIniValue(configPath, "LOG", "LogPath");
  163. }
  164. public static void LoadPTConfig()
  165. {
  166. if (string.IsNullOrWhiteSpace(appBasePath))
  167. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  168. string configPath = appBasePath + "\\PTConfig.json";
  169. string lsTmp = File.ReadAllText(configPath);
  170. joPTSetting = JObject.Parse(lsTmp);
  171. }
  172. private static void InitDevDic()
  173. {
  174. //dicDevType.Add("CodeScanner", "扫码枪");//固定为必有开始
  175. if (!dicDevType.ContainsKey("IOCard")) dicDevType.Add("IOCard", "I/O控制");
  176. if (!dicDevType.ContainsKey("Axis")) dicDevType.Add("Axis", "滑台电机");
  177. if (!dicDevType.ContainsKey("Light")) dicDevType.Add("Light", "光源");
  178. if (!dicDevType.ContainsKey("Scanner_CC")) dicDevType.Add("Scanner_CC", "网口相机");
  179. if (!dicDevType.ContainsKey("Size")) dicDevType.Add("Size", "尺寸测量");
  180. if (!dicDevType.ContainsKey("For")) dicDevType.Add("For", "For循环");
  181. if (!dicDevType.ContainsKey("If")) dicDevType.Add("If", "If条件");
  182. }
  183. private static void DeleteFiles(string dirPath, int days = -7)
  184. {
  185. if (!Directory.Exists(dirPath)) return;
  186. string[] file_list = Directory.GetFiles(dirPath);
  187. var delFiles = file_list.Select(file => new FileInfo(file))
  188. .Where(f => f.CreationTime <= DateTime.Now.AddDays(days))
  189. .Select(x => x.FullName)
  190. .ToList();
  191. foreach (string file in delFiles)
  192. File.Delete(file);
  193. }
  194. public static string getDefectName(string defectCode)
  195. {
  196. //defectCode= defectCode.ToLower();
  197. var temp = DefectItemParamsList.Find(x=>x.Code ==defectCode);
  198. if(temp != null)
  199. return temp.Name;
  200. else
  201. return "未知";
  202. //禁用,现在使用文档
  203. //switch (defectCode)
  204. //{
  205. // case "dk":
  206. // return "堵孔";
  207. // case "zw":
  208. // return "脏污";
  209. // case "xws":
  210. // return "纤维丝";
  211. // case "gsyc":
  212. // return "钢丝异常";
  213. // case "qk":
  214. // return "缺口";
  215. // case "zk":
  216. // return "针孔";
  217. // case "pp":
  218. // return "泡泡";
  219. // case "hs":
  220. // return "划伤";
  221. // case "yx":
  222. // return "压线";
  223. // case "xb":
  224. // return "斜边";
  225. // case "sx":
  226. // return "栅线";
  227. // case "ds":
  228. // return "断栅";
  229. // default:
  230. // return "未知";
  231. //}
  232. }
  233. /// <summary>
  234. /// 获取缺陷类型 0:缺陷检测 10:比对 -1:未知
  235. /// </summary>
  236. /// <param name="defectCode"></param>
  237. /// <returns></returns>
  238. public static int getDefectType(string defectCode)
  239. {
  240. //defectCode= defectCode.ToLower();
  241. var temp = DefectItemParamsList.Find(x => x.Code == defectCode);
  242. if (temp != null)
  243. return temp.Index;
  244. else
  245. return -1;
  246. }
  247. #region 缺陷检测项
  248. #region 缺陷检测参数
  249. public class DefectItemParam
  250. {
  251. /// <summary>
  252. /// 名称
  253. /// </summary>
  254. public string Name { get; set; }
  255. /// <summary>
  256. /// 代码
  257. /// </summary>
  258. public string Code { get; set; }
  259. /// <summary>
  260. /// 序号
  261. /// </summary>
  262. public int Index { get; set; }
  263. /// <summary>
  264. /// 默认分值
  265. /// </summary>
  266. public double Threshold { get; set; }
  267. /// <summary>
  268. /// RGB颜色代码
  269. /// </summary>
  270. public int[] RGBcolor { get; set; }
  271. /// <summary>
  272. /// 对应类型
  273. /// </summary>
  274. public string Type { get; set; }
  275. /// <summary>
  276. /// 尺寸
  277. /// </summary>
  278. public float Size { get; set; }
  279. /// <summary>
  280. /// 最大允许缺陷数量
  281. /// </summary>
  282. public int MaxDefectCount { get; set; }
  283. /// <summary>
  284. /// 显示
  285. /// </summary>
  286. public int Show { get; set; }
  287. }
  288. #endregion
  289. public static List<DefectItemParam> DefectItemParamsList = new List<DefectItemParam>();
  290. public static void ReadDefectItems()
  291. {
  292. try
  293. {
  294. if (string.IsNullOrWhiteSpace(appBasePath))
  295. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  296. string str = File.ReadAllText(appBasePath + "\\缺陷测试项.json");
  297. DefectItemParamsList = JsonConvert.DeserializeObject<List<DefectItemParam>>(str);
  298. }
  299. catch (Exception ex)
  300. {
  301. MessageBox.Show(ex.Message, "警告");
  302. }
  303. }
  304. #endregion
  305. #region 显示分类
  306. public enum ShowType
  307. {
  308. Main,
  309. Small,
  310. All
  311. }
  312. #endregion
  313. }
  314. }