MainPageViewModel.cs 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118
  1. using HslCommunication.Core.IMessage;
  2. using LogForceTestApp.Modules.MainModule.Models;
  3. using LogoForceTestApp.Modules.MainModule.Enums;
  4. using LogoForceTestApp.Modules.MainModule.Models;
  5. using LogoForceTestApp.Modules.MainModule.Services;
  6. using LogoForceTestApp.Services;
  7. using LogoForceTestApp.Services.Interfaces;
  8. using Newtonsoft.Json;
  9. using Newtonsoft.Json.Linq;
  10. using OxyPlot;
  11. using OxyPlot.Axes;
  12. using OxyPlot.Series;
  13. using Prism.Commands;
  14. using Prism.Events;
  15. using Prism.Mvvm;
  16. using Prism.Regions;
  17. using Prism.Services.Dialogs;
  18. using PropertyChanged;
  19. using Repository;
  20. using Repository.Entiies;
  21. using Serilog;
  22. using SkiaSharp.QrCode; //生成二维码
  23. using SkiaSharp;
  24. using StatementMachineService.Core;
  25. using StatementMachineService.Events;
  26. using System;
  27. using System.Collections.Concurrent;
  28. using System.Collections.Generic;
  29. using System.Diagnostics;
  30. using System.IO;
  31. using System.Net.Http;
  32. using System.Runtime.Serialization;
  33. using System.Security.Cryptography;
  34. using System.Text;
  35. using System.Threading;
  36. using System.Threading.Tasks;
  37. using System.Timers;
  38. using System.Windows;
  39. using Team.Utility;
  40. using static AutoMapper.Internal.ExpressionFactory;
  41. using System.Collections.ObjectModel;
  42. using TouchSocket.Core;
  43. using TouchSocket.Sockets;
  44. using Result = LogoForceTestApp.Modules.MainModule.Models.Result;
  45. using System.Windows.Media;
  46. using SkiaSharp.Views.WPF;
  47. using System.Windows.Media.Imaging;
  48. using System.Windows.Media.Media3D;
  49. using System.Drawing;
  50. using ZXing.Common;
  51. using ZXing;
  52. using HandyControl.Controls;
  53. using LogoForceTestApp.Core;
  54. namespace LogoForceTestApp.Modules.MainModule.ViewModels
  55. {
  56. public class MainPageViewModel : BindableBase
  57. {
  58. int _upLoadSlowTime;
  59. private bool _start;
  60. private List<DataPoint> _points = new();
  61. private readonly ConcurrentQueue<UpLoadTraceModel> _upLoadTraceModels = new();
  62. private readonly IHttpClientFactory _httpClientFactory;
  63. private readonly IScanService _scanService;
  64. private readonly IModbusTcpSlaverService _modbusTcpSlaverService;
  65. private readonly IStateService _stateService;
  66. private readonly IRepository _repository;
  67. private readonly IWritableOptions<AppSettings> _appSttings;
  68. private readonly IEventAggregator _eventAggregator;
  69. private readonly InovanceTcp inovanceTcp;
  70. private readonly ILogger _logger;
  71. private readonly IWarningUpdateService _warningUpdateService;
  72. private readonly IDialogService _dialogService;
  73. private readonly TcpService tcpService;
  74. private readonly Dictionary<int, string> SignalMapper;
  75. private bool _firstStart = true;
  76. private ResettableTimer _resettableTimer;
  77. public List<InformationNew> InforNew { get; set; }
  78. public PlotModel PlotModel { get; private set; }
  79. public bool ScanConnected { get; set; }
  80. public Param Param { get; set; }
  81. public string NewBarcode { get; set; }
  82. public string UsingBarcode { get; set; }
  83. public string ErrorCode { get; set; }
  84. [DoNotNotify]
  85. public string CSVPath { get; set; }
  86. [DoNotNotify]
  87. public string ImagePath { get; set; }
  88. public int OkDuration { get; set; } = 6000;
  89. public OeeConfig OeeConfig { get; set; }
  90. private bool _connected;
  91. public bool Connected
  92. {
  93. get
  94. {
  95. _connected = inovanceTcp.Connection("192.168.0.10", 502);
  96. return _connected;
  97. }
  98. set { _connected = value; }
  99. }
  100. public DelegateCommand QRCommand { get; set; }
  101. public DelegateCommand HouseCommand { get; set; }
  102. public DelegateCommand OutWorkCommand { get; set; }
  103. public DelegateCommand OrderCommand { get; set; }
  104. public string SelectedOrderName { get; set; }
  105. public ObservableCollection<string> OrderNames { get; set; }
  106. public string InQR { get; set; }
  107. public string LackHouse { get; set; }
  108. public string UsedHouse { get; set; }
  109. public string TotalHouse { get; set; }
  110. public int ActPer { get; set; }
  111. public int FallPer { get; set; }
  112. public int AbsPer { get; set; }
  113. #region Operator
  114. public string Operator1 { get; set; }
  115. public string Operator2 { get; set; }
  116. public string Operator3 { get; set; }
  117. public string Operator4 { get; set; }
  118. public string Operator5 { get; set; }
  119. public string Operator6 { get; set; }
  120. public string Operator7 { get; set; }
  121. public string Operator8 { get; set; }
  122. public string Operator9 { get; set; }
  123. public string Operator10 { get; set; }
  124. public string Operator11 { get; set; }
  125. public string Operator12 { get; set; }
  126. public string Operator13 { get; set; }
  127. public string Operator14 { get; set; }
  128. public string Operator15 { get; set; }
  129. public string Operator16 { get; set; }
  130. public string Operator17 { get; set; }
  131. public string Operator18 { get; set; }
  132. #endregion
  133. #region Material
  134. public string Material1 { get; set; }
  135. public string Material2 { get; set; }
  136. public string Material3 { get; set; }
  137. public string Material4 { get; set; }
  138. public string Material5 { get; set; }
  139. public string Material6 { get; set; }
  140. public string Material7 { get; set; }
  141. public string Material8 { get; set; }
  142. public string Material9 { get; set; }
  143. public string Material10 { get; set; }
  144. public string Material11 { get; set; }
  145. public string Material12 { get; set; }
  146. public string Material13 { get; set; }
  147. public string Material14 { get; set; }
  148. public string Material15 { get; set; }
  149. public string Material16 { get; set; }
  150. public string Material17 { get; set; }
  151. public string Material18 { get; set; }
  152. #endregion
  153. int[] q = new int[30];
  154. public MainPageViewModel(IHttpClientFactory httpClientFactory, IScanService scanService,
  155. IModbusTcpSlaverService modbusTcpSlaverService, IStateService stateService, IRepository repository,
  156. IWritableOptions<AppSettings> appSttings, IEventAggregator eventAggregator, InovanceTcp inovanceTcp,
  157. ILogger logger, IWarningUpdateService warningUpdateService, IDialogService dialogService, TcpService tcpService)
  158. {
  159. _httpClientFactory = httpClientFactory;
  160. _scanService = scanService;
  161. _modbusTcpSlaverService = modbusTcpSlaverService;
  162. _stateService = stateService;
  163. _repository = repository;
  164. _appSttings = appSttings;
  165. CSVPath = _appSttings.Value.CSVPath;
  166. ImagePath = _appSttings.Value.ImageSavePath;
  167. _eventAggregator = eventAggregator;
  168. this.inovanceTcp = inovanceTcp;
  169. _eventAggregator.GetEvent<WaringUpdateLog>().Subscribe(WaringUpdateLogChanged);
  170. _logger = logger;
  171. _warningUpdateService = warningUpdateService;
  172. _dialogService = dialogService;
  173. this.tcpService = tcpService;
  174. InforNew = new List<InformationNew>();
  175. HouseCommand = new DelegateCommand(UploadHouse);
  176. OutWorkCommand = new DelegateCommand(UploadOutWork);
  177. OrderCommand = new DelegateCommand(OrderEnter);
  178. #region tcpService
  179. tcpService.Connecting = (client, e) =>
  180. {
  181. #region ip
  182. /*
  183. e.Id = $"{client.IP}:{client.Port}";
  184. if (client.IP == "192.168.10.1")//1号机
  185. {
  186. e.Id = "Num1";
  187. }
  188. if (client.IP == "192.168.10.2")//2号机
  189. {
  190. e.Id = "Num2";
  191. }
  192. if (client.IP == "192.168.10.3")//3号机
  193. {
  194. e.Id = "Num3";
  195. }
  196. if (client.IP == "192.168.10.4")//4号机
  197. {
  198. e.Id = "Num4";
  199. }
  200. if (client.IP == "192.168.10.5")//5号机
  201. {
  202. e.Id = "Num5";
  203. }
  204. if (client.IP == "192.168.10.6")//6号机
  205. {
  206. e.Id = "Num6";
  207. }
  208. if (client.IP == "192.168.10.7")//7号机
  209. {
  210. e.Id = "Num7";
  211. }
  212. if (client.IP == "192.168.10.8")//8号机
  213. {
  214. e.Id = "Num8";
  215. }
  216. if (client.IP == "192.168.10.9")//9号机
  217. {
  218. e.Id = "Num9";
  219. }
  220. if (client.IP == "192.168.10.10")//10号机
  221. {
  222. e.Id = "Num10";
  223. }
  224. if (client.IP == "192.168.10.11")//11号机
  225. {
  226. e.Id = "Num11";
  227. }
  228. if (client.IP == "192.168.10.12")//12号机
  229. {
  230. e.Id = "Num12";
  231. }
  232. if (client.IP == "192.168.10.13")//13号机
  233. {
  234. e.Id = "Num13";
  235. }
  236. if (client.IP == "192.168.10.14")//14号机
  237. {
  238. e.Id = "Num14";
  239. }
  240. if (client.IP == "192.168.10.15")//检测机1
  241. {
  242. e.Id = "Test1";
  243. }
  244. if (client.IP == "192.168.10.16")//检测机2
  245. {
  246. e.Id = "Test2";
  247. }
  248. if (client.IP == "192.168.10.17")//检测机3
  249. {
  250. e.Id = "Test3";
  251. }
  252. if (client.IP == "192.168.10.18")//检测机4
  253. {
  254. e.Id = "Test4";
  255. }*/
  256. #endregion
  257. return EasyTask.CompletedTask;
  258. };//有客户端正在连接
  259. tcpService.Connected = (client, e) =>
  260. {
  261. WriteLog("有客户端成功连接");
  262. return EasyTask.CompletedTask;
  263. };//有客户端成功连接
  264. tcpService.Disconnecting = (client, e) =>
  265. {
  266. return EasyTask.CompletedTask;
  267. };//有客户端正在断开连接,只有当主动断开时才有效。
  268. tcpService.Disconnected = (client, e) =>
  269. {
  270. WriteLog("有客户端断开连接");
  271. return EasyTask.CompletedTask;
  272. };//有客户端断开连接
  273. tcpService.Received = (client, e) =>
  274. {
  275. //从客户端收到信息
  276. var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len
  277. //WriteLog($"已从{client.Id}接收到信息:{mes}");
  278. //client.Send(mes);
  279. //WriteLog("发送" + mes);
  280. try
  281. {
  282. #region 1-7
  283. if (client.IP == "192.168.10.1")//1号机
  284. {
  285. if (mes.Split(":")[0] == "WU")
  286. {
  287. Material1 = mes.Split(":")[1];
  288. client.Send($"WU:物料上传成功");
  289. WriteLog("1#物料上传成功");
  290. }
  291. if (mes.Split(":")[0] == "New")
  292. {
  293. var newOper = new Account()
  294. {
  295. Id = Guid.NewGuid(),
  296. AccountID = mes.Split(":")[1],
  297. ChangePassword = mes.Split(":")[2],
  298. };
  299. _repository.Add(newOper);
  300. client.Send($"NewSuc:注册成功");
  301. WriteLog("1#注册成功");
  302. }
  303. if (mes.Split(":")[0] == "Login")
  304. {
  305. string accountID = mes.Split(":")[1];
  306. string changePassword = mes.Split(":")[2];
  307. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  308. if (login != null)
  309. {
  310. Operator1 = accountID;
  311. client.Send($"LoginSuc:登录成功");
  312. WriteLog("1#登录成功");
  313. }
  314. }
  315. if (mes == "切换完成")
  316. {
  317. inovanceTcp.WriteDate("D1501.0", true);
  318. Thread.Sleep(1000);
  319. WriteLog("1#切换完成");
  320. }
  321. inovanceTcp.WriteDate("D1501.0", false);
  322. }
  323. if (client.IP == "192.168.10.2")//2号机
  324. {
  325. if (mes.Split(":")[0] == "WU")
  326. {
  327. Material2 = mes.Split(":")[1];
  328. client.Send($"WU:物料上传成功");
  329. WriteLog("2#物料上传成功");
  330. }
  331. if (mes.Split(":")[0] == "New")
  332. {
  333. var newOper = new Account()
  334. {
  335. Id = Guid.NewGuid(),
  336. AccountID = mes.Split(":")[1],
  337. ChangePassword = mes.Split(":")[2],
  338. };
  339. _repository.Add(newOper);
  340. client.Send($"NewSuc:注册成功");
  341. WriteLog("2#注册成功");
  342. }
  343. if (mes.Split(":")[0] == "Login")
  344. {
  345. string accountID = mes.Split(":")[1];
  346. string changePassword = mes.Split(":")[2];
  347. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  348. if (login != null)
  349. {
  350. Operator2 = accountID;
  351. client.Send($"LoginSuc:登录成功");
  352. WriteLog("2#登录成功");
  353. }
  354. }
  355. if (mes == "切换完成")
  356. {
  357. inovanceTcp.WriteDate("D1501.1", true);
  358. Thread.Sleep(1000);
  359. WriteLog("2#切换完成");
  360. }
  361. inovanceTcp.WriteDate("D1501.1", false);
  362. }
  363. if (client.IP == "192.168.10.3")//3号机
  364. {
  365. if (mes.Split(":")[0] == "WU")
  366. {
  367. Material3 = mes.Split(":")[1];
  368. client.Send($"WU:物料上传成功");
  369. WriteLog("3#物料上传成功");
  370. }
  371. if (mes.Split(":")[0] == "New")
  372. {
  373. var newOper = new Account()
  374. {
  375. Id = Guid.NewGuid(),
  376. AccountID = mes.Split(":")[1],
  377. ChangePassword = mes.Split(":")[2],
  378. };
  379. _repository.Add(newOper);
  380. client.Send($"NewSuc:注册成功");
  381. WriteLog("3#注册成功");
  382. }
  383. if (mes.Split(":")[0] == "Login")
  384. {
  385. string accountID = mes.Split(":")[1];
  386. string changePassword = mes.Split(":")[2];
  387. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  388. if (login != null)
  389. {
  390. Operator3 = accountID;
  391. client.Send($"LoginSuc:登录成功");
  392. WriteLog("3#登录成功");
  393. }
  394. }
  395. if (mes == "切换完成")
  396. {
  397. inovanceTcp.WriteDate("D1501.2", true);
  398. Thread.Sleep(1000);
  399. WriteLog("3#切换完成");
  400. }
  401. inovanceTcp.WriteDate("D1501.2", false);
  402. }
  403. if (client.IP == "192.168.10.4")//4号机
  404. {
  405. if (mes.Split(":")[0] == "WU")
  406. {
  407. Material4 = mes.Split(":")[1];
  408. client.Send($"WU:物料上传成功");
  409. WriteLog("4#物料上传成功");
  410. }
  411. if (mes.Split(":")[0] == "New")
  412. {
  413. var newOper = new Account()
  414. {
  415. Id = Guid.NewGuid(),
  416. AccountID = mes.Split(":")[1],
  417. ChangePassword = mes.Split(":")[2],
  418. };
  419. _repository.Add(newOper);
  420. client.Send($"NewSuc:注册成功");
  421. WriteLog("4#注册成功");
  422. }
  423. if (mes.Split(":")[0] == "Login")
  424. {
  425. string accountID = mes.Split(":")[1];
  426. string changePassword = mes.Split(":")[2];
  427. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  428. if (login != null)
  429. {
  430. Operator4 = accountID;
  431. client.Send($"LoginSuc:登录成功");
  432. WriteLog("4#登录成功");
  433. }
  434. }
  435. if (mes == "切换完成")
  436. {
  437. inovanceTcp.WriteDate("D1501.3", true);
  438. Thread.Sleep(1000);
  439. WriteLog("4#切换完成");
  440. }
  441. inovanceTcp.WriteDate("D1501.3", false);
  442. }
  443. if (client.IP == "192.168.10.5")//5号机
  444. {
  445. if (mes.Split(":")[0] == "WU")
  446. {
  447. Material5 = mes.Split(":")[1];
  448. client.Send($"WU:物料上传成功");
  449. WriteLog("5#物料上传成功");
  450. }
  451. if (mes.Split(":")[0] == "New")
  452. {
  453. var newOper = new Account()
  454. {
  455. Id = Guid.NewGuid(),
  456. AccountID = mes.Split(":")[1],
  457. ChangePassword = mes.Split(":")[2],
  458. };
  459. _repository.Add(newOper);
  460. client.Send($"NewSuc:注册成功");
  461. WriteLog("5#注册成功");
  462. }
  463. if (mes.Split(":")[0] == "Login")
  464. {
  465. string accountID = mes.Split(":")[1];
  466. string changePassword = mes.Split(":")[2];
  467. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  468. if (login != null)
  469. {
  470. Operator5 = accountID;
  471. client.Send($"LoginSuc:登录成功");
  472. WriteLog("5#登录成功");
  473. }
  474. }
  475. if (mes == "切换完成")
  476. {
  477. inovanceTcp.WriteDate("D1501.4", true);
  478. Thread.Sleep(1000);
  479. WriteLog("5#切换完成");
  480. }
  481. inovanceTcp.WriteDate("D1501.4", false);
  482. }
  483. if (client.IP == "192.168.10.6")//6号机
  484. {
  485. if (mes.Split(":")[0] == "WU")
  486. {
  487. Material6 = mes.Split(":")[1];
  488. client.Send($"WU:物料上传成功");
  489. WriteLog("6#物料上传成功");
  490. }
  491. if (mes.Split(":")[0] == "New")
  492. {
  493. var newOper = new Account()
  494. {
  495. Id = Guid.NewGuid(),
  496. AccountID = mes.Split(":")[1],
  497. ChangePassword = mes.Split(":")[2],
  498. };
  499. _repository.Add(newOper);
  500. client.Send($"NewSuc:注册成功");
  501. WriteLog("6#注册成功");
  502. }
  503. if (mes.Split(":")[0] == "Login")
  504. {
  505. string accountID = mes.Split(":")[1];
  506. string changePassword = mes.Split(":")[2];
  507. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  508. if (login != null)
  509. {
  510. Operator6 = accountID;
  511. client.Send($"LoginSuc:登录成功");
  512. WriteLog("6#登录成功");
  513. }
  514. }
  515. if (mes == "切换完成")
  516. {
  517. inovanceTcp.WriteDate("D1501.5", true);
  518. Thread.Sleep(1000);
  519. WriteLog("6#切换完成");
  520. }
  521. inovanceTcp.WriteDate("D1501.5", false);
  522. }
  523. if (client.IP == "192.168.10.7")//7号机
  524. {
  525. if (mes.Split(":")[0] == "WU")
  526. {
  527. Material7 = mes.Split(":")[1];
  528. client.Send($"WU:物料上传成功");
  529. WriteLog("7#物料上传成功");
  530. }
  531. if (mes.Split(":")[0] == "New")
  532. {
  533. var newOper = new Account()
  534. {
  535. Id = Guid.NewGuid(),
  536. AccountID = mes.Split(":")[1],
  537. ChangePassword = mes.Split(":")[2],
  538. };
  539. _repository.Add(newOper);
  540. client.Send($"NewSuc:注册成功");
  541. WriteLog("7#注册成功");
  542. }
  543. if (mes.Split(":")[0] == "Login")
  544. {
  545. string accountID = mes.Split(":")[1];
  546. string changePassword = mes.Split(":")[2];
  547. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  548. if (login != null)
  549. {
  550. Operator7 = accountID;
  551. client.Send($"LoginSuc:登录成功");
  552. WriteLog("7#登录成功");
  553. }
  554. }
  555. if (mes == "切换完成")
  556. {
  557. inovanceTcp.WriteDate("D1501.6", true);
  558. Thread.Sleep(1000);
  559. WriteLog("7#切换完成");
  560. }
  561. inovanceTcp.WriteDate("D1501.6", false);
  562. }
  563. #endregion
  564. #region 7-14
  565. if (client.IP == "192.168.10.8")//8号机
  566. {
  567. if (mes.Split(":")[0] == "WU")
  568. {
  569. Material8 = mes.Split(":")[1];
  570. client.Send($"WU:物料上传成功");
  571. WriteLog("8#物料上传成功");
  572. }
  573. if (mes.Split(":")[0] == "New")
  574. {
  575. var newOper = new Account()
  576. {
  577. Id = Guid.NewGuid(),
  578. AccountID = mes.Split(":")[1],
  579. ChangePassword = mes.Split(":")[2],
  580. };
  581. _repository.Add(newOper);
  582. client.Send($"NewSuc:注册成功");
  583. WriteLog("8#注册成功");
  584. }
  585. if (mes.Split(":")[0] == "Login")
  586. {
  587. string accountID = mes.Split(":")[1];
  588. string changePassword = mes.Split(":")[2];
  589. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  590. if (login != null)
  591. {
  592. Operator8 = accountID;
  593. client.Send($"LoginSuc:登录成功");
  594. WriteLog("8#登录成功");
  595. }
  596. }
  597. if (mes == "切换完成")
  598. {
  599. inovanceTcp.WriteDate("D1501.7", true);
  600. Thread.Sleep(1000);
  601. WriteLog("8#切换完成");
  602. }
  603. inovanceTcp.WriteDate("D1501.7", false);
  604. }
  605. if (client.IP == "192.168.10.9")//9号机
  606. {
  607. if (mes.Split(":")[0] == "WU")
  608. {
  609. Material9 = mes.Split(":")[1];
  610. client.Send($"WU:物料上传成功");
  611. WriteLog("9#物料上传成功");
  612. }
  613. if (mes.Split(":")[0] == "New")
  614. {
  615. var newOper = new Account()
  616. {
  617. Id = Guid.NewGuid(),
  618. AccountID = mes.Split(":")[1],
  619. ChangePassword = mes.Split(":")[2],
  620. };
  621. _repository.Add(newOper);
  622. client.Send($"NewSuc:注册成功");
  623. WriteLog("9#注册成功");
  624. }
  625. if (mes.Split(":")[0] == "Login")
  626. {
  627. string accountID = mes.Split(":")[1];
  628. string changePassword = mes.Split(":")[2];
  629. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  630. if (login != null)
  631. {
  632. Operator9 = accountID;
  633. client.Send($"LoginSuc:登录成功");
  634. WriteLog("9#登录成功");
  635. }
  636. }
  637. if (mes == "切换完成")
  638. {
  639. inovanceTcp.WriteDate("D1501.8", true);
  640. Thread.Sleep(1000);
  641. WriteLog("9#切换完成");
  642. }
  643. inovanceTcp.WriteDate("D1501.8", false);
  644. }
  645. if (client.IP == "192.168.10.10")//10号机
  646. {
  647. if (mes.Split(":")[0] == "WU")
  648. {
  649. Material10 = mes.Split(":")[1];
  650. client.Send($"WU:物料上传成功");
  651. WriteLog("10#物料上传成功");
  652. }
  653. if (mes.Split(":")[0] == "New")
  654. {
  655. var newOper = new Account()
  656. {
  657. Id = Guid.NewGuid(),
  658. AccountID = mes.Split(":")[1],
  659. ChangePassword = mes.Split(":")[2],
  660. };
  661. _repository.Add(newOper);
  662. client.Send($"NewSuc:注册成功");
  663. WriteLog("10#注册成功");
  664. }
  665. if (mes.Split(":")[0] == "Login")
  666. {
  667. string accountID = mes.Split(":")[1];
  668. string changePassword = mes.Split(":")[2];
  669. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  670. if (login != null)
  671. {
  672. Operator10 = accountID;
  673. client.Send($"LoginSuc:登录成功");
  674. WriteLog("10#登录成功");
  675. }
  676. }
  677. if (mes == "切换完成")
  678. {
  679. inovanceTcp.WriteDate("D1501.9", true);
  680. Thread.Sleep(1000);
  681. WriteLog("10#切换完成");
  682. }
  683. inovanceTcp.WriteDate("D1501.9", false);
  684. }
  685. if (client.IP == "192.168.10.11")//11号机
  686. {
  687. if (mes.Split(":")[0] == "WU")
  688. {
  689. Material11 = mes.Split(":")[1];
  690. client.Send($"WU:物料上传成功");
  691. WriteLog("11#物料上传成功");
  692. }
  693. if (mes.Split(":")[0] == "New")
  694. {
  695. var newOper = new Account()
  696. {
  697. Id = Guid.NewGuid(),
  698. AccountID = mes.Split(":")[1],
  699. ChangePassword = mes.Split(":")[2],
  700. };
  701. _repository.Add(newOper);
  702. client.Send($"NewSuc:注册成功");
  703. WriteLog("11#注册成功");
  704. }
  705. if (mes.Split(":")[0] == "Login")
  706. {
  707. string accountID = mes.Split(":")[1];
  708. string changePassword = mes.Split(":")[2];
  709. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  710. if (login != null)
  711. {
  712. Operator11 = accountID;
  713. client.Send($"LoginSuc:登录成功");
  714. WriteLog("11#登录成功");
  715. }
  716. }
  717. if (mes == "切换完成")
  718. {
  719. inovanceTcp.WriteDate("D1501.10", true);
  720. Thread.Sleep(1000);
  721. WriteLog("11#切换完成");
  722. }
  723. inovanceTcp.WriteDate("D1501.10", false);
  724. }
  725. if (client.IP == "192.168.10.12")//12号机
  726. {
  727. if (mes.Split(":")[0] == "WU")
  728. {
  729. Material12 = mes.Split(":")[1];
  730. client.Send($"WU:物料上传成功");
  731. WriteLog("12#物料上传成功");
  732. }
  733. if (mes.Split(":")[0] == "New")
  734. {
  735. var newOper = new Account()
  736. {
  737. Id = Guid.NewGuid(),
  738. AccountID = mes.Split(":")[1],
  739. ChangePassword = mes.Split(":")[2],
  740. };
  741. _repository.Add(newOper);
  742. client.Send($"NewSuc:注册成功");
  743. WriteLog("12#注册成功");
  744. }
  745. if (mes.Split(":")[0] == "Login")
  746. {
  747. string accountID = mes.Split(":")[1];
  748. string changePassword = mes.Split(":")[2];
  749. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  750. if (login != null)
  751. {
  752. Operator12 = accountID;
  753. client.Send($"LoginSuc:登录成功");
  754. WriteLog("12#登录成功");
  755. }
  756. }
  757. if (mes == "切换完成")
  758. {
  759. inovanceTcp.WriteDate("D1501.11", true);
  760. Thread.Sleep(1000);
  761. WriteLog("12#切换完成");
  762. }
  763. inovanceTcp.WriteDate("D1501.11", false);
  764. }
  765. if (client.IP == "192.168.10.13")//13号机
  766. {
  767. if (mes.Split(":")[0] == "WU")
  768. {
  769. Material13 = mes.Split(":")[1];
  770. client.Send($"WU:物料上传成功");
  771. WriteLog("13#物料上传成功");
  772. }
  773. if (mes.Split(":")[0] == "New")
  774. {
  775. var newOper = new Account()
  776. {
  777. Id = Guid.NewGuid(),
  778. AccountID = mes.Split(":")[1],
  779. ChangePassword = mes.Split(":")[2],
  780. };
  781. _repository.Add(newOper);
  782. client.Send($"NewSuc:注册成功");
  783. WriteLog("13#注册成功");
  784. }
  785. if (mes.Split(":")[0] == "Login")
  786. {
  787. string accountID = mes.Split(":")[1];
  788. string changePassword = mes.Split(":")[2];
  789. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  790. if (login != null)
  791. {
  792. Operator13 = accountID;
  793. client.Send($"LoginSuc:登录成功");
  794. WriteLog("13#登录成功");
  795. }
  796. }
  797. if (mes == "切换完成")
  798. {
  799. inovanceTcp.WriteDate("D1501.12", true);
  800. Thread.Sleep(1000);
  801. WriteLog("13#切换完成");
  802. }
  803. inovanceTcp.WriteDate("D1501.12", false);
  804. }
  805. if (client.IP == "192.168.10.14")//14号机
  806. {
  807. if (mes.Split(":")[0] == "WU")
  808. {
  809. Material14 = mes.Split(":")[1];
  810. client.Send($"WU:物料上传成功");
  811. WriteLog("14#物料上传成功");
  812. }
  813. if (mes.Split(":")[0] == "New")
  814. {
  815. var newOper = new Account()
  816. {
  817. Id = Guid.NewGuid(),
  818. AccountID = mes.Split(":")[1],
  819. ChangePassword = mes.Split(":")[2],
  820. };
  821. _repository.Add(newOper);
  822. client.Send($"NewSuc:注册成功");
  823. WriteLog("14#注册成功");
  824. }
  825. if (mes.Split(":")[0] == "Login")
  826. {
  827. string accountID = mes.Split(":")[1];
  828. string changePassword = mes.Split(":")[2];
  829. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  830. if (login != null)
  831. {
  832. Operator14 = accountID;
  833. client.Send($"LoginSuc:登录成功");
  834. WriteLog("14#登录成功");
  835. }
  836. }
  837. if (mes == "切换完成")
  838. {
  839. inovanceTcp.WriteDate("D1501.13", true);
  840. Thread.Sleep(1000);
  841. WriteLog("14#切换完成");
  842. }
  843. inovanceTcp.WriteDate("D1501.13", false);
  844. }
  845. #endregion
  846. #region test
  847. if (client.IP == "192.168.10.15")//检测1
  848. {
  849. if (mes.Split(":")[0] == "Test")
  850. {
  851. for (int i = 0; i < 30; i++)
  852. {
  853. if (mes.Split(":")[i+1] == "1")
  854. {
  855. q[i] = 1;
  856. }
  857. else
  858. {
  859. q[i] = 0;
  860. }
  861. }
  862. string str = DateTime.Now.ToString("yyyy/MM/dd");
  863. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality==str);//查一个值
  864. if (list != null)
  865. {
  866. list.Q1 = list.Q1 + q[0];
  867. list.Q2 = list.Q2 + q[1];
  868. list.Q3 = list.Q3 + q[2];
  869. list.Q4 = list.Q4 + q[3];
  870. list.Q5 = list.Q5 + q[4];
  871. list.Q6 = list.Q6 + q[5];
  872. list.Q7 = list.Q7 + q[6];
  873. list.Q8 = list.Q8 + q[7];
  874. list.Q9 = list.Q9 + q[8];
  875. list.Q10 = list.Q10 + q[9];
  876. list.Q11 = list.Q11 + q[10];
  877. list.Q12 = list.Q12 + q[11];
  878. list.Q13 = list.Q13 + q[12];
  879. list.Q14 = list.Q14 + q[13];
  880. list.Q15 = list.Q15 + q[14];
  881. list.Q16 = list.Q16 + q[15];
  882. list.Q17 = list.Q17 + q[16];
  883. list.Q18 = list.Q18 + q[17];
  884. list.Q19 = list.Q19 + q[18];
  885. list.Q20 = list.Q20 + q[19];
  886. list.Q21 = list.Q21 + q[20];
  887. list.Q22 = list.Q22 + q[21];
  888. list.Q23 = list.Q23 + q[22];
  889. list.Q24 = list.Q24 + q[23];
  890. list.Q25 = list.Q25 + q[24];
  891. list.Q26 = list.Q26 + q[25];
  892. list.Q27 = list.Q27 + q[26];
  893. list.Q28 = list.Q28 + q[27];
  894. list.Q29 = list.Q29 + q[28];
  895. list.Q30 = list.Q30 + q[29];
  896. _repository.Update(list);
  897. client.Send("Te:上传成功");
  898. WriteLog("检测1#上传成功");
  899. }
  900. else
  901. {
  902. var item = new Quality()
  903. {
  904. Id = Guid.NewGuid(),
  905. DateQuality = str,
  906. Q1 = q[0],Q2 = q[1],Q3 = q[2], Q4 = q[3],Q5 = q[4],
  907. Q6 = q[5], Q7 = q[6], Q8 = q[7],Q9 = q[8],Q10 = q[9],
  908. Q11 = q[10], Q12 = q[11],Q13 = q[12], Q14 = q[13],Q15 = q[14],
  909. Q16 = q[15],Q17 = q[16],Q18 = q[17],Q19 = q[18],Q20 = q[19],
  910. Q21 = q[20],Q22 = q[21],Q23 = q[22], Q24 = q[23], Q25 = q[24],
  911. Q26 = q[25], Q27 = q[26],Q28 = q[27],Q29 = q[28],Q30 = q[29],
  912. };
  913. _repository.Add(item);
  914. client.Send("Te:上传成功");
  915. WriteLog("检测1#上传成功");
  916. }
  917. }
  918. if (mes == "切换完成")
  919. {
  920. inovanceTcp.WriteDate("D1501.14", true);
  921. Thread.Sleep(1000);
  922. WriteLog("检测1#切换完成");
  923. }
  924. inovanceTcp.WriteDate("D1501.14", false);
  925. if (mes.Split(":")[0] == "New")
  926. {
  927. var newOper = new Account()
  928. {
  929. Id = Guid.NewGuid(),
  930. AccountID = mes.Split(":")[1],
  931. ChangePassword = mes.Split(":")[2],
  932. };
  933. _repository.Add(newOper);
  934. client.Send($"NewSuc:注册成功");
  935. WriteLog("检测1#注册成功");
  936. }
  937. if (mes.Split(":")[0] == "Login")
  938. {
  939. string accountID = mes.Split(":")[1];
  940. string changePassword = mes.Split(":")[2];
  941. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  942. if (login != null)
  943. {
  944. Operator15 = accountID;
  945. client.Send($"LoginSuc:登录成功");
  946. WriteLog("检测1#登录成功");
  947. }
  948. }
  949. }
  950. if (client.IP == "192.168.10.16")//检测2
  951. {
  952. if (mes.Split(":")[0] == "Test")
  953. {
  954. for (int i = 0; i < 30; i++)
  955. {
  956. if (mes.Split(":")[i + 1] == "1")
  957. {
  958. q[i] = 1;
  959. }
  960. else
  961. {
  962. q[i] = 0;
  963. }
  964. }
  965. string str = DateTime.Now.ToString("yyyy/MM/dd");
  966. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == str);//查一个值
  967. if (list != null)
  968. {
  969. list.Q1 = list.Q1 + q[0];
  970. list.Q2 = list.Q2 + q[1];
  971. list.Q3 = list.Q3 + q[2];
  972. list.Q4 = list.Q4 + q[3];
  973. list.Q5 = list.Q5 + q[4];
  974. list.Q6 = list.Q6 + q[5];
  975. list.Q7 = list.Q7 + q[6];
  976. list.Q8 = list.Q8 + q[7];
  977. list.Q9 = list.Q9 + q[8];
  978. list.Q10 = list.Q10 + q[9];
  979. list.Q11 = list.Q11 + q[10];
  980. list.Q12 = list.Q12 + q[11];
  981. list.Q13 = list.Q13 + q[12];
  982. list.Q14 = list.Q14 + q[13];
  983. list.Q15 = list.Q15 + q[14];
  984. list.Q16 = list.Q16 + q[15];
  985. list.Q17 = list.Q17 + q[16];
  986. list.Q18 = list.Q18 + q[17];
  987. list.Q19 = list.Q19 + q[18];
  988. list.Q20 = list.Q20 + q[19];
  989. list.Q21 = list.Q21 + q[20];
  990. list.Q22 = list.Q22 + q[21];
  991. list.Q23 = list.Q23 + q[22];
  992. list.Q24 = list.Q24 + q[23];
  993. list.Q25 = list.Q25 + q[24];
  994. list.Q26 = list.Q26 + q[25];
  995. list.Q27 = list.Q27 + q[26];
  996. list.Q28 = list.Q28 + q[27];
  997. list.Q29 = list.Q29 + q[28];
  998. list.Q30 = list.Q30 + q[29];
  999. _repository.Update(list);
  1000. client.Send("Te:上传成功");
  1001. WriteLog("检测2#上传成功");
  1002. }
  1003. else
  1004. {
  1005. var item = new Quality()
  1006. {
  1007. Id = Guid.NewGuid(),
  1008. DateQuality = str,
  1009. Q1 = q[0],
  1010. Q2 = q[1],
  1011. Q3 = q[2],
  1012. Q4 = q[3],
  1013. Q5 = q[4],
  1014. Q6 = q[5],
  1015. Q7 = q[6],
  1016. Q8 = q[7],
  1017. Q9 = q[8],
  1018. Q10 = q[9],
  1019. Q11 = q[10],
  1020. Q12 = q[11],
  1021. Q13 = q[12],
  1022. Q14 = q[13],
  1023. Q15 = q[14],
  1024. Q16 = q[15],
  1025. Q17 = q[16],
  1026. Q18 = q[17],
  1027. Q19 = q[18],
  1028. Q20 = q[19],
  1029. Q21 = q[20],
  1030. Q22 = q[21],
  1031. Q23 = q[22],
  1032. Q24 = q[23],
  1033. Q25 = q[24],
  1034. Q26 = q[25],
  1035. Q27 = q[26],
  1036. Q28 = q[27],
  1037. Q29 = q[28],
  1038. Q30 = q[29],
  1039. };
  1040. _repository.Add(item);
  1041. client.Send("Te:上传成功");
  1042. WriteLog("检测2#上传成功");
  1043. }
  1044. }
  1045. if (mes == "切换完成")
  1046. {
  1047. inovanceTcp.WriteDate("D1501.15", true);
  1048. Thread.Sleep(1000);
  1049. WriteLog("检测2#切换完成");
  1050. }
  1051. inovanceTcp.WriteDate("D1501.15", false);
  1052. if (mes.Split(":")[0] == "New")
  1053. {
  1054. var newOper = new Account()
  1055. {
  1056. Id = Guid.NewGuid(),
  1057. AccountID = mes.Split(":")[1],
  1058. ChangePassword = mes.Split(":")[2],
  1059. };
  1060. _repository.Add(newOper);
  1061. client.Send($"NewSuc:注册成功");
  1062. WriteLog("检测2#注册成功");
  1063. }
  1064. if (mes.Split(":")[0] == "Login")
  1065. {
  1066. string accountID = mes.Split(":")[1];
  1067. string changePassword = mes.Split(":")[2];
  1068. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  1069. if (login != null)
  1070. {
  1071. Operator16 = accountID;
  1072. client.Send($"LoginSuc:登录成功");
  1073. WriteLog("检测2#登录成功");
  1074. }
  1075. }
  1076. }
  1077. if (client.IP == "192.168.10.17")//检测3
  1078. {
  1079. if (mes.Split(":")[0] == "Test")
  1080. {
  1081. for (int i = 0; i < 30; i++)
  1082. {
  1083. if (mes.Split(":")[i + 1] == "1")
  1084. {
  1085. q[i] = 1;
  1086. }
  1087. else
  1088. {
  1089. q[i] = 0;
  1090. }
  1091. }
  1092. string str = DateTime.Now.ToString("yyyy/MM/dd");
  1093. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == str);//查一个值
  1094. if (list != null)
  1095. {
  1096. list.Q1 = list.Q1 + q[0];
  1097. list.Q2 = list.Q2 + q[1];
  1098. list.Q3 = list.Q3 + q[2];
  1099. list.Q4 = list.Q4 + q[3];
  1100. list.Q5 = list.Q5 + q[4];
  1101. list.Q6 = list.Q6 + q[5];
  1102. list.Q7 = list.Q7 + q[6];
  1103. list.Q8 = list.Q8 + q[7];
  1104. list.Q9 = list.Q9 + q[8];
  1105. list.Q10 = list.Q10 + q[9];
  1106. list.Q11 = list.Q11 + q[10];
  1107. list.Q12 = list.Q12 + q[11];
  1108. list.Q13 = list.Q13 + q[12];
  1109. list.Q14 = list.Q14 + q[13];
  1110. list.Q15 = list.Q15 + q[14];
  1111. list.Q16 = list.Q16 + q[15];
  1112. list.Q17 = list.Q17 + q[16];
  1113. list.Q18 = list.Q18 + q[17];
  1114. list.Q19 = list.Q19 + q[18];
  1115. list.Q20 = list.Q20 + q[19];
  1116. list.Q21 = list.Q21 + q[20];
  1117. list.Q22 = list.Q22 + q[21];
  1118. list.Q23 = list.Q23 + q[22];
  1119. list.Q24 = list.Q24 + q[23];
  1120. list.Q25 = list.Q25 + q[24];
  1121. list.Q26 = list.Q26 + q[25];
  1122. list.Q27 = list.Q27 + q[26];
  1123. list.Q28 = list.Q28 + q[27];
  1124. list.Q29 = list.Q29 + q[28];
  1125. list.Q30 = list.Q30 + q[29];
  1126. _repository.Update(list);
  1127. client.Send("Te:上传成功");
  1128. WriteLog("检测3#上传成功");
  1129. }
  1130. else
  1131. {
  1132. var item = new Quality()
  1133. {
  1134. Id = Guid.NewGuid(),
  1135. DateQuality = str,
  1136. Q1 = q[0],
  1137. Q2 = q[1],
  1138. Q3 = q[2],
  1139. Q4 = q[3],
  1140. Q5 = q[4],
  1141. Q6 = q[5],
  1142. Q7 = q[6],
  1143. Q8 = q[7],
  1144. Q9 = q[8],
  1145. Q10 = q[9],
  1146. Q11 = q[10],
  1147. Q12 = q[11],
  1148. Q13 = q[12],
  1149. Q14 = q[13],
  1150. Q15 = q[14],
  1151. Q16 = q[15],
  1152. Q17 = q[16],
  1153. Q18 = q[17],
  1154. Q19 = q[18],
  1155. Q20 = q[19],
  1156. Q21 = q[20],
  1157. Q22 = q[21],
  1158. Q23 = q[22],
  1159. Q24 = q[23],
  1160. Q25 = q[24],
  1161. Q26 = q[25],
  1162. Q27 = q[26],
  1163. Q28 = q[27],
  1164. Q29 = q[28],
  1165. Q30 = q[29],
  1166. };
  1167. _repository.Add(item);
  1168. client.Send("Te:上传成功");
  1169. WriteLog("检测3#上传成功");
  1170. }
  1171. }
  1172. if (mes == "切换完成")
  1173. {
  1174. inovanceTcp.WriteDate("D1502.0", true);
  1175. Thread.Sleep(1000);
  1176. WriteLog("检测3#切换完成");
  1177. }
  1178. inovanceTcp.WriteDate("D1502.0", false);
  1179. if (mes.Split(":")[0] == "New")
  1180. {
  1181. var newOper = new Account()
  1182. {
  1183. Id = Guid.NewGuid(),
  1184. AccountID = mes.Split(":")[1],
  1185. ChangePassword = mes.Split(":")[2],
  1186. };
  1187. _repository.Add(newOper);
  1188. client.Send($"NewSuc:注册成功");
  1189. WriteLog("检测3#注册成功");
  1190. }
  1191. if (mes.Split(":")[0] == "Login")
  1192. {
  1193. string accountID = mes.Split(":")[1];
  1194. string changePassword = mes.Split(":")[2];
  1195. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  1196. if (login != null)
  1197. {
  1198. Operator17 = accountID;
  1199. client.Send($"LoginSuc:登录成功");
  1200. WriteLog("检测3#登录成功");
  1201. }
  1202. }
  1203. }
  1204. if (client.IP == "192.168.10.18")//检测4
  1205. {
  1206. if (mes.Split(":")[0] == "Test")
  1207. {
  1208. for (int i = 0; i < 30; i++)
  1209. {
  1210. if (mes.Split(":")[i + 1] == "1")
  1211. {
  1212. q[i] = 1;
  1213. }
  1214. else
  1215. {
  1216. q[i] = 0;
  1217. }
  1218. }
  1219. string str = DateTime.Now.ToString("yyyy/MM/dd");
  1220. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == str);//查一个值
  1221. if (list != null)
  1222. {
  1223. list.Q1 = list.Q1 + q[0];
  1224. list.Q2 = list.Q2 + q[1];
  1225. list.Q3 = list.Q3 + q[2];
  1226. list.Q4 = list.Q4 + q[3];
  1227. list.Q5 = list.Q5 + q[4];
  1228. list.Q6 = list.Q6 + q[5];
  1229. list.Q7 = list.Q7 + q[6];
  1230. list.Q8 = list.Q8 + q[7];
  1231. list.Q9 = list.Q9 + q[8];
  1232. list.Q10 = list.Q10 + q[9];
  1233. list.Q11 = list.Q11 + q[10];
  1234. list.Q12 = list.Q12 + q[11];
  1235. list.Q13 = list.Q13 + q[12];
  1236. list.Q14 = list.Q14 + q[13];
  1237. list.Q15 = list.Q15 + q[14];
  1238. list.Q16 = list.Q16 + q[15];
  1239. list.Q17 = list.Q17 + q[16];
  1240. list.Q18 = list.Q18 + q[17];
  1241. list.Q19 = list.Q19 + q[18];
  1242. list.Q20 = list.Q20 + q[19];
  1243. list.Q21 = list.Q21 + q[20];
  1244. list.Q22 = list.Q22 + q[21];
  1245. list.Q23 = list.Q23 + q[22];
  1246. list.Q24 = list.Q24 + q[23];
  1247. list.Q25 = list.Q25 + q[24];
  1248. list.Q26 = list.Q26 + q[25];
  1249. list.Q27 = list.Q27 + q[26];
  1250. list.Q28 = list.Q28 + q[27];
  1251. list.Q29 = list.Q29 + q[28];
  1252. list.Q30 = list.Q30 + q[29];
  1253. _repository.Update(list);
  1254. client.Send("Te:上传成功");
  1255. WriteLog("检测4#上传成功");
  1256. }
  1257. else
  1258. {
  1259. var item = new Quality()
  1260. {
  1261. Id = Guid.NewGuid(),
  1262. DateQuality = str,
  1263. Q1 = q[0],
  1264. Q2 = q[1],
  1265. Q3 = q[2],
  1266. Q4 = q[3],
  1267. Q5 = q[4],
  1268. Q6 = q[5],
  1269. Q7 = q[6],
  1270. Q8 = q[7],
  1271. Q9 = q[8],
  1272. Q10 = q[9],
  1273. Q11 = q[10],
  1274. Q12 = q[11],
  1275. Q13 = q[12],
  1276. Q14 = q[13],
  1277. Q15 = q[14],
  1278. Q16 = q[15],
  1279. Q17 = q[16],
  1280. Q18 = q[17],
  1281. Q19 = q[18],
  1282. Q20 = q[19],
  1283. Q21 = q[20],
  1284. Q22 = q[21],
  1285. Q23 = q[22],
  1286. Q24 = q[23],
  1287. Q25 = q[24],
  1288. Q26 = q[25],
  1289. Q27 = q[26],
  1290. Q28 = q[27],
  1291. Q29 = q[28],
  1292. Q30 = q[29],
  1293. };
  1294. _repository.Add(item);
  1295. client.Send("Te:上传成功");
  1296. WriteLog("检测4#上传成功");
  1297. }
  1298. }
  1299. if (mes == "切换完成")
  1300. {
  1301. inovanceTcp.WriteDate("D1502.1", true);
  1302. Thread.Sleep(1000);
  1303. WriteLog("检测4#切换完成");
  1304. }
  1305. inovanceTcp.WriteDate("D1502.1", false);
  1306. if (mes.Split(":")[0] == "New")
  1307. {
  1308. var newOper = new Account()
  1309. {
  1310. Id = Guid.NewGuid(),
  1311. AccountID = mes.Split(":")[1],
  1312. ChangePassword = mes.Split(":")[2],
  1313. };
  1314. _repository.Add(newOper);
  1315. client.Send($"NewSuc:注册成功");
  1316. WriteLog("检测4#注册成功");
  1317. }
  1318. if (mes.Split(":")[0] == "Login")
  1319. {
  1320. string accountID = mes.Split(":")[1];
  1321. string changePassword = mes.Split(":")[2];
  1322. var login = _repository.GetFirstDefault<Account>(c => c.AccountID == accountID && c.ChangePassword == changePassword);//数据库查
  1323. if (login != null)
  1324. {
  1325. Operator18 = accountID;
  1326. client.Send($"LoginSuc:登录成功");
  1327. WriteLog("检测4#登录成功");
  1328. }
  1329. }
  1330. }
  1331. #endregion
  1332. }
  1333. catch (Exception ex)
  1334. {
  1335. WriteLog($"报错:{ex.Message}");
  1336. }
  1337. return EasyTask.CompletedTask;
  1338. };
  1339. #endregion
  1340. SignalMapper = new Dictionary<int, string>
  1341. {
  1342. {1, "D1025.0" },
  1343. {2, "D1025.1" },
  1344. {3, "D1025.2" },
  1345. {4, "D1025.3" },
  1346. {5, "D1025.4" },
  1347. {6, "D1025.5" },
  1348. {7, "D1025.8" },
  1349. {8, "D1025.9" },
  1350. {9, "D1025.10" },
  1351. {10, "D1025.11" },
  1352. {11, "D1025.14" },
  1353. {12, "D1025.15" },
  1354. {13, "D1026.0" },
  1355. {14, "D1026.1" },
  1356. };
  1357. _stateService.CreateMachine(1, RecordOneMessage1, null);
  1358. _stateService.CreateMachine(2, RecordOneMessage2, null);
  1359. _stateService.CreateMachine(3, RecordOneMessage3, null);
  1360. _stateService.CreateMachine(4, RecordOneMessage4, null);
  1361. _stateService.CreateMachine(5, RecordOneMessage5, null);
  1362. _stateService.CreateMachine(6, RecordOneMessage6, null);
  1363. _stateService.CreateMachine(7, RecordOneMessage7, null);
  1364. _stateService.CreateMachine(8, RecordOneMessage8, null);
  1365. _stateService.CreateMachine(9, RecordOneMessage9, null);
  1366. _stateService.CreateMachine(10, RecordOneMessage10, null);
  1367. _stateService.CreateMachine(11, RecordOneMessage11, null);
  1368. _stateService.CreateMachine(12, RecordOneMessage12, null);
  1369. _stateService.CreateMachine(13, RecordOneMessage13, null);
  1370. _stateService.CreateMachine(14, RecordOneMessage14, null);
  1371. Task.Factory.StartNew(Timer_Elapsed, TaskCreationOptions.LongRunning);
  1372. Task.Factory.StartNew(Timer_Elapsed2, TaskCreationOptions.LongRunning);
  1373. QRCommand = new DelegateCommand(QRcode);
  1374. //_eventAggregator.GetEvent<FileChangedEvent>().Subscribe(ReadConfig);
  1375. }
  1376. private void OrderEnter()
  1377. {
  1378. try
  1379. {
  1380. if (string.IsNullOrWhiteSpace(SelectedOrderName))
  1381. {
  1382. }
  1383. else
  1384. {
  1385. Quest(SelectedOrderName);
  1386. WriteLog("切换订单成功");
  1387. }
  1388. }
  1389. catch (Exception)
  1390. {
  1391. }
  1392. }
  1393. public void ReadOrder()
  1394. {
  1395. var customRepo = new CustomRepository();
  1396. try
  1397. {
  1398. DateTime max = DateTime.Today.AddDays(1);
  1399. DateTime min = DateTime.Today.AddDays(-1);
  1400. //var list = customRepo.GetAllQuery<ICMO>(c => c.FDate == DateTime.Today);
  1401. var list = customRepo.GetAllQuery<ICMO>(c => c.FDate < max && c.FDate > min);
  1402. if (list != null)
  1403. {
  1404. OrderNames = new ObservableCollection<string>();
  1405. for (int i = 0; i < list.Count; i++)
  1406. {
  1407. OrderNames.Add(list[i].FBillNo);
  1408. }
  1409. }
  1410. }
  1411. catch (Exception ex)
  1412. {
  1413. }
  1414. }
  1415. private void UploadOutWork()
  1416. {
  1417. string str = DateTime.Now.ToString("yyyy/MM/dd");
  1418. var list = _repository.GetFirstDefault<OutofWork>(c => c.DateOutWork == str);
  1419. if (list != null)
  1420. {
  1421. list.DateOutWork = str;
  1422. list.Actual = ActPer;
  1423. list.FallIll = FallPer;
  1424. list.Absenteeism = AbsPer;
  1425. _repository.Update(list);
  1426. WriteLog("出勤信息上传成功");
  1427. }
  1428. else
  1429. {
  1430. var outwork = new OutofWork()
  1431. {
  1432. Id = Guid.NewGuid(),
  1433. DateOutWork = DateTime.Now.ToString("yyyy/MM/dd"),
  1434. Actual = ActPer,
  1435. FallIll = FallPer,
  1436. Absenteeism = AbsPer,
  1437. };
  1438. _repository.Add(outwork);
  1439. WriteLog("出勤信息上传成功");
  1440. }
  1441. }
  1442. private void UploadHouse()
  1443. {
  1444. string str = DateTime.Now.ToString("yyyy/MM/dd");
  1445. var list = _repository.GetFirstDefault<House>(c => c.DateH == str);
  1446. if (list != null)
  1447. {
  1448. list.DateH = str;
  1449. list.LackH = LackHouse;
  1450. list.UsedH = UsedHouse;
  1451. list.TotalH = TotalHouse;
  1452. _repository.Update(list);
  1453. WriteLog("线边仓数据上传成功");
  1454. }
  1455. else
  1456. {
  1457. var houses = new House()
  1458. {
  1459. Id = Guid.NewGuid(),
  1460. DateH = DateTime.Now.ToString("yyyy/MM/dd"),
  1461. LackH = LackHouse,
  1462. UsedH = UsedHouse,
  1463. TotalH = TotalHouse,
  1464. };
  1465. _repository.Add(houses);
  1466. WriteLog("线边仓数据上传成功");
  1467. }
  1468. }
  1469. //void SwitchProduct()
  1470. //{
  1471. // SendToClient("Num1");
  1472. //}
  1473. //public void SendToClient(string id)
  1474. //{
  1475. // //tcpService.SocketClients.GetIds() 向所有id发送
  1476. // //foreach (var item in tcpService.SocketClients.GetIds())
  1477. // //{
  1478. // // if (string.IsNullOrWhiteSpace(SelectedConfigName))
  1479. // // {
  1480. // // tcpService.Send(item, "None");
  1481. // // WriteLog("发送:None");
  1482. // // return;
  1483. // // }
  1484. // // tcpService.Send(item, SelectedConfigName);
  1485. // // WriteLog("发送:" + SelectedConfigName);
  1486. // //}
  1487. // if (string.IsNullOrWhiteSpace(SelectedConfigName))
  1488. // {
  1489. // tcpService.Send(id, "None");
  1490. // WriteLog("发送:None");
  1491. // return;
  1492. // }
  1493. // tcpService.Send(id, SelectedConfigName);
  1494. // WriteLog("发送:" + SelectedConfigName);
  1495. //}
  1496. public void SendPro(string id, string name)
  1497. {
  1498. try
  1499. {
  1500. var ids = tcpService.SocketClients.GetIds();
  1501. foreach (var item in tcpService.SocketClients.GetClients())
  1502. {
  1503. if (item.IP == id)
  1504. {
  1505. item.Send("Type:" + name + ":" + id);
  1506. WriteLog("发送:" + name);
  1507. break;
  1508. }
  1509. }
  1510. //tcpService.Send(id, "Type:" + name + ":" + id);
  1511. //WriteLog("发送:" + name);
  1512. }
  1513. catch (Exception)
  1514. {
  1515. }
  1516. }
  1517. #region 工位
  1518. public void RecordOneMessage1(object sender, StateEventArgs e)//1
  1519. {
  1520. var spt = inovanceTcp.ReadInt("D1003");
  1521. var d1 = inovanceTcp.ReadInt("D1030");
  1522. var d2 = inovanceTcp.ReadInt("D1031");
  1523. var d3 = inovanceTcp.ReadInt("D1032");
  1524. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1525. var productNew = new InformationNew
  1526. {
  1527. OperatorCode = Operator1,
  1528. ProCode = Material1,
  1529. SpendTime = spt/10,
  1530. CreateTime = DateTime.Now,
  1531. ProType = proName,
  1532. ProNo=pno,
  1533. };
  1534. var product = new Information()
  1535. {
  1536. CreateTime = productNew.CreateTime,
  1537. Id = Guid.NewGuid(),
  1538. OperatorCode = productNew.OperatorCode,
  1539. ProCode = productNew.ProCode,
  1540. SpendTime = productNew.SpendTime,
  1541. ProType = productNew.ProType,
  1542. ProNo=productNew.ProNo
  1543. };
  1544. InforNew.Add(productNew);
  1545. _repository.Add(product);
  1546. inovanceTcp.WriteDate("D1025.0", false);
  1547. }
  1548. public void RecordOneMessage2(object sender, StateEventArgs e)//2
  1549. {
  1550. var spt = inovanceTcp.ReadInt("D1004");
  1551. var d1 = inovanceTcp.ReadInt("D1033");
  1552. var d2 = inovanceTcp.ReadInt("D1034");
  1553. var d3 = inovanceTcp.ReadInt("D1035");
  1554. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1555. var productNew = new InformationNew
  1556. {
  1557. OperatorCode = Operator2,
  1558. ProCode = Material2,
  1559. SpendTime = spt/10,
  1560. CreateTime = DateTime.Now,
  1561. ProType = proName,
  1562. ProNo = pno,
  1563. };
  1564. var product = new Information()
  1565. {
  1566. CreateTime = productNew.CreateTime,
  1567. Id = Guid.NewGuid(),
  1568. OperatorCode = productNew.OperatorCode,
  1569. ProCode = productNew.ProCode,
  1570. SpendTime = productNew.SpendTime,
  1571. ProType = productNew.ProType,
  1572. ProNo = productNew.ProNo
  1573. };
  1574. _repository.Add(product);
  1575. InforNew.Add(productNew);
  1576. inovanceTcp.WriteDate("D1025.1", false);
  1577. }
  1578. public void RecordOneMessage3(object sender, StateEventArgs e)//3
  1579. {
  1580. var spt = inovanceTcp.ReadInt("D1005");
  1581. var d1 = inovanceTcp.ReadInt("D1036");
  1582. var d2 = inovanceTcp.ReadInt("D1037");
  1583. var d3 = inovanceTcp.ReadInt("D1038");
  1584. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1585. var productNew = new InformationNew
  1586. {
  1587. OperatorCode = Operator3,
  1588. ProCode = Material3,
  1589. SpendTime = spt/10,
  1590. CreateTime = DateTime.Now,
  1591. ProType = proName,
  1592. ProNo = pno,
  1593. };
  1594. var product = new Information()
  1595. {
  1596. CreateTime = productNew.CreateTime,
  1597. Id = Guid.NewGuid(),
  1598. OperatorCode = productNew.OperatorCode,
  1599. ProCode = productNew.ProCode,
  1600. SpendTime = productNew.SpendTime,
  1601. ProType = productNew.ProType,
  1602. ProNo=productNew.ProNo
  1603. };
  1604. _repository.Add(product);
  1605. InforNew.Add(productNew);
  1606. inovanceTcp.WriteDate("D1025.2", false);
  1607. }
  1608. public void RecordOneMessage4(object sender, StateEventArgs e)//4
  1609. {
  1610. var spt = inovanceTcp.ReadInt("D1006");
  1611. var d1 = inovanceTcp.ReadInt("D1039");
  1612. var d2 = inovanceTcp.ReadInt("D1040");
  1613. var d3 = inovanceTcp.ReadInt("D1041");
  1614. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1615. var productNew = new InformationNew
  1616. {
  1617. OperatorCode = Operator4,
  1618. ProCode = Material4,
  1619. SpendTime = spt/10,
  1620. CreateTime = DateTime.Now,
  1621. ProType = proName,
  1622. ProNo = pno,
  1623. };
  1624. var product = new Information()
  1625. {
  1626. CreateTime = productNew.CreateTime,
  1627. Id = Guid.NewGuid(),
  1628. OperatorCode = productNew.OperatorCode,
  1629. ProCode = productNew.ProCode,
  1630. SpendTime = productNew.SpendTime,
  1631. ProType = productNew.ProType,
  1632. ProNo = productNew.ProNo
  1633. };
  1634. _repository.Add(product);
  1635. InforNew.Add(productNew);
  1636. inovanceTcp.WriteDate("D1025.3", false);
  1637. }
  1638. public void RecordOneMessage5(object sender, StateEventArgs e)//5
  1639. {
  1640. var spt = inovanceTcp.ReadInt("D1007");
  1641. var d1 = inovanceTcp.ReadInt("D1042");
  1642. var d2 = inovanceTcp.ReadInt("D1043");
  1643. var d3 = inovanceTcp.ReadInt("D1044");
  1644. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1645. var productNew = new InformationNew
  1646. {
  1647. OperatorCode = Operator5,
  1648. ProCode = Material5,
  1649. SpendTime = spt/10,
  1650. CreateTime = DateTime.Now,
  1651. ProType = proName,
  1652. ProNo = pno,
  1653. };
  1654. var product = new Information()
  1655. {
  1656. CreateTime = productNew.CreateTime,
  1657. Id = Guid.NewGuid(),
  1658. OperatorCode = productNew.OperatorCode,
  1659. ProCode = productNew.ProCode,
  1660. SpendTime = productNew.SpendTime,
  1661. ProType = productNew.ProType,
  1662. ProNo = productNew.ProNo
  1663. };
  1664. _repository.Add(product);
  1665. InforNew.Add(productNew);
  1666. inovanceTcp.WriteDate("D1025.4", false);
  1667. }
  1668. public void RecordOneMessage6(object sender, StateEventArgs e)//6
  1669. {
  1670. var spt = inovanceTcp.ReadInt("D1008");
  1671. var d1 = inovanceTcp.ReadInt("D1045");
  1672. var d2 = inovanceTcp.ReadInt("D1046");
  1673. var d3 = inovanceTcp.ReadInt("D1047");
  1674. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1675. var productNew = new InformationNew
  1676. {
  1677. OperatorCode = Operator6,
  1678. ProCode = Material6,
  1679. SpendTime = spt/10,
  1680. CreateTime = DateTime.Now,
  1681. ProType = proName,
  1682. ProNo = pno,
  1683. };
  1684. var product = new Information()
  1685. {
  1686. CreateTime = productNew.CreateTime,
  1687. Id = Guid.NewGuid(),
  1688. OperatorCode = productNew.OperatorCode,
  1689. ProCode = productNew.ProCode,
  1690. SpendTime = productNew.SpendTime,
  1691. ProType = productNew.ProType,
  1692. ProNo=productNew.ProNo
  1693. };
  1694. _repository.Add(product);
  1695. InforNew.Add(productNew);
  1696. inovanceTcp.WriteDate("D1025.5", false);
  1697. }
  1698. public void RecordOneMessage7(object sender, StateEventArgs e)//7
  1699. {
  1700. var spt = inovanceTcp.ReadInt("D1011");
  1701. var d1 = inovanceTcp.ReadInt("D1048");
  1702. var d2 = inovanceTcp.ReadInt("D1049");
  1703. var d3 = inovanceTcp.ReadInt("D1050");
  1704. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1705. var productNew = new InformationNew
  1706. {
  1707. OperatorCode = Operator9,
  1708. ProCode = Material9,
  1709. SpendTime = spt / 10,
  1710. CreateTime = DateTime.Now,
  1711. ProType = proName,
  1712. ProNo = pno,
  1713. };
  1714. var product = new Information()
  1715. {
  1716. CreateTime = productNew.CreateTime,
  1717. Id = Guid.NewGuid(),
  1718. OperatorCode = productNew.OperatorCode,
  1719. ProCode = productNew.ProCode,
  1720. SpendTime = productNew.SpendTime,
  1721. ProType = productNew.ProType,
  1722. ProNo = productNew.ProNo,
  1723. };
  1724. _repository.Add(product);
  1725. InforNew.Add(productNew);
  1726. inovanceTcp.WriteDate("D1025.8", false);
  1727. }
  1728. public void RecordOneMessage8(object sender, StateEventArgs e)//8
  1729. {
  1730. var spt = inovanceTcp.ReadInt("D1012");
  1731. var d1 = inovanceTcp.ReadInt("D1051");
  1732. var d2 = inovanceTcp.ReadInt("D1052");
  1733. var d3 = inovanceTcp.ReadInt("D1053");
  1734. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1735. var productNew = new InformationNew
  1736. {
  1737. OperatorCode = Operator10,
  1738. ProCode = Material10,
  1739. SpendTime = spt/10,
  1740. CreateTime = DateTime.Now,
  1741. ProType = proName,
  1742. ProNo = pno,
  1743. };
  1744. var product = new Information()
  1745. {
  1746. CreateTime = productNew.CreateTime,
  1747. Id = Guid.NewGuid(),
  1748. OperatorCode = productNew.OperatorCode,
  1749. ProCode = productNew.ProCode,
  1750. SpendTime = productNew.SpendTime,
  1751. ProType = productNew.ProType,
  1752. ProNo= productNew.ProNo,
  1753. };
  1754. _repository.Add(product);
  1755. InforNew.Add(productNew);
  1756. inovanceTcp.WriteDate("D1025.9", false);
  1757. }
  1758. public void RecordOneMessage9(object sender, StateEventArgs e)//9
  1759. {
  1760. var spt = inovanceTcp.ReadInt("D1013");
  1761. var d1 = inovanceTcp.ReadInt("D1054");
  1762. var d2 = inovanceTcp.ReadInt("D1055");
  1763. var d3 = inovanceTcp.ReadInt("D1056");
  1764. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1765. var productNew = new InformationNew
  1766. {
  1767. OperatorCode = Operator11,
  1768. ProCode = Material11,
  1769. SpendTime = spt/10,
  1770. CreateTime = DateTime.Now,
  1771. ProType = proName,
  1772. ProNo = pno,
  1773. };
  1774. var product = new Information()
  1775. {
  1776. CreateTime = productNew.CreateTime,
  1777. Id = Guid.NewGuid(),
  1778. OperatorCode = productNew.OperatorCode,
  1779. ProCode = productNew.ProCode,
  1780. SpendTime = productNew.SpendTime,
  1781. ProType = productNew.ProType,
  1782. ProNo= productNew.ProNo,
  1783. };
  1784. _repository.Add(product);
  1785. InforNew.Add(productNew);
  1786. inovanceTcp.WriteDate("D1025.10", false);
  1787. }
  1788. public void RecordOneMessage10(object sender, StateEventArgs e)//10
  1789. {
  1790. var spt = inovanceTcp.ReadInt("D1014");
  1791. var d1 = inovanceTcp.ReadInt("D1057");
  1792. var d2 = inovanceTcp.ReadInt("D1058");
  1793. var d3 = inovanceTcp.ReadInt("D1059");
  1794. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1795. var productNew = new InformationNew
  1796. {
  1797. OperatorCode = Operator12,
  1798. ProCode = Material12,
  1799. SpendTime = spt/10,
  1800. CreateTime = DateTime.Now,
  1801. ProType = proName,
  1802. ProNo = pno,
  1803. };
  1804. var product = new Information()
  1805. {
  1806. CreateTime = productNew.CreateTime,
  1807. Id = Guid.NewGuid(),
  1808. OperatorCode = productNew.OperatorCode,
  1809. ProCode = productNew.ProCode,
  1810. SpendTime = productNew.SpendTime,
  1811. ProType = productNew.ProType,
  1812. ProNo= productNew.ProNo,
  1813. };
  1814. _repository.Add(product);
  1815. InforNew.Add(productNew);
  1816. inovanceTcp.WriteDate("D1025.11", false);
  1817. }
  1818. public void RecordOneMessage11(object sender, StateEventArgs e)//11
  1819. {
  1820. var spt = inovanceTcp.ReadInt("D1017");
  1821. var d1 = inovanceTcp.ReadInt("D1060");
  1822. var d2 = inovanceTcp.ReadInt("D1061");
  1823. var d3 = inovanceTcp.ReadInt("D1062");
  1824. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1825. var productNew = new InformationNew
  1826. {
  1827. OperatorCode = Operator15,
  1828. ProCode = Material15,
  1829. SpendTime = spt/10,
  1830. CreateTime = DateTime.Now,
  1831. ProType = proName,
  1832. ProNo = pno,
  1833. };
  1834. var product = new Information()
  1835. {
  1836. CreateTime = productNew.CreateTime,
  1837. Id = Guid.NewGuid(),
  1838. OperatorCode = productNew.OperatorCode,
  1839. ProCode = productNew.ProCode,
  1840. SpendTime = productNew.SpendTime,
  1841. ProType = productNew.ProType,
  1842. ProNo= productNew.ProNo,
  1843. };
  1844. _repository.Add(product);
  1845. InforNew.Add(productNew);
  1846. inovanceTcp.WriteDate("D1025.14", false);
  1847. }
  1848. public void RecordOneMessage12(object sender, StateEventArgs e)//12
  1849. {
  1850. var spt = inovanceTcp.ReadInt("D1018");
  1851. var d1 = inovanceTcp.ReadInt("D1063");
  1852. var d2 = inovanceTcp.ReadInt("D1064");
  1853. var d3 = inovanceTcp.ReadInt("D1065");
  1854. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1855. var productNew = new InformationNew
  1856. {
  1857. OperatorCode = Operator16,
  1858. ProCode = Material16,
  1859. SpendTime = spt/10,
  1860. CreateTime = DateTime.Now,
  1861. ProType = proName,
  1862. ProNo = pno,
  1863. };
  1864. var product = new Information()
  1865. {
  1866. CreateTime = productNew.CreateTime,
  1867. Id = Guid.NewGuid(),
  1868. OperatorCode = productNew.OperatorCode,
  1869. ProCode = productNew.ProCode,
  1870. SpendTime = productNew.SpendTime,
  1871. ProType = productNew.ProType,
  1872. ProNo = productNew.ProNo,
  1873. };
  1874. _repository.Add(product);
  1875. InforNew.Add(productNew);
  1876. inovanceTcp.WriteDate("D1025.15", false);
  1877. }
  1878. public void RecordOneMessage13(object sender, StateEventArgs e)//13
  1879. {
  1880. var spt = inovanceTcp.ReadInt("D1019");
  1881. var d1 = inovanceTcp.ReadInt("D1066");
  1882. var d2 = inovanceTcp.ReadInt("D1067");
  1883. var d3 = inovanceTcp.ReadInt("D1068");
  1884. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1885. var productNew = new InformationNew
  1886. {
  1887. OperatorCode = Operator17,
  1888. ProCode = Material17,
  1889. SpendTime = spt/10,
  1890. CreateTime = DateTime.Now,
  1891. ProType = proName,
  1892. ProNo = pno,
  1893. };
  1894. var product = new Information()
  1895. {
  1896. CreateTime = productNew.CreateTime,
  1897. Id = Guid.NewGuid(),
  1898. OperatorCode = productNew.OperatorCode,
  1899. ProCode = productNew.ProCode,
  1900. SpendTime = productNew.SpendTime,
  1901. ProType = productNew.ProType,
  1902. ProNo = productNew.ProNo,
  1903. };
  1904. _repository.Add(product);
  1905. InforNew.Add(productNew);
  1906. inovanceTcp.WriteDate("D1026.0", false);
  1907. }
  1908. public void RecordOneMessage14(object sender, StateEventArgs e)//14
  1909. {
  1910. var spt = inovanceTcp.ReadInt("D1020");
  1911. var d1 = inovanceTcp.ReadInt("D1069");
  1912. var d2 = inovanceTcp.ReadInt("D1070");
  1913. var d3 = inovanceTcp.ReadInt("D1071");
  1914. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1915. var productNew = new InformationNew
  1916. {
  1917. OperatorCode = Operator18,
  1918. ProCode = Material18,
  1919. SpendTime = spt/10,
  1920. CreateTime = DateTime.Now,
  1921. ProType = proName,
  1922. ProNo = pno,
  1923. };
  1924. var product = new Information()
  1925. {
  1926. CreateTime = productNew.CreateTime,
  1927. Id = Guid.NewGuid(),
  1928. OperatorCode = productNew.OperatorCode,
  1929. ProCode = productNew.ProCode,
  1930. SpendTime = productNew.SpendTime,
  1931. ProType = productNew.ProType,
  1932. ProNo = productNew.ProNo,
  1933. };
  1934. _repository.Add(product);
  1935. InforNew.Add(productNew);
  1936. inovanceTcp.WriteDate("D1026.1", false);
  1937. }
  1938. #endregion
  1939. public void Quest(string str)
  1940. {
  1941. _eventAggregator.GetEvent<QuestEvent>().Publish(str);
  1942. }
  1943. public void Alarm(Dictionary<string, string> plcsignal)
  1944. {
  1945. _eventAggregator.GetEvent<AlarmEvent>().Publish(plcsignal);//跨viewmodel发信息,Publish(发送的消息)
  1946. }
  1947. bool mybool = false;
  1948. bool one = true;
  1949. string proName;
  1950. private void Timer_Elapsed()
  1951. {
  1952. while (true)
  1953. {
  1954. if (!Connected)
  1955. {
  1956. if (one)
  1957. {
  1958. WriteLog("plc连接异常", LogType.Error);
  1959. one = false;
  1960. }
  1961. continue;
  1962. }
  1963. try
  1964. {
  1965. if (one)
  1966. {
  1967. WriteLog("plc连接成功", LogType.Info);
  1968. one = false;
  1969. }
  1970. if (!mybool)
  1971. {
  1972. inovanceTcp.WriteDate("D1500", 0);
  1973. mybool = true;
  1974. }
  1975. else
  1976. {
  1977. inovanceTcp.WriteDate("D1500", 1);
  1978. mybool = false;
  1979. }
  1980. foreach (var item in SignalMapper)
  1981. {
  1982. //if (e.StartingAddress+e.Points.Length < item.Value)
  1983. //{
  1984. // continue;
  1985. //}
  1986. //var data = e.Points[item.Value];
  1987. //var value = inovanceTcp.Read(item.Value, 1);
  1988. var value=inovanceTcp.ReadBool(item.Value);
  1989. _stateService.ExecuteState(item.Key, value ? (ushort)1 : (ushort)0);
  1990. }
  1991. }
  1992. catch (ObjectDisposedException ex)
  1993. {
  1994. _logger.Information(ex.ToString());
  1995. }
  1996. finally
  1997. {
  1998. Thread.Sleep(1000);
  1999. }
  2000. }
  2001. }
  2002. int a=0;
  2003. private void Timer_Elapsed2()
  2004. {
  2005. while (true)
  2006. {
  2007. if (!Connected)
  2008. {
  2009. continue;
  2010. }
  2011. try
  2012. {
  2013. ReadOrder();
  2014. //切换产品
  2015. int type = inovanceTcp.ReadInt("D1000");
  2016. if (a !=type)
  2017. {
  2018. Change();
  2019. }
  2020. a = type;
  2021. #region 报警
  2022. var dictionary = new Dictionary<string, string>();
  2023. for (int i = 0; i < 31; i++)
  2024. {
  2025. var adrress = "D" + (1100 + i).ToString();
  2026. int ad = inovanceTcp.ReadInt(adrress);
  2027. if (ad != 0)
  2028. {
  2029. dictionary.Add(adrress, "报警");
  2030. }
  2031. else
  2032. {
  2033. dictionary.Add(adrress, "正常");
  2034. }
  2035. }
  2036. for (int i = 0; i < 25; i++)
  2037. {
  2038. var adrress = "D" + (1141.15 + i).ToString();
  2039. if (inovanceTcp.ReadBool(adrress))
  2040. {
  2041. dictionary.Add(adrress, "缺料");
  2042. }
  2043. else
  2044. {
  2045. dictionary.Add(adrress, "正常");
  2046. }
  2047. }
  2048. for (int i = 0; i < 7; i++)
  2049. {
  2050. var adrress = "D" + (1166 + (double)i / 10).ToString("0.0");
  2051. if (inovanceTcp.ReadBool(adrress))
  2052. {
  2053. dictionary.Add(adrress, "缺料");
  2054. }
  2055. else
  2056. {
  2057. dictionary.Add(adrress, "正常");
  2058. }
  2059. }
  2060. Alarm(dictionary);
  2061. #endregion
  2062. }
  2063. catch (ObjectDisposedException ex)
  2064. {
  2065. _logger.Information(ex.ToString());
  2066. }
  2067. finally
  2068. {
  2069. Thread.Sleep(1000);
  2070. }
  2071. }
  2072. }
  2073. public void Change()
  2074. {
  2075. int type = inovanceTcp.ReadInt("D1000");
  2076. switch (type)
  2077. {
  2078. case 0:
  2079. break;
  2080. case 1:
  2081. proName = "P60";
  2082. break;
  2083. case 2:
  2084. proName = "P70";
  2085. break;
  2086. case 3:
  2087. proName = "P80";
  2088. break;
  2089. case 4:
  2090. proName = "P90";
  2091. break;
  2092. }
  2093. if (inovanceTcp.ReadBool("D1001.0"))
  2094. {
  2095. SendPro("192.168.10.1", proName);
  2096. }
  2097. if (inovanceTcp.ReadBool("D1001.1"))
  2098. {
  2099. SendPro("192.168.10.2", proName);
  2100. }
  2101. if (inovanceTcp.ReadBool("D1001.2"))
  2102. {
  2103. SendPro("192.168.10.3", proName);
  2104. }
  2105. if (inovanceTcp.ReadBool("D1001.3"))
  2106. {
  2107. SendPro("192.168.10.4", proName);
  2108. }
  2109. if (inovanceTcp.ReadBool("D1001.4"))
  2110. {
  2111. SendPro("192.168.10.5", proName);
  2112. }
  2113. if (inovanceTcp.ReadBool("D1001.5"))
  2114. {
  2115. SendPro("192.168.10.6", proName);
  2116. }
  2117. if (inovanceTcp.ReadBool("D1001.6"))
  2118. {
  2119. SendPro("192.168.10.7", proName);
  2120. }
  2121. if (inovanceTcp.ReadBool("D1001.7"))
  2122. {
  2123. SendPro("192.168.10.8", proName);
  2124. }
  2125. if (inovanceTcp.ReadBool("D1001.8"))
  2126. {
  2127. SendPro("192.168.10.9", proName);
  2128. }
  2129. if (inovanceTcp.ReadBool("D1001.9"))
  2130. {
  2131. SendPro("192.168.10.10", proName);
  2132. }
  2133. if (inovanceTcp.ReadBool("D1001.10"))
  2134. {
  2135. SendPro("192.168.10.11", proName);
  2136. }
  2137. if (inovanceTcp.ReadBool("D1001.11"))
  2138. {
  2139. SendPro("192.168.10.12", proName);
  2140. }
  2141. if (inovanceTcp.ReadBool("D1001.12"))
  2142. {
  2143. SendPro("192.168.10.13", proName);
  2144. }
  2145. if (inovanceTcp.ReadBool("D1001.13"))
  2146. {
  2147. SendPro("192.168.10.14", proName);
  2148. }
  2149. if (inovanceTcp.ReadBool("D1001.14"))
  2150. {
  2151. SendPro("192.168.10.15", proName);
  2152. }
  2153. if (inovanceTcp.ReadBool("D1001.15"))
  2154. {
  2155. SendPro("192.168.10.16", proName);
  2156. }
  2157. if (inovanceTcp.ReadBool("D1002.0"))
  2158. {
  2159. SendPro("192.168.10.17", proName);
  2160. }
  2161. if (inovanceTcp.ReadBool("D1002.1"))
  2162. {
  2163. SendPro("192.168.10.18", proName);
  2164. }
  2165. }
  2166. public string SelectedConfigName { get; set; }
  2167. public ObservableCollection<string> ConfigNames { get; set; }
  2168. public WriteableBitmap QrImage { get; set; }
  2169. public void ReadConfig()
  2170. {
  2171. ConfigNames = new ObservableCollection<string>();
  2172. if (!Directory.Exists(@"d:\作业指导书\"))
  2173. {
  2174. return;
  2175. }
  2176. var files = Directory.GetFiles(@"d:\作业指导书\");
  2177. foreach (var item in files)
  2178. {
  2179. var file = new FileInfo(item);
  2180. if (file.Extension == ".json")
  2181. {
  2182. ConfigNames.Add(file.Name.Replace(file.Extension, ""));
  2183. }
  2184. }
  2185. }
  2186. #region old
  2187. private void StopCheck(object sender, StateEventArgs e)
  2188. {
  2189. var modbus = _modbusTcpSlaverService.GetModbusSlaveByIp();
  2190. //var points = modbus.DataStore.HoldingRegisters.ReadPoints(200, 1);
  2191. Application.Current.Dispatcher.Invoke(new Action(() =>
  2192. {
  2193. var (errorCode, error) = _warningUpdateService.GetErrorCode(1);
  2194. //Dialog.Show(new OeeDialogPage(), "");
  2195. // var DialogResult = await Dialog.Show<OeeDialogPage>()
  2196. //.Initialize<OeeDialogPageViewModel>(vm => vm.Message = "DialogResult")
  2197. //.GetResultAsync<string>();
  2198. var param = new DialogParameters
  2199. {
  2200. { "OP_Id", Param.OPID },
  2201. {"ExceptionCode", errorCode}
  2202. };
  2203. modbus.DataStore.CoilInputs.WritePoints(12, new bool[] { true });
  2204. _dialogService.ShowDialog("OeeDialogPage", param, async r =>
  2205. {
  2206. //dialog.Parameters.Add("OP_Id", OP_Id);
  2207. //dialog.Parameters.Add("ExceptionCode", ExceptionCode);
  2208. //dialog.Parameters.Add("ExceptionContent", ExceptionContent);
  2209. //dialog.Parameters.Add("Duration", Duration);
  2210. //dialog.Parameters.Add("ExceptionTime", ExceptionTime.ToString("yyyy-mm-dd HH:mm:ss"));
  2211. //dialog.Parameters.Add("Mode", "手动调试模式");
  2212. //dialog.Parameters.Add("Reason", ExceptionReason);
  2213. var param = r.Parameters;
  2214. var opid = param.GetValue<string>("OP_Id");
  2215. var exceptionCodeMessage = param.GetValue<string>("ExceptionCode");
  2216. var exceptionCode = exceptionCodeMessage.Split('-')[0];
  2217. var exceptionContent = param.GetValue<string>("ExceptionContent");
  2218. var duration = param.GetValue<int>("Duration");
  2219. var exceptionTime = param.GetValue<string>("ExceptionTime");
  2220. var mode = param.GetValue<string>("Mode");
  2221. var reason = param.GetValue<string>("Reason");
  2222. var oeeLogger = new OeeLogger
  2223. {
  2224. site = OeeConfig.Site,
  2225. floor = OeeConfig.Floor,
  2226. product = OeeConfig.Product,
  2227. line = OeeConfig.Line,
  2228. vendor = "Team",
  2229. process = OeeConfig.Process,
  2230. terminalId = OeeConfig.TerminalId,
  2231. machineId = OeeConfig.MachineId,
  2232. status = mode,
  2233. op_id = opid,
  2234. startTime = exceptionTime,
  2235. ipaddr = OeeConfig.Ipaddr,
  2236. macaddr = OeeConfig.Macaddr,
  2237. warningCodeList = new Warningcodelist[2]
  2238. };
  2239. oeeLogger.warningCodeList[0] = new Warningcodelist
  2240. {
  2241. warningCode = "400002",
  2242. remark = exceptionContent
  2243. };
  2244. oeeLogger.warningCodeList[1] = new Warningcodelist
  2245. {
  2246. warningCode = exceptionCode,
  2247. remark = reason
  2248. };
  2249. await UploadOeeAsync(oeeLogger);
  2250. modbus.DataStore.CoilInputs.WritePoints(12, new bool[] { false });
  2251. });
  2252. }));
  2253. }
  2254. private async void ResettableTimer_Elapsed(object sender, ElapsedEventArgs e)
  2255. {
  2256. OeeLogger oeeLogger = new()
  2257. {
  2258. site = OeeConfig.Site,
  2259. floor = OeeConfig.Floor,
  2260. product = OeeConfig.Product,
  2261. line = OeeConfig.Line,
  2262. vendor = "Team",
  2263. process = OeeConfig.Process,
  2264. terminalId = OeeConfig.TerminalId,
  2265. machineId = OeeConfig.MachineId,
  2266. status = "Waiting for parts",
  2267. op_id = Param.OPID,
  2268. startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  2269. ipaddr = OeeConfig.Ipaddr,
  2270. macaddr = OeeConfig.Macaddr,
  2271. warningCodeList = new Warningcodelist[1]
  2272. };
  2273. oeeLogger.warningCodeList[0] = new Warningcodelist
  2274. {
  2275. warningCode = "100002",
  2276. remark = "待料"
  2277. };
  2278. await UploadOeeAsync(oeeLogger);
  2279. }
  2280. private void WaringUpdateLogChanged(Tuple<LogType, string> tuple)
  2281. {
  2282. Debug.WriteLine(tuple.Item2);
  2283. HandyControl.Controls.MessageBox.Show("test");
  2284. }
  2285. private void OeeConfigChanged(OeeConfig config)
  2286. {
  2287. OeeConfig ??= new OeeConfig();
  2288. OeeConfig.Ip = config.Ip;
  2289. OeeConfig.Port = config.Port;
  2290. OeeConfig.WaitPartDuration = config.WaitPartDuration;
  2291. OeeConfig.StopDuration = config.StopDuration;
  2292. OeeConfig.Site = config.Site;
  2293. OeeConfig.Floor = config.Floor;
  2294. OeeConfig.Product = config.Product;
  2295. OeeConfig.Line = config.Line;
  2296. OeeConfig.Process = config.Process;
  2297. OeeConfig.Vendor = config.Vendor;
  2298. OeeConfig.TerminalId = config.TerminalId;
  2299. OeeConfig.MachineId = config.MachineId;
  2300. OeeConfig.Op_id = config.Op_id;
  2301. OeeConfig.Ipaddr = config.Ipaddr;
  2302. OeeConfig.Macaddr = config.Macaddr;
  2303. OeeConfig.OeePath = config.OeePath;
  2304. OeeConfig.UnUse = config.UnUse;
  2305. }
  2306. private async Task UploadOeeAsync(OeeLogger oeeLogger)
  2307. {
  2308. if (OeeConfig == null)
  2309. {
  2310. WriteLog("oee配置文件不存在请重新配置", LogType.Error);
  2311. return;
  2312. }
  2313. using var client = _httpClientFactory.CreateClient();
  2314. //var url = _appSttings.Value.OeeUrl;
  2315. var loggingURI = $"http://{OeeConfig.Ip}:{OeeConfig.Port}/device/upload/logging/v1";
  2316. try
  2317. {
  2318. var json = JsonConvert.SerializeObject(oeeLogger, Formatting.Indented);
  2319. WriteToLocal(json);
  2320. if (!OeeConfig.UnUse)
  2321. {
  2322. client.BaseAddress = new Uri(loggingURI);
  2323. var content = new StringContent(json, Encoding.UTF8, "application/json");
  2324. var response = await client.PostAsync(loggingURI, content);
  2325. WriteLog("oee上传成功");
  2326. var s = await response.Content.ReadAsStringAsync();
  2327. WriteLog($"状态码:{response.StatusCode}:" + s, LogType.Info);
  2328. }
  2329. else
  2330. {
  2331. WriteLog("oee上传屏蔽,未上传");
  2332. }
  2333. }
  2334. catch (Exception e)
  2335. {
  2336. WriteLog($"oee上传失败,{e.Message}", LogType.Error);
  2337. }
  2338. }
  2339. private void WriteToLocal(string json)
  2340. {
  2341. var name = DateTime.Now.ToString("yyyy-mm-dd-HH-mm-ss") + "_oee" + ".json";
  2342. var path = Path.Combine(OeeConfig.OeePath, name);
  2343. if (!Directory.Exists(OeeConfig.OeePath))
  2344. {
  2345. WriteLog("oee路径不存在", LogType.Error);
  2346. return;
  2347. }
  2348. using var stream = new StreamWriter(path);
  2349. stream.Write(json);
  2350. }
  2351. private void ClearQueue(object sender, StateEventArgs e)
  2352. {
  2353. var length = _upLoadTraceModels.Count;
  2354. for (int i = 0; i < length; i++)
  2355. {
  2356. _upLoadTraceModels.TryDequeue(out _);
  2357. }
  2358. }
  2359. private void InitTraceData()
  2360. {
  2361. var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "param.json");
  2362. if (File.Exists(filePath))
  2363. {
  2364. using var stream = new StreamReader(filePath);
  2365. var json = stream.ReadToEnd();
  2366. Param = JsonConvert.DeserializeObject<Param>(json);
  2367. }
  2368. else
  2369. {
  2370. Param = new Param
  2371. {
  2372. station_id = "LkYC_BO7_2F_01_002_TRACE",
  2373. line_id = "B07-2F-01",
  2374. station_vendor = "Team",
  2375. test = "Logo 30N Non-Destructive Test",
  2376. OPID = "C10088888",
  2377. DownLimit = "30",
  2378. UpperLimit = "60"
  2379. };
  2380. }
  2381. }
  2382. private void ScanMethodComplete(object sender, StateEventArgs e)
  2383. {
  2384. //var modbus = _modbusTcpSlaverService.GetModbusSlaveByIp();
  2385. //modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { false });
  2386. //WriteLog("复位扫码OK信号");
  2387. }
  2388. private void SaveDataCompleted(object sender, StateEventArgs e)
  2389. {
  2390. var modbus = _modbusTcpSlaverService.GetModbusSlaveByIp();
  2391. modbus.DataStore.CoilInputs.WritePoints(10, new bool[] { false });
  2392. modbus.DataStore.CoilInputs.WritePoints(11, new bool[] { false });
  2393. }
  2394. private void SaveImage(string barcode, string result)
  2395. {
  2396. var filePath = string.Empty;
  2397. var fileName = barcode + "-" + Guid.NewGuid().ToString("N") + $"-{result}" + ".png";
  2398. string directory = ImagePath;
  2399. Application.Current.Dispatcher.Invoke(new Action(() =>
  2400. {
  2401. try
  2402. {
  2403. var finalPath = Path.Combine(directory, result);
  2404. if (!Directory.Exists(finalPath))
  2405. {
  2406. Directory.CreateDirectory(finalPath);
  2407. }
  2408. filePath = Path.Combine(finalPath, fileName);
  2409. (PlotModel.PlotView as OxyPlot.Wpf.PlotView)?.SaveBitmap(filePath);
  2410. }
  2411. catch (Exception e)
  2412. {
  2413. WriteLog($"保存图片出现异常:{e.Message}");
  2414. }
  2415. }));
  2416. }
  2417. public float ReadFloat(ushort startId)
  2418. {
  2419. var modbus = _modbusTcpSlaverService.GetModbusSlaveByIp();
  2420. var data = modbus.DataStore
  2421. .HoldingRegisters.ReadPoints((ushort)(32 + startId), 2);
  2422. var bytes1 = BitConverter.GetBytes(data[0]);
  2423. var bytes2 = BitConverter.GetBytes(data[1]);
  2424. var bytes = new List<byte>();
  2425. bytes.AddRange(bytes1);
  2426. bytes.AddRange(bytes2);
  2427. var value = BitConverter.ToSingle(bytes.ToArray(), 0);
  2428. return value;
  2429. }
  2430. private async void ScanMethod(object sender, StateEventArgs e)
  2431. {
  2432. ErrorCode = string.Empty;
  2433. var modbus = _modbusTcpSlaverService.GetModbusSlaveByIp();
  2434. if (!ScanConnected)
  2435. {
  2436. WriteLog($"扫码枪未连接,无法执行扫码动作");
  2437. ErrorCode = "扫码枪未连接,无法执行扫码动作";
  2438. modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { false });
  2439. return;
  2440. }
  2441. for (int i = 0; i < 3; i++)
  2442. {
  2443. try
  2444. {
  2445. WriteLog($"开始第{i + 1}次扫码");
  2446. NewBarcode = await _scanService.ReadAsync("start");
  2447. WriteLog($"第{i + 1}次扫码结果:{NewBarcode}");
  2448. if (NewBarcode != string.Empty && (NewBarcode.ToUpper()) != "NOREAD")
  2449. {
  2450. break;
  2451. }
  2452. }
  2453. catch (Exception ex)
  2454. {
  2455. modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { false });
  2456. WriteLog($"扫码出现异常:{ex.Message}", LogType.Error, ex);
  2457. ErrorCode = "扫码出现异常";
  2458. }
  2459. }
  2460. if (NewBarcode != string.Empty && NewBarcode.ToUpper() != "NOREAD")
  2461. {
  2462. // modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { true });
  2463. WriteLog($"扫码成功,SN:{NewBarcode}");
  2464. if (!_appSttings.Value.TraceDisable)
  2465. {
  2466. var result = await GetTraceAsync(NewBarcode);
  2467. if (result)
  2468. {
  2469. modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { true });
  2470. WriteLog($"获取trace成功,SN:{NewBarcode}");
  2471. if (OkDuration <= 1000)
  2472. {
  2473. OkDuration = 4000;
  2474. }
  2475. await Task.Delay(OkDuration);
  2476. modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { false });
  2477. }
  2478. else
  2479. {
  2480. modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { false });
  2481. WriteLog($"trace卡关无法继续 ");
  2482. ErrorCode = "trace卡关校验失败";
  2483. }
  2484. }
  2485. else
  2486. {
  2487. modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { true });
  2488. WriteLog($"卡关屏蔽中,直接放行:SN:{NewBarcode}");
  2489. }
  2490. }
  2491. else
  2492. {
  2493. ErrorCode = $"扫码没有读取正确的二维码";
  2494. modbus.DataStore.CoilInputs.WritePoints(9, new bool[] { false });
  2495. WriteLog($"扫码失败:{NewBarcode}", LogType.Error);
  2496. }
  2497. }
  2498. private async Task Test()
  2499. {
  2500. var updateModel = new UpLoadTraceModel()
  2501. {
  2502. serials = new Serials { part_id = UsingBarcode },
  2503. data = new Data
  2504. {
  2505. insight = new Insight
  2506. {
  2507. test_attributes = new Test_Attributes()
  2508. {
  2509. test_result = "pass",
  2510. uut_start = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  2511. },
  2512. test_station_attributes = new Test_Station_Attributes()
  2513. {
  2514. line_id = Param.line_id,
  2515. software_name = "ForceTest",
  2516. software_version = "1.0.12",
  2517. station_id = Param.station_id
  2518. },
  2519. uut_attributes = new Uut_Attributes()
  2520. {
  2521. station_vendor = Param.station_vendor
  2522. },
  2523. results = new Result[1]
  2524. {
  2525. new() {
  2526. test=Param.test,
  2527. units="N"
  2528. }
  2529. }
  2530. }
  2531. }
  2532. };
  2533. var dateName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
  2534. var fileName = dateName + "-" + updateModel.serials.part_id + ".csv";
  2535. var filePath = Path.Combine(CSVPath, fileName);
  2536. var exsit = File.Exists(filePath);
  2537. using var streamWriter = new StreamWriter(filePath, false, Encoding.UTF8);
  2538. if (!exsit)
  2539. {
  2540. var header = "SERIAL_NUMBER,MEASURE_DATE,MEASURE_TIME,STATION,OP_NAME,AIM_VENDOR,AIM_NAME,AIM_UNIQUE," +
  2541. "INSPECTION_PROGRAM_NAME,PROJECT,PART,PROCESS,BUILDS,SHIFT_D_N,CAVITY,RESULT,BIN_MP,COLOR,TEMPERATURE," +
  2542. "HUMIDITY,PRODUCT_TEMP,COLOR_BANKING,KB_LAYOUT,DATA_BIN," +
  2543. "DATA1,DATA2,DATA3,DATA4,DATA5,DATA6,DATA7,DATA8,DATA9,DATA10,DATA11,DATA12,DATA13," +
  2544. "DATA14,DATA15,DATA16,DATA17,DATA18,DATA19,DATA20,DATA21,DATA22,DATA23,DATA24,DATA25,DATA26," +
  2545. "DATA27,DATA28,DATA29,DATA30,DATA31,DATA32,DATA33,DATA34,DATA35,DATA36,DATA37,DATA38,DATA39," +
  2546. "DATA40,DATA41,DATA42,DATA43,DATA44,DATA45,DATA46,DATA47,DATA48,DATA49,DATA50,DATA51,DATA52," +
  2547. "DATA53,DATA54,DATA55,DATA56,DATA57,DATA58,DATA59,DATA60,DATA61,DATA62,DATA63,DATA64,DATA65," +
  2548. "DATA66,DATA67,DATA68,DATA69,DATA70,DATA71,DATA72,DATA73,DATA74,DATA75," +
  2549. "DATA76,DATA77,DATA78,DATA79,DATA80,DATA81,DATA82,DATA83,DATA84,DATA85,DATA86,DATA87,DATA88," +
  2550. "DATA89,DATA90,DATA91,DATA92,DATA93,DATA94,DATA95,DATA96,DATA97,DATA98,DATA99,DATA100";
  2551. await streamWriter.WriteLineAsync(header);
  2552. await streamWriter.FlushAsync();
  2553. }
  2554. var value = $"SPC_G1/{updateModel.data.insight.results[0].value}/H{Param.UpperLimit}/L{Param.DownLimit}";
  2555. var data = $"{updateModel.serials.part_id},{DateTime.Now:yyyy/MM/dd}" + $",{DateTime.Now:HH:mm:ss}" +
  2556. $",logo-test,{Param.OPID},{updateModel.data.insight.uut_attributes.station_vendor}," +
  2557. $"{_appSttings.Value.AimName},{_appSttings.Value.AIM_UNIQUE},{_appSttings.Value.INSPECTION_PROGRAM_NAME}," +
  2558. $"{_appSttings.Value.Project},{_appSttings.Value.Part},{_appSttings.Value.Process},{_appSttings.Value.Builds},,," +
  2559. $"{updateModel.data.insight.test_attributes.test_result},,color,,,,,,,{value}";
  2560. var list = new List<string>();
  2561. for (int i = 0; i < 99; i++)
  2562. {
  2563. data += ",";
  2564. }
  2565. data += "test";
  2566. await streamWriter.WriteLineAsync(data);
  2567. await streamWriter.FlushAsync();
  2568. streamWriter.Close();
  2569. WriteLog("保存csv完成");
  2570. }
  2571. private async Task<bool> GetTraceAsync(string barcode)
  2572. {
  2573. using var client = _httpClientFactory.CreateClient();
  2574. try
  2575. {
  2576. var content = await client.GetStringAsync($"http://localhost:8765/v2/process_control?serial={barcode}&serial_type=part_id");
  2577. var data = JsonConvert.DeserializeObject<Rootobject>(content);
  2578. try
  2579. {
  2580. if (string.IsNullOrWhiteSpace(barcode))
  2581. {
  2582. barcode = Guid.NewGuid().ToString("N");
  2583. }
  2584. var fileName = "request_" + barcode + ".json";
  2585. var path = Path.Combine("logs", fileName);
  2586. using var stream = new StreamWriter(path);
  2587. await stream.WriteLineAsync(content);
  2588. _logger.Information(content);
  2589. }
  2590. catch (Exception)
  2591. {
  2592. }
  2593. if (!data.pass)
  2594. {
  2595. foreach (var item in data.processes)
  2596. {
  2597. if (!item.pass)
  2598. {
  2599. WriteLog($"{item.id}:{item.name}卡关fail!", LogType.Error);
  2600. }
  2601. }
  2602. }
  2603. return data.pass;
  2604. }
  2605. catch (HttpRequestException e)
  2606. {
  2607. WriteLog($"请求超时失败:{e.Message}", LogType.Error, e);
  2608. return false;
  2609. }
  2610. }
  2611. private async void SaveData(object sender, StateEventArgs e)
  2612. {
  2613. var modbus = _modbusTcpSlaverService.GetModbusSlaveByIp();
  2614. _upLoadTraceModels.TryDequeue(out var _updateModel);
  2615. if (_updateModel == null)
  2616. {
  2617. WriteLog("_updateModel not init");
  2618. modbus.DataStore.CoilInputs.WritePoints(10, new bool[] { false });
  2619. modbus.DataStore.CoilInputs.WritePoints(11, new bool[] { true });
  2620. return;
  2621. }
  2622. var productTestForce = ReadFloat(74);//test
  2623. WriteLog($"读取当前压检值:{productTestForce}");
  2624. modbus.DataStore.CoilInputs.WritePoints(10, new bool[] { false });
  2625. modbus.DataStore.CoilInputs.WritePoints(11, new bool[] { false });
  2626. var plcResult = modbus.DataStore.HoldingRegisters.ReadPoints(32, 1);
  2627. var juge = plcResult[0] == 1 ? "pass" : "fail";
  2628. _updateModel.data.insight.test_attributes.uut_stop = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2629. _updateModel.data.insight.test_attributes.test_result = juge;
  2630. _updateModel.data.insight.results[0].value = productTestForce.ToString("F2");
  2631. _updateModel.data.insight.results[0].result = juge;
  2632. var runResult = plcResult[0] == 1 ? RunResultState.OK : RunResultState.NG;
  2633. _eventAggregator.GetEvent<ResultEvent>().Publish(runResult);
  2634. WriteLog("开始保存图片");
  2635. SaveImage(_updateModel.serials.part_id, juge);
  2636. WriteLog("保存图片完成");
  2637. await _repository.AddAsync(new TestResult
  2638. {
  2639. Id = Guid.NewGuid(),
  2640. Barcode = _updateModel.serials.part_id,
  2641. Datetime = DateTime.Now,
  2642. Result = productTestForce
  2643. });
  2644. WriteLog("开始保存csv");
  2645. try
  2646. {
  2647. var dateName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
  2648. var fileName = dateName + "-" + _updateModel.serials.part_id + ".csv";
  2649. var filePath = Path.Combine(CSVPath, fileName);
  2650. var exsit = File.Exists(filePath);
  2651. using var streamWriter = new StreamWriter(filePath, false, Encoding.UTF8);
  2652. if (!exsit)
  2653. {
  2654. var header = "SERIAL_NUMBER,MEASURE_DATE,MEASURE_TIME,STATION,OP_NAME,AIM_VENDOR,AIM_NAME,AIM_UNIQUE," +
  2655. "INSPECTION_PROGRAM_NAME,PROJECT,PART,PROCESS,BUILDS,SHIFT_D_N,CAVITY,RESULT,BIN_MP,COLOR,TEMPERATURE," +
  2656. "HUMIDITY,PRODUCT_TEMP,COLOR_BANKING,KB_LAYOUT,DATA_BIN," +
  2657. "DATA1,DATA2,DATA3,DATA4,DATA5,DATA6,DATA7,DATA8,DATA9,DATA10,DATA11,DATA12,DATA13," +
  2658. "DATA14,DATA15,DATA16,DATA17,DATA18,DATA19,DATA20,DATA21,DATA22,DATA23,DATA24,DATA25,DATA26," +
  2659. "DATA27,DATA28,DATA29,DATA30,DATA31,DATA32,DATA33,DATA34,DATA35,DATA36,DATA37,DATA38,DATA39," +
  2660. "DATA40,DATA41,DATA42,DATA43,DATA44,DATA45,DATA46,DATA47,DATA48,DATA49,DATA50,DATA51,DATA52," +
  2661. "DATA53,DATA54,DATA55,DATA56,DATA57,DATA58,DATA59,DATA60,DATA61,DATA62,DATA63,DATA64,DATA65," +
  2662. "DATA66,DATA67,DATA68,DATA69,DATA70,DATA71,DATA72,DATA73,DATA74,DATA75," +
  2663. "DATA76,DATA77,DATA78,DATA79,DATA80,DATA81,DATA82,DATA83,DATA84,DATA85,DATA86,DATA87,DATA88," +
  2664. "DATA89,DATA90,DATA91,DATA92,DATA93,DATA94,DATA95,DATA96,DATA97,DATA98,DATA99,DATA100";
  2665. await streamWriter.WriteLineAsync(header);
  2666. await streamWriter.FlushAsync();
  2667. }
  2668. var value = $"SPC_G1/{_updateModel.data.insight.results[0].value}/H{Param.UpperLimit}/L{Param.DownLimit}";
  2669. var data = $"{_updateModel.serials.part_id},{DateTime.Now:yyyy/MM/dd}" + $",{DateTime.Now:HH:mm:ss}" +
  2670. $",logo-test,{Param.OPID},{_updateModel.data.insight.uut_attributes.station_vendor}," +
  2671. $"{_appSttings.Value.AimName},{_appSttings.Value.AIM_UNIQUE},{_appSttings.Value.INSPECTION_PROGRAM_NAME}," +
  2672. $"{_appSttings.Value.Project},{_appSttings.Value.Part},{_appSttings.Value.Process},{_appSttings.Value.Builds},,," +
  2673. $"{_updateModel.data.insight.test_attributes.test_result},,color,,,,,,,{value}";
  2674. var list = new List<string>();
  2675. for (int i = 0; i < 99; i++)
  2676. {
  2677. data += ",";
  2678. }
  2679. await streamWriter.WriteLineAsync(data);
  2680. await streamWriter.FlushAsync();
  2681. streamWriter.Close();
  2682. WriteLog("保存csv完成");
  2683. }
  2684. catch (Exception ex)
  2685. {
  2686. WriteLog($"保存csv失败:{ex}");
  2687. }
  2688. WriteLog("开始上传数据");
  2689. if (!_appSttings.Value.UnUseUpload)
  2690. {
  2691. var json = JsonConvert.SerializeObject(_updateModel, Formatting.Indented);
  2692. try
  2693. {
  2694. var barcode = _updateModel.serials.part_id;
  2695. if (string.IsNullOrWhiteSpace(barcode))
  2696. {
  2697. barcode = Guid.NewGuid().ToString("N");
  2698. }
  2699. var fileName = "upload_" + barcode + ".json";
  2700. var path = Path.Combine("logs", fileName);
  2701. using var stream = new StreamWriter(path);
  2702. await stream.WriteLineAsync(json);
  2703. }
  2704. catch (Exception)
  2705. {
  2706. }
  2707. _logger.Information("正在上传数据:" + json);
  2708. var stopWatch = new System.Diagnostics.Stopwatch();
  2709. stopWatch.Start();
  2710. var ret = await UploadAsync(json);
  2711. if (stopWatch.ElapsedMilliseconds > 2000)
  2712. {
  2713. _upLoadSlowTime++;
  2714. WriteLog($"连续{_upLoadSlowTime}上传trace数据大于2s", LogType.Warning);
  2715. if (_upLoadSlowTime >= 5)
  2716. {
  2717. ErrorCode = "连续5次上传数据缓慢,请检查网络连接";
  2718. }
  2719. }
  2720. else
  2721. {
  2722. _upLoadSlowTime = 0;
  2723. }
  2724. if (ret)
  2725. {
  2726. modbus.DataStore.CoilInputs.WritePoints(10, new bool[] { true });
  2727. modbus.DataStore.CoilInputs.WritePoints(11, new bool[] { false });
  2728. }
  2729. else
  2730. {
  2731. modbus.DataStore.CoilInputs.WritePoints(10, new bool[] { false });
  2732. modbus.DataStore.CoilInputs.WritePoints(11, new bool[] { true });
  2733. }
  2734. }
  2735. else
  2736. {
  2737. modbus.DataStore.CoilInputs.WritePoints(10, new bool[] { true });
  2738. modbus.DataStore.CoilInputs.WritePoints(11, new bool[] { false });
  2739. }
  2740. OeeLogger oeeLogger = new()
  2741. {
  2742. site = OeeConfig.Site,
  2743. floor = OeeConfig.Floor,
  2744. product = OeeConfig.Product,
  2745. line = OeeConfig.Line,
  2746. vendor = "Team",
  2747. process = OeeConfig.Process,
  2748. terminalId = OeeConfig.TerminalId,
  2749. machineId = OeeConfig.MachineId,
  2750. status = "running",
  2751. op_id = Param.OPID,
  2752. startTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  2753. ipaddr = OeeConfig.Ipaddr,
  2754. macaddr = OeeConfig.Macaddr,
  2755. warningCodeList = new Warningcodelist[1]
  2756. };
  2757. oeeLogger.warningCodeList[0] = new Warningcodelist
  2758. {
  2759. warningCode = "100001",
  2760. remark = "压力检测完成"
  2761. };
  2762. await UploadOeeAsync(oeeLogger);
  2763. WriteLog("上传数据完成");
  2764. }
  2765. //UpLoadTraceModel _updateModel;
  2766. private async Task<bool> UploadAsync(string data)
  2767. {
  2768. using var client = _httpClientFactory.CreateClient();
  2769. var stringContent = new StringContent(data);
  2770. stringContent.Headers.ContentType = new
  2771. System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
  2772. var statisticsLog = new StatisticsLog
  2773. {
  2774. Id = Guid.NewGuid(),
  2775. Timestamp = DateTime.Now,
  2776. RequstType = RequstType.Post
  2777. };
  2778. try
  2779. {
  2780. var responseMessage = await client.PostAsync("http://localhost:8765/v2/logs", stringContent);
  2781. if (responseMessage.StatusCode == System.Net.HttpStatusCode.OK)
  2782. {
  2783. WriteLog($"上传数据成功");
  2784. statisticsLog.TraceState = TraceState.PostOK;
  2785. var s = await responseMessage.Content.ReadAsStringAsync();
  2786. WriteLog($"response:{s}");
  2787. statisticsLog.RequestCode = (int)responseMessage.StatusCode;
  2788. return true;
  2789. }
  2790. else
  2791. {
  2792. statisticsLog.TraceState = TraceState.PostNG;
  2793. WriteLog($"上传失败:状态码{responseMessage.StatusCode}," +
  2794. $"请求uri:{responseMessage.RequestMessage.RequestUri}");
  2795. statisticsLog.RequestCode = (int)responseMessage.StatusCode;
  2796. var s = await responseMessage.Content.ReadAsStringAsync();
  2797. WriteLog($"response:{s}");
  2798. return false;
  2799. }
  2800. }
  2801. catch (HttpRequestException e)
  2802. {
  2803. statisticsLog.TraceState = TraceState.PostNG;
  2804. statisticsLog.RequestCode = 600;
  2805. WriteLog($"上传失败:{e.Message}");
  2806. return false;
  2807. }
  2808. finally
  2809. {
  2810. await _repository.AddAsync(statisticsLog);
  2811. }
  2812. }
  2813. private async void StartReadForceMethod(object sender, StateEventArgs e)
  2814. {
  2815. WriteLog("开始读取压力传感器数值");
  2816. UsingBarcode = NewBarcode;
  2817. _resettableTimer.Stop();
  2818. var updateModel = new UpLoadTraceModel()
  2819. {
  2820. serials = new Serials { part_id = UsingBarcode },
  2821. data = new Data
  2822. {
  2823. insight = new Insight
  2824. {
  2825. test_attributes = new Test_Attributes()
  2826. {
  2827. test_result = "pass",
  2828. uut_start = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  2829. },
  2830. test_station_attributes = new Test_Station_Attributes()
  2831. {
  2832. line_id = Param.line_id,
  2833. software_name = "ForceTest",
  2834. software_version = "1.0.12",
  2835. station_id = Param.station_id
  2836. },
  2837. uut_attributes = new Uut_Attributes()
  2838. {
  2839. station_vendor = Param.station_vendor
  2840. },
  2841. results = new Result[1]
  2842. {
  2843. new() {
  2844. test=Param.test,
  2845. units="N"
  2846. }
  2847. }
  2848. }
  2849. }
  2850. };
  2851. _upLoadTraceModels.Enqueue(updateModel);
  2852. var modbusSlave = _modbusTcpSlaverService.GetModbusSlaveByIp();
  2853. _start = true;
  2854. //Clear();
  2855. int i = 1;
  2856. var sw = new System.Diagnostics.Stopwatch();
  2857. sw.Start();
  2858. var points = new List<DataPoint>();
  2859. while (true)
  2860. {
  2861. var data = modbusSlave.DataStore.HoldingRegisters.ReadPoints(32 + 68, 2);//读取节拍
  2862. var bytes1 = BitConverter.GetBytes(data[0]);
  2863. var bytes2 = BitConverter.GetBytes(data[1]);
  2864. var bytes = new List<byte>();
  2865. bytes.AddRange(bytes1);
  2866. bytes.AddRange(bytes2);
  2867. var force = BitConverter.ToSingle(bytes.ToArray(), 0);
  2868. var dataPoint = new DataPoint((++i) * 0.005, force);
  2869. points.Add(dataPoint);
  2870. lock (PlotModel.SyncRoot)
  2871. {
  2872. //Update(dataPoint);
  2873. }
  2874. this.PlotModel.InvalidatePlot(true);
  2875. if (!_start)
  2876. {
  2877. break;
  2878. }
  2879. await Task.Delay(5);
  2880. if (sw.ElapsedMilliseconds > 10000)
  2881. {
  2882. break;
  2883. }
  2884. }
  2885. _resettableTimer.Reset();
  2886. }
  2887. private void StopReadForceMethod(object sender, StateEventArgs e)
  2888. {
  2889. WriteLog("停止读取压力传感器数值");
  2890. _start = false;
  2891. }
  2892. private void ModbusTcpSlaverService_CoilDiscretesHandler(object sender, LogoForceTestApp.Services.Interfaces.Events.StorageEventArgs<bool> e)
  2893. {
  2894. }
  2895. //private void SetupModel()
  2896. //{
  2897. // PlotModel = new PlotModel();
  2898. // PlotModel.Axes.Add(new LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, Minimum = 0, Maximum = 80 });
  2899. // PlotModel.Series.Add(new OxyPlot.Series.LineSeries { LineStyle = LineStyle.Solid });
  2900. // RaisePropertyChanged(nameof(PlotModel));
  2901. //}
  2902. //private void Clear()
  2903. //{
  2904. // var s = (OxyPlot.Series.LineSeries)PlotModel.Series[0];
  2905. // s.Points.Clear();
  2906. //}
  2907. //private void Update(DataPoint dataPoint)
  2908. //{
  2909. // var s = (OxyPlot.Series.LineSeries)PlotModel.Series[0];
  2910. // s.Points.Add(dataPoint);
  2911. //}
  2912. #endregion
  2913. #region log
  2914. private void WriteLog(string message, LogType logType = LogType.Info, Exception exception = null)
  2915. {
  2916. if (exception != null)
  2917. {
  2918. _logger.Error("{@Message}", exception.ToString());
  2919. }
  2920. else
  2921. {
  2922. _logger.Information("{@Message}", message);
  2923. }
  2924. string singleLine = message.Trim();
  2925. string item = $"【{DateTime.Now:F}】 {singleLine}";
  2926. _eventAggregator.GetEvent<LogEvent>().Publish(new Tuple<LogType, string>(logType, item));
  2927. }
  2928. #endregion
  2929. #region 生成二维码
  2930. public void QRcode()
  2931. {
  2932. //GenerateQRCode(InQR);
  2933. //GenerateBarCode(InQR, 400, 150).Save("BarCode.png", System.Drawing.Imaging.ImageFormat.Png);
  2934. }
  2935. /// <summary>
  2936. /// 生成二维码图片
  2937. /// </summary>
  2938. public void GenerateQRCode(string qrCodeContent)
  2939. {
  2940. if (qrCodeContent != null)
  2941. {
  2942. using (var generator = new QRCodeGenerator())
  2943. {
  2944. // 创建二维码(并设置纠错能力最高级)
  2945. var createQrCode = generator.CreateQrCode(qrCodeContent, ECCLevel.H);
  2946. var skImageInfo = new SKImageInfo(300, 300);
  2947. // 创建SkiaSharp画布
  2948. using (var surface = SKSurface.Create(skImageInfo))
  2949. {
  2950. var canvas = surface.Canvas;
  2951. // 渲染二维码到画布
  2952. canvas.Render(createQrCode, skImageInfo.Width, skImageInfo.Height);
  2953. using var image = surface.Snapshot();// 获取画布快照
  2954. using var data = image.Encode(SKEncodedImageFormat.Png, 100);// 编码画布快照为PNG格式的数据
  2955. using (var stream = File.OpenWrite(@"MyQRCode.png"))
  2956. {
  2957. data.SaveTo(stream);// 将数据保存到文件流中,生成二维码图片
  2958. }
  2959. QrImage = image.ToWriteableBitmap();
  2960. }
  2961. WriteLog("二维码生成成功");
  2962. }
  2963. }
  2964. }
  2965. /// <summary>
  2966. /// 生成一维条形码
  2967. /// </summary>
  2968. /// <param name="text">内容</param>
  2969. /// <param name="width">宽度</param>
  2970. /// <param name="height">高度</param>
  2971. /// <returns></returns>
  2972. public Bitmap GenerateBarCode(string text, int width, int height)
  2973. {
  2974. BarcodeWriter writer = new BarcodeWriter();
  2975. //使用ITF 格式,不能被现在常用的支付宝、微信扫出来
  2976. //如果想生成可识别的可以使用 CODE_128 格式
  2977. writer.Format = BarcodeFormat.CODE_128;
  2978. EncodingOptions options = new EncodingOptions()
  2979. {
  2980. Width = width,
  2981. Height = height,
  2982. //GS1Format = false,
  2983. //PureBarcode = true,
  2984. Margin = 20
  2985. };
  2986. writer.Options = options;
  2987. BitMatrix bm = writer.Encode(text);
  2988. //Bitmap b = writer.Write(bm);
  2989. Bitmap b = writer.Write(text);
  2990. WriteLog("一维码生成成功");
  2991. return b;
  2992. }
  2993. #endregion
  2994. }
  2995. }