public static void Connect(CancellationToken ct) { if (ControllerNames.LSdebug) { foreach (ControllerListSource cls in IODataCollection.controllerNameList.Where(c => c.name.StartsWith(_name + '-'))) { LSu.Connect(cls.name, int.Parse(cls.IP)); } } else { foreach (ControllerListSource cls in IODataCollection.controllerNameList.Where(c => c.name.StartsWith(_name + '-'))) { try { LSConnect(ct); } catch (Exception e) { throw new Exception(e.Message); } break; } } }
static void LSConnectDetail() { short i = LTDMC.dmc_board_init(); if (i <= 0 || i > 8) { throw new Exception($"雷赛卡初始化错误,返回值:{i}"); } else { ushort _num = 0; ushort[] cardIDs = new ushort[8]; uint[] cardTypes = new uint[8]; short res = LTDMC.dmc_get_CardInfList(ref _num, cardTypes, cardIDs); if (res != 0) { throw new Exception($"雷赛卡无法获取卡信息,错误代码:{res}"); } foreach (ControllerListSource cls in IODataCollection.controllerNameList.Where(c => c.name.StartsWith(_name + '-'))) { string s = string.Join(",", cardIDs).TrimEnd(','); if ((Array.IndexOf(cardIDs, ushort.Parse(cls.IP)) == -1) || ((int.Parse(cls.IP) == 0) && (cardIDs[0] != 0))) { throw new Exception($"雷赛卡卡号不存在:{cls.IP},卡号列表:{s}"); } LSu.Connect(cls.name, int.Parse(cls.IP)); } } }
public static void ForceStopUpdate() { if (LSQueryThread.IsAlive) { LSQueryThread.Abort(); } LSu.CloseComm(); /*if (IODataUpdateThread.IsAlive) * { * IODataUpdateThread.Abort(); * }*/ }
// not in use, use acs's as master // private static void IODataUpdate() // { // while (true) // { // Thread.Sleep(10); // IODataCollection.UpdateDataSetIOFromQueryList(); // IODataCollection.RemoveOldFromChangeDict(); // } // } private static void StopThreadLSQuery() { LSThreadAbort = true; int i = 0; while ((!LSThreadAborted) && (i < 10)) { Thread.Sleep(100); i++; } ; try { LSQueryThread.Abort(); } catch { } LSu.CloseComm(); LSThreadAbort = false; LSThreadAborted = false; }
private static void Update(string cname, List <string> queryList) { while (true) { try { Thread.Sleep(50); List <int> tl = LSu.ReadDevice(cname, queryList); IODataCollection.UpdateIOQueryList(cname, tl); } catch (Exception e) { string queryStr = string.Join(",", queryList); string err = $"{e.Message} {cname}@{queryStr}"; IOInterface.updateError = true; RunningTransaction.Remove(cname); if (RunningTransaction.Count == 0) { LSThreadAborted = true; } IOInterface.ShowError(err); return; } if (LSThreadAbort) { RunningTransaction.Remove(cname); if (RunningTransaction.Count == 0) { LSThreadAborted = true; } return; } } }