Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

259 lignes
12 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 AssistClient.Utils;
  10. using Newtonsoft.Json.Linq;
  11. namespace AssistClient
  12. {
  13. public class Config
  14. {
  15. public static Models.User loginUser;
  16. public static Dictionary<string, string> dicDevType = new Dictionary<string, string>();
  17. //
  18. public static string appBasePath = "";
  19. //跳过检测设备
  20. public static bool SkipAxis0, SkipAxis1, SkipAxis2,SkipAxis3;
  21. public static bool SkipLight, SkipScannerGL, SkipScannerCC, SkipSmallAxis;
  22. //DEV
  23. public static int[] Axis_PulseOutMode=new int[4];
  24. public static int[] Axis_MM2PulseNum = new int[4] { 1000, 1000, 1000, 1000};//1mm对应脉冲数
  25. public static int[] Axis_HomeMode = new int[4];
  26. public static int[] Axis_HomeDir = new int[4];//回Home方向
  27. //回HOME速度
  28. public static JArray Axis_HomeVelLow = new JArray();
  29. public static JArray Axis_HomeVelHigh = new JArray();
  30. public static JArray Axis_HomeAcc = new JArray();
  31. public static JArray Axis_HomeDec = new JArray();
  32. //回JOG速度
  33. public static JArray Axis_JogVelLow = new JArray();
  34. public static JArray Axis_JogVelHigh = new JArray();
  35. public static JArray Axis_JogAcc = new JArray();
  36. public static JArray Axis_JogDec = new JArray();
  37. public static string IOCard_DeviceNum = "PCI-1730,BID#0";
  38. public static int Light_PortNum = 1;//COM端口号
  39. public static string SmallAxis_ComName = "COM2";//COM端口号
  40. public static string Scanner_GENTL_CTI = "ScannerRuntime\\Win64_x64\\MvFGProducerCXP.cti";
  41. public static string SizeEnginePath;
  42. public static string SizeBmp_Path, Defect_SavePath;
  43. public static string SizeRepairTablePath;
  44. //尺寸配置
  45. //public static string Size_LoadPath, Size_FileName;
  46. //
  47. public static Dictionary<CMDName, JObject> CMDProcess;
  48. //DB
  49. //有些服务器防火墙有问题需要加上 min pool size=1 避免认为是恶意请求
  50. //如果用到bulkCopy需要加: AllowLoadLocalInfile=true
  51. //public static string dbMysqlCon = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456;";
  52. public static string DBConStr = "server=localhost;Database=ProductionDB;Uid=root;Pwd=123456; AllowLoadLocalInfile=true";
  53. public static string ServerIP = "";
  54. public static int ServerPort = 18082;
  55. //LOG
  56. public static string LogPath;
  57. //WEBAPI
  58. public static string baseUrl="";
  59. //==========位置 初始位 上料位 下料位(下料位不存在时使用上料位)
  60. public static JObject joPTSetting = new JObject()
  61. {
  62. { "initPT", null },
  63. { "upPT", null},
  64. { "downPT", null}
  65. };
  66. public static void LoadAllConfig()
  67. {
  68. InitDevDic();
  69. LoadSysConfig();
  70. LoadPTConfig();
  71. DeleteFiles(Config.SizeBmp_Path, -2);
  72. //
  73. string lsCmdPath = appBasePath + "\\CMDProcess\\";
  74. if(!Directory.Exists(lsCmdPath))
  75. Directory.CreateDirectory(lsCmdPath);
  76. string fileName;
  77. CMDProcess = new Dictionary<CMDName, JObject>();
  78. foreach (int item in Enum.GetValues(typeof(CMDName)))//item为key值
  79. {
  80. //string name = Enum.GetName(typeof(CMDName), item);//获取名称
  81. fileName = lsCmdPath + item + ".json";
  82. if (File.Exists(fileName))
  83. CMDProcess.Add((CMDName)item, JObject.Parse(File.ReadAllText(fileName)));
  84. //else
  85. // CMDProcess.Add((CMDName)item, null);
  86. }
  87. }
  88. public static void LoadSysConfig()
  89. {
  90. if (string.IsNullOrWhiteSpace(appBasePath))
  91. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  92. string configPath = appBasePath + "\\SysConfig.ini";
  93. string lsTmp = "";
  94. DBConStr = Util.ReadIniValue(configPath, "Server", "DBConStr");
  95. ServerIP = Util.ReadIniValue(configPath, "Server", "ServerIP");
  96. lsTmp = Util.ReadIniValue(configPath, "Server", "ServerPort");
  97. if (Util.IsNumber(lsTmp)) ServerPort = Convert.ToInt32(lsTmp);
  98. //Skip
  99. SkipAxis0 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis0") == "1";
  100. SkipAxis1 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis1") == "1";
  101. SkipAxis2 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis2") == "1";
  102. SkipAxis3 = Util.ReadIniValue(configPath, "SKIP", "SkipAxis3") == "1";
  103. SkipLight = Util.ReadIniValue(configPath, "SKIP", "SkipLight") == "1";
  104. SkipScannerGL = Util.ReadIniValue(configPath, "SKIP", "SkipScannerGL") == "1";
  105. SkipScannerCC = Util.ReadIniValue(configPath, "SKIP", "SkipScannerCC") == "1";
  106. SkipSmallAxis = Util.ReadIniValue(configPath, "SKIP", "SkipSmallAxis") == "1";
  107. //DEV
  108. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_PulseOutMode");
  109. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[0] = Convert.ToInt32(lsTmp);
  110. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_PulseOutMode");
  111. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[1] = Convert.ToInt32(lsTmp);
  112. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_PulseOutMode");
  113. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[2] = Convert.ToInt32(lsTmp);
  114. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_PulseOutMode");
  115. if (Util.IsNumber(lsTmp)) Config.Axis_PulseOutMode[3] = Convert.ToInt32(lsTmp);
  116. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_HomeMode");
  117. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[0] = Convert.ToInt32(lsTmp);
  118. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_HomeMode");
  119. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[1] = Convert.ToInt32(lsTmp);
  120. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_HomeMode");
  121. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[2] = Convert.ToInt32(lsTmp);
  122. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_HomeMode");
  123. if (Util.IsNumber(lsTmp)) Config.Axis_HomeMode[3] = Convert.ToInt32(lsTmp);
  124. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis0_HomeDir");
  125. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[0] = Convert.ToInt32(lsTmp);
  126. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis1_HomeDir");
  127. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[1] = Convert.ToInt32(lsTmp);
  128. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis2_HomeDir");
  129. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[2] = Convert.ToInt32(lsTmp);
  130. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis3_HomeDir");
  131. if (Util.IsNumber(lsTmp)) Config.Axis_HomeDir[3] = Convert.ToInt32(lsTmp);
  132. //HOME速度
  133. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeVelLow");
  134. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeVelLow = JArray.Parse(lsTmp);
  135. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeVelHigh");
  136. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeVelHigh = JArray.Parse(lsTmp);
  137. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeAcc");
  138. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeAcc = JArray.Parse(lsTmp);
  139. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_HomeDec");
  140. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_HomeDec = JArray.Parse(lsTmp);
  141. //JOG速度
  142. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogVelLow");
  143. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogVelLow = JArray.Parse(lsTmp);
  144. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogVelHigh");
  145. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogVelHigh = JArray.Parse(lsTmp);
  146. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogAcc");
  147. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogAcc = JArray.Parse(lsTmp);
  148. lsTmp = Util.ReadIniValue(configPath, "DEV", "Axis_JogDec");
  149. if (!string.IsNullOrWhiteSpace(lsTmp)) Axis_JogDec = JArray.Parse(lsTmp);
  150. //
  151. lsTmp = Util.ReadIniValue(configPath, "DEV", "Light_PortNum");
  152. if (Util.IsNumber(lsTmp)) Config.Light_PortNum = Convert.ToInt32(lsTmp);
  153. IOCard_DeviceNum = Util.ReadIniValue(configPath, "DEV", "IOCard_DeviceNum");
  154. SizeEnginePath = Util.ReadIniValue(configPath, "DEV", "SizeEnginePath");
  155. SizeBmp_Path = Util.ReadIniValue(configPath, "DEV", "SizeBmp_Path");
  156. SizeRepairTablePath = Util.ReadIniValue(configPath, "DEV", "SizeRepairTablePath");
  157. //LOG
  158. LogPath = Util.ReadIniValue(configPath, "LOG", "LogPath");
  159. }
  160. public static void LoadPTConfig()
  161. {
  162. if (string.IsNullOrWhiteSpace(appBasePath))
  163. appBasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  164. string configPath = appBasePath + "\\PTConfig.json";
  165. string lsTmp = File.ReadAllText(configPath);
  166. joPTSetting = JObject.Parse(lsTmp);
  167. }
  168. private static void InitDevDic()
  169. {
  170. //dicDevType.Add("CodeScanner", "扫码枪");//固定为必有开始
  171. if (!dicDevType.ContainsKey("IOCard")) dicDevType.Add("IOCard", "I/O控制");
  172. if (!dicDevType.ContainsKey("Axis")) dicDevType.Add("Axis", "滑台电机");
  173. if (!dicDevType.ContainsKey("Light")) dicDevType.Add("Light", "光源");
  174. if (!dicDevType.ContainsKey("Scanner_CC")) dicDevType.Add("Scanner_CC", "网口相机");
  175. if (!dicDevType.ContainsKey("Size")) dicDevType.Add("Size", "尺寸测量");
  176. if (!dicDevType.ContainsKey("For")) dicDevType.Add("For", "For循环");
  177. if (!dicDevType.ContainsKey("If")) dicDevType.Add("If", "If条件");
  178. }
  179. private static void DeleteFiles(string dirPath, int days = -7)
  180. {
  181. if (!Directory.Exists(dirPath)) return;
  182. string[] file_list = Directory.GetFiles(dirPath);
  183. var delFiles = file_list.Select(file => new FileInfo(file))
  184. .Where(f => f.CreationTime <= DateTime.Now.AddDays(days))
  185. .Select(x => x.FullName)
  186. .ToList();
  187. foreach (string file in delFiles)
  188. File.Delete(file);
  189. }
  190. public static string getDefectName(string defectCode)
  191. {
  192. defectCode= defectCode.ToLower();
  193. switch (defectCode)
  194. {
  195. case "dk":
  196. return "堵孔";
  197. case "zw":
  198. return "脏污";
  199. case "xws":
  200. return "纤维丝";
  201. case "gsyc":
  202. return "钢丝异常";
  203. case "qk":
  204. return "缺口";
  205. case "zk":
  206. return "针孔";
  207. case "pp":
  208. return "泡泡";
  209. case "hs":
  210. return "划伤";
  211. case "yx":
  212. return "压线";
  213. case "xb":
  214. return "斜边";
  215. case "sx":
  216. return "栅线";
  217. case "ds":
  218. return "断栅";
  219. case "wtg":
  220. return "未通过";
  221. case "qs":
  222. return "缺失";
  223. case "dc":
  224. return "多出";
  225. case "gsdl":
  226. return "钢丝断裂";
  227. case "gs":
  228. return "格栅";
  229. default:
  230. return "未知";
  231. }
  232. }
  233. }
  234. }