예제 #1
0
        //---------------------------------------------------
        #region 基本数据处理
        //type 1 uint,2 float,3 flag
        //设置数据
        public void updateValue(string name, string value, int type, int handle)
        {
            //double time, timeStep;
            //ComTCPLib.UpdateData(handle, out time, out timeStep);
            int index = GetIdex.getDicOutputIndex(name);

            if (type == 1)
            {
                ComTCPLib.SetOutputAsUINT(handle, index, uint.Parse(value));
            }
            else if (type == 2)
            {
                ComTCPLib.SetOutputAsREAL32(handle, index, float.Parse(value));
            }
            else if (type == 3)
            {
                ComTCPLib.SetOutputAsBOOL(handle, index, bool.Parse(value));
            }
        }
예제 #2
0
        private void AGVThreadFunc(object obj)
        {
            int  index = Convert.ToInt32(obj);
            bool tmp   = false;

            while (true)
            {
                #region 临时使用,正式使用时去掉

                if (tmp == false)
                {
                    if (index == 2)
                    {
                        if (agvTempLine[3] > 0)
                        {
                            tmp = true;
                        }
                    }
                    else if (index == 1)
                    {
                        if (agvTempLine[2] > 0)
                        {
                            tmp = true;
                        }
                    }
                    else
                    {
                        tmp = true;
                    }
                }

                #endregion

                if (isStart && tmp)
                {
                    //数据库最新数据
                    AGVStatus model = AGVStatusBLL.GetModel(index);

                    if (model.position == -1)
                    {
                        //内存数据
                        //OCSStatus oldModel = ocsModelList.Find(s => s.carId == index);
                        int i = agvModelList.FindIndex(s => s.carId == index);

                        //初始
                        if (i == -1)
                        {
                            int count = AGVStatusBLL.getCountByLine(model.line);

                            agvCarPos[index] = (count - model.sequence) * agvCarWidth + agvStartPos;
                            agvModelList.Add(model);
                        }
                        else
                        {
                            //驱动段改变
                            if (agvModelList[i].line != model.line)
                            {
                                if (model.direction == 1)
                                {
                                    agvCarPos[index] = agvStartPos;
                                }
                                else
                                {
                                    agvCarPos[index] = agvLineLength[int.Parse(model.line)] - agvStartPos;
                                }
                            }
                            else
                            {
                                if (model.direction == 1)
                                {
                                    if (agvCarPos[index] < agvLineLength[int.Parse(model.line)])
                                    {
                                        agvCarPos[index] += agvSpeed;
                                    }
                                }
                                else if (model.direction == 2)
                                {
                                    if (agvCarPos[index] - agvSpeed < agvEndPos)
                                    {
                                        agvCarPos[index] = agvEndPos;
                                    }
                                    else
                                    {
                                        agvCarPos[index] -= agvSpeed;
                                    }
                                }
                            }

                            agvModelList[i] = model;
                        }
                    }
                    else
                    {
                        agvCarPos[index] = float.Parse(model.position.ToString());
                    }

                    int index1 = GetIdex.getDicOutputIndex("agvCar" + index + "01_input_pos");
                    ComTCPLib.SetOutputAsREAL32(handle, index1, float.Parse(agvCarPos[index].ToString()));
                    index1 = GetIdex.getDicOutputIndex("agvCar" + index + "01_input_Path");
                    ComTCPLib.SetOutputAsINT(handle, index1, int.Parse(model.line.ToString()));
                }

                Thread.Sleep(ocsThreadTime);
            }
        }
예제 #3
0
        /// <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)
            {
            }
        }