版博士V2.0程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Config.cs 14 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. //==========位置 初始位 上料位 下料位(下料位不存在时使用上料位)
  62. public static JObject joPTSetting = new JObject()
  63. {
  64. { "initPT", null },
  65. { "upPT", null},
  66. { "downPT", null}
  67. };
  68. public static void LoadAllConfig()
  69. {
  70. InitDevDic();
  71. ReadDefectItems();
  72. LoadSysConfig();
  73. LoadPTConfig();
  74. DeleteFiles(Config.SizeBmp_Path, -2);
  75. //
  76. string lsCmdPath = appBasePath + "\\CMDProcess\\";
  77. if(!Directory.Exists(lsCmdPath))
  78. Directory.CreateDirectory(lsCmdPath);
  79. string fileName;
  80. CMDProcess = new Dictionary<CMDName, JObject>();
  81. foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
  82. {
  83. //string name = Enum.GetName(typeof(CMDName), item);//获取名称
  84. fileName = lsCmdPath + item + ".json";
  85. if (File.Exists(fileName))
  86. CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
  87. //else
  88. // CMDProcess.Add((CMDName)item, null);
  89. }
  90. }
  91. public static void LoadSysConfig()
  92. {
  93. if (string.IsNullOrWhiteSpace(appBasePath))
  94. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  95. string configPath = appBasePath + "\\SysConfig.ini";
  96. string lsTmp = "";
  97. DBConStr = Util.ReadIniValue(configPath, "Server", "DBConStr");
  98. ServerIP = Util.ReadIniValue(configPath, "Server", "ServerIP");
  99. lsTmp = Util.ReadIniValue(configPath, "Server", "ServerPort");
  100. if (Util.IsNumber(lsTmp)) ServerPort = Convert.ToInt32(lsTmp);
  101. //Skip
  102. SkipAxis0 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis0") == "1";
  103. SkipAxis1 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis1") == "1";
  104. SkipAxis2 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis2") == "1";
  105. SkipAxis3 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis3") == "1";
  106. SkipLight = Util.ReadIniValue(configPath, "SKIP", "SkipLight") == "1";
  107. SkipScannerGL = Util.ReadIniValue(configPath, "SKIP", "SkipScannerGL") == "1";
  108. SkipScannerCC = Util.ReadIniValue(configPath, "SKIP", "SkipScannerCC") == "1";
  109. SkipSmallAxis = Util.ReadIniValue(configPath, "SKIP", "SkipSmallAxis") == "1";
  110. //DEV
  111. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_PulseOutMode");
  112. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[0] = Convert.ToInt32(lsTmp);
  113. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_PulseOutMode");
  114. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[1] = Convert.ToInt32(lsTmp);
  115. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_PulseOutMode");
  116. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[2] = Convert.ToInt32(lsTmp);
  117. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_PulseOutMode");
  118. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[3] = Convert.ToInt32(lsTmp);
  119. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_HomeMode");
  120. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[0] = Convert.ToInt32(lsTmp);
  121. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_HomeMode");
  122. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[1] = Convert.ToInt32(lsTmp);
  123. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_HomeMode");
  124. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[2] = Convert.ToInt32(lsTmp);
  125. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_HomeMode");
  126. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[3] = Convert.ToInt32(lsTmp);
  127. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_HomeDir");
  128. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[0] = Convert.ToInt32(lsTmp);
  129. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_HomeDir");
  130. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[1] = Convert.ToInt32(lsTmp);
  131. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_HomeDir");
  132. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[2] = Convert.ToInt32(lsTmp);
  133. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_HomeDir");
  134. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[3] = Convert.ToInt32(lsTmp);
  135. //HOME速度
  136. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeVelLow");
  137. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeVelLow = JArray.Parse(lsTmp);
  138. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeVelHigh");
  139. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeVelHigh = JArray.Parse(lsTmp);
  140. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeAcc");
  141. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeAcc = JArray.Parse(lsTmp);
  142. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeDec");
  143. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeDec = JArray.Parse(lsTmp);
  144. //JOG速度
  145. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogVelLow");
  146. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogVelLow = JArray.Parse(lsTmp);
  147. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogVelHigh");
  148. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogVelHigh = JArray.Parse(lsTmp);
  149. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogAcc");
  150. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogAcc = JArray.Parse(lsTmp);
  151. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogDec");
  152. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogDec = JArray.Parse(lsTmp);
  153. //
  154. lsTmp = Util.ReadIniValue(configPath, "DEV", "Light_PortNum");
  155. if (Util.IsNumber(lsTmp)) Config.Light_PortNum = Convert.ToInt32(lsTmp);
  156. IOCard_DeviceNum = Util.ReadIniValue(configPath, "DEV", "IOCard_DeviceNum");
  157. SizeEnginePath = Util.ReadIniValue(configPath, "DEV", "SizeEnginePath");
  158. SizeBmp_Path = Util.ReadIniValue(configPath, "DEV", "SizeBmp_Path");
  159. SizeRepairTablePath = Util.ReadIniValue(configPath, "DEV", "SizeRepairTablePath");
  160. //LOG
  161. LogPath = Util.ReadIniValue(configPath, "LOG", "LogPath");
  162. }
  163. public static void LoadPTConfig()
  164. {
  165. if (string.IsNullOrWhiteSpace(appBasePath))
  166. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  167. string configPath = appBasePath + "\\PTConfig.json";
  168. string lsTmp = File.ReadAllText(configPath);
  169. joPTSetting = JObject.Parse(lsTmp);
  170. }
  171. private static void InitDevDic()
  172. {
  173. //dicDevType.Add("CodeScanner", "扫码枪");//固定为必有开始
  174. if (!dicDevType.ContainsKey("IOCard")) dicDevType.Add("IOCard", "I/O控制");
  175. if (!dicDevType.ContainsKey("Axis")) dicDevType.Add("Axis", "滑台电机");
  176. if (!dicDevType.ContainsKey("Light")) dicDevType.Add("Light", "光源");
  177. if (!dicDevType.ContainsKey("Scanner_CC")) dicDevType.Add("Scanner_CC", "网口相机");
  178. if (!dicDevType.ContainsKey("Size")) dicDevType.Add("Size", "尺寸测量");
  179. if (!dicDevType.ContainsKey("For")) dicDevType.Add("For", "For循环");
  180. if (!dicDevType.ContainsKey("If")) dicDevType.Add("If", "If条件");
  181. }
  182. private static void DeleteFiles(string dirPath, int days = -7)
  183. {
  184. if (!Directory.Exists(dirPath)) return;
  185. string[] file_list = Directory.GetFiles(dirPath);
  186. var delFiles = file_list.Select(file => new FileInfo(file))
  187. .Where(f => f.CreationTime <= DateTime.Now.AddDays(days))
  188. .Select(x => x.FullName)
  189. .ToList();
  190. foreach (string file in delFiles)
  191. File.Delete(file);
  192. }
  193. public static string getDefectName(string defectCode)
  194. {
  195. //defectCode= defectCode.ToLower();
  196. var temp = DefectItemParamsList.Find(x=>x.Code ==defectCode);
  197. if(temp != null)
  198. return temp.Name;
  199. else
  200. return "未知";
  201. //禁用,现在使用文档
  202. //switch (defectCode)
  203. //{
  204. // case "dk":
  205. // return "堵孔";
  206. // case "zw":
  207. // return "脏污";
  208. // case "xws":
  209. // return "纤维丝";
  210. // case "gsyc":
  211. // return "钢丝异常";
  212. // case "qk":
  213. // return "缺口";
  214. // case "zk":
  215. // return "针孔";
  216. // case "pp":
  217. // return "泡泡";
  218. // case "hs":
  219. // return "划伤";
  220. // case "yx":
  221. // return "压线";
  222. // case "xb":
  223. // return "斜边";
  224. // case "sx":
  225. // return "栅线";
  226. // case "ds":
  227. // return "断栅";
  228. // default:
  229. // return "未知";
  230. //}
  231. }
  232. #region 缺陷检测项
  233. #region 缺陷检测参数
  234. public class DefectItemParam
  235. {
  236. /// <summary>
  237. /// 名称
  238. /// </summary>
  239. public string Name { get; set; }
  240. /// <summary>
  241. /// 代码
  242. /// </summary>
  243. public string Code { get; set; }
  244. /// <summary>
  245. /// 序号
  246. /// </summary>
  247. public int Index { get; set; }
  248. /// <summary>
  249. /// 默认分值
  250. /// </summary>
  251. public double Threshold { get; set; }
  252. /// <summary>
  253. /// RGB颜色代码
  254. /// </summary>
  255. public int[] RGBcolor { get; set; }
  256. /// <summary>
  257. /// 对应类型
  258. /// </summary>
  259. public string Type { get; set; }
  260. /// <summary>
  261. /// 尺寸
  262. /// </summary>
  263. public float Size { get; set; }
  264. /// <summary>
  265. /// 最大允许缺陷数量
  266. /// </summary>
  267. public int MaxDefectCount { get; set; }
  268. /// <summary>
  269. /// 显示
  270. /// </summary>
  271. public int Show { get; set; }
  272. }
  273. #endregion
  274. public static List<DefectItemParam> DefectItemParamsList = new List<DefectItemParam>();
  275. public static void ReadDefectItems()
  276. {
  277. try
  278. {
  279. if (string.IsNullOrWhiteSpace(appBasePath))
  280. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  281. string str = File.ReadAllText(appBasePath + "\\缺陷测试项.json");
  282. DefectItemParamsList = JsonConvert.DeserializeObject<List<DefectItemParam>>(str);
  283. }
  284. catch (Exception ex)
  285. {
  286. MessageBox.Show(ex.Message, "警告");
  287. }
  288. }
  289. #endregion
  290. }
  291. }