public void OcsThreadFunc(object o) { try { OCSStatus lastModel = null; int ID = Convert.ToInt16(o); int[] XmlIndex = getXmlIndex(ID); while (true) { if (IsStart) { OCSStatus thisModel = OCSStatusBLL.GetModel(ID); //OCSStatus thisModel = getOCSStatus(lastModel,(uint)ID); if (thisModel != null) { setCarData(lastModel, thisModel, XmlIndex); lastModel = thisModel; } } Thread.Sleep(sleepTime); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 小车线程处理 /// </summary> /// <param name="o"></param> private void OCSThreadFunc(object o) { try { int index = Convert.ToInt32(o); bool isF = true; while (true) { if (isStart) { //数据库最新数据 OCSStatus model = OCSStatusBLL.GetModel(index); if (isF) { ocsCarPos[index] = 0.01f; isF = false; } else { if (model.position == -1) { //内存数据 //OCSStatus oldModel = ocsModelList.Find(s => s.carId == index); int i = ocsModelList.FindIndex(s => s.carId == index); //初始 if (i == -1) { int count = OCSStatusBLL.getCountByLine(model.line); ocsCarPos[index] = (count - model.sequence) * ocsCarWidth + ocsStartPos; ocsModelList.Add(model); } else { //驱动段改变 if (ocsModelList[i].line != model.line) { if (model.direction == 1) { ocsCarPos[index] = ocsStartPos; } else { ocsCarPos[index] = GetIdex.getOCSPathLength(model.line) - ocsStartPos; } } else { if (model.direction == 1) { ocsCarPos[index] += ocsSpeed; } else if (model.direction == 2) { ocsCarPos[index] -= ocsSpeed; } } ocsModelList[i] = model; } } else { ocsCarPos[index] = float.Parse(model.position.ToString()); } } //设定位置 int index1 = GetIdex.getDicOutputIndex("vehicle" + index.ToString("000") + "01_input_Pos"); ComTCPLib.SetOutputAsREAL32(handle, index1, float.Parse(ocsCarPos[index].ToString())); //设定驱动段 index1 = GetIdex.getDicOutputIndex("vehicle" + index.ToString("000") + "01_input_Path"); ComTCPLib.SetOutputAsINT(handle, index1, int.Parse(model.line.Substring(1))); //设定区域 int tmpArea = 0; if (model.line.Substring(0, 1).ToLower() == "a") { tmpArea = 1; } else if (model.line.Substring(0, 1).ToLower() == "b") { tmpArea = 2; } else if (model.line.Substring(0, 1).ToLower() == "c") { tmpArea = 3; } index1 = GetIdex.getDicOutputIndex("vehicle" + index.ToString("000") + "01_input_Area"); ComTCPLib.SetOutputAsINT(handle, index1, tmpArea); //设定是否显示阀体 index1 = GetIdex.getDicOutputIndex("vehicle" + index.ToString("000") + "01_input_Ftv"); ComTCPLib.SetOutputAsINT(handle, index1, 1); } Thread.Sleep(ocsThreadTime); } } catch (Exception ex) { } }