/// <summary> /// 获得数据列表 /// </summary> public static List <OCSStatus> DataTableToList(DataTable dt) { List <OCSStatus> modelList = new List <OCSStatus>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { OCSStatus model; for (int n = 0; n < rowsCount; n++) { model = new OCSStatus(); if (dt.Rows[n]["id"].ToString() != "") { model.carId = uint.Parse(dt.Rows[n]["id"].ToString()); } model.line = dt.Rows[n]["line"].ToString(); if (dt.Rows[n]["displaystate"].ToString() != "") { model.displayState = uint.Parse(dt.Rows[n]["displaystate"].ToString()); } if (dt.Rows[n]["position"].ToString() != "") { model.position = float.Parse(dt.Rows[n]["position"].ToString()); } modelList.Add(model); } } return(modelList); }
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; } }
private OCSStatus getOCSStatus(OCSStatus lastmodel, uint id) { OCSStatus model = new OCSStatus(); if (lastmodel == null) { model.carId = id; model.line = "B" + path[0]; model.position = 0.01f; model.displayState = 1; return(model); } else { model.carId = id; model.displayState = 1; if (Convert.ToDecimal(lastmodel.position) > pathLength[m]) { m = m + 1; if (m == path.Length) { m = 0; } model.line = "B" + path[m]; model.position = 0.01f; } else { model.line = lastmodel.line; model.position = lastmodel.position + 0.3f; } return(model); } }
private void setCarData(OCSStatus lastData, OCSStatus thisData, int[] xmlIndex) { int CarXmlIndex_OcsArea = xmlIndex[0]; int CarXmlIndex_OcsPath = xmlIndex[1]; int CarXmlIndex_OcsPos = xmlIndex[2]; int CarXmlIndex_OcsFtv = xmlIndex[3]; if (lastData == null) { //设定区域 001 int tmpArea = getOcsArea(thisData.line); if (tmpArea != -1) { ComTCPLib.SetOutputAsUINT(handle, CarXmlIndex_OcsArea, (UInt32)tmpArea); } //设定驱动段 002 ComTCPLib.SetOutputAsUINT(handle, CarXmlIndex_OcsPath, UInt32.Parse(thisData.line.Substring(1))); //设定位置 003 ComTCPLib.SetOutputAsREAL32(handle, CarXmlIndex_OcsPos, thisData.position); //设定是否显示阀体 ComTCPLib.SetOutputAsUINT(handle, CarXmlIndex_OcsFtv, thisData.displayState); } else if (!thisData.Equals(lastData)) { if (!thisData.line.Equals(lastData.line)) { int tmpArea = getOcsArea(thisData.line); if (tmpArea != -1) { ComTCPLib.SetOutputAsUINT(handle, CarXmlIndex_OcsArea, (UInt32)tmpArea); } ComTCPLib.SetOutputAsUINT(handle, CarXmlIndex_OcsPath, UInt32.Parse(thisData.line.Substring(1))); } if (thisData.position != lastData.position) { ComTCPLib.SetOutputAsREAL32(handle, CarXmlIndex_OcsPos, thisData.position); } if (thisData.displayState != lastData.displayState) { ComTCPLib.SetOutputAsUINT(handle, CarXmlIndex_OcsFtv, thisData.displayState); } } //double time, timeStep; //ComTCPLib.UpdateData(handle, out time, out timeStep); }
/// <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) { } }