Exemplo n.º 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));
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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)
            {
            }
        }
Exemplo n.º 4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //ocs数据初始化
            ocsCarPos   = new float[ocsCarCount + 1];
            ocsThread   = new Thread[ocsCarCount];
            ocsTempLine = new int[ocsCarCount + 1];

            GetIdex.SetOCSPathLengthSetCache(ocsLineLength);

            //int[] ocsTmpSequence = new int[1000];
            ////for (int i = 1; i <= 5; i++)
            //for (int i = 1; i <= ocsCarCount; i++)
            //{
            //    ocsTempLine[i] = 0;
            //    OCSStatus model = OCSStatusBLL.GetModel(i);

            //    if (model != null)
            //    {
            //        model.line = int.Parse(ocsPath[i].Split(',')[0]);
            //        model.sequence = ocsTmpSequence[model.line] + 1;
            //        ocsTmpSequence[model.line]++;
            //        OCSStatusBLL.Update(model);
            //    }
            //    else
            //    {
            //        model = new OCSStatus();
            //        model.carId = i;
            //        model.line = int.Parse(ocsPath[i].Split(',')[0]);
            //        model.direction = 1;
            //        model.sequence = ocsTmpSequence[model.line] + 1;
            //        model.backLine = 1;
            //        model.position = -1;
            //        ocsTmpSequence[model.line]++;
            //        OCSStatusBLL.Add(model);
            //    }
            //}

            //agv数据初始化
            //agvCarPos = new float[agvCarCount + 1];
            //agvThread = new Thread[agvCarCount];
            //agvTempLine = new int[agvCarCount + 1];
            //agvdirection = new int[agvCarCount + 1];
            //agvStopTime = new int[agvCarCount + 1];

            //int[] agvTmpSequence = new int[10000];

            //for (int i = 1; i <= agvCarCount; i++)
            //{
            //    agvTempLine[i] = 0;
            //    agvdirection[i] = 0;
            //    agvStopTime[i] = 0;
            //    AGVStatus model = AGVStatusBLL.GetModel(i);

            //    if (model != null)
            //    {
            //        model.line = int.Parse(agvPath[i].Split(',')[0]);
            //        model.direction = 1;
            //        model.sequence = agvTmpSequence[model.line] + 1;
            //        agvTmpSequence[model.line]++;
            //        AGVStatusBLL.Update(model);
            //    }
            //    else
            //    {
            //        model = new AGVStatus();
            //        model.carId = i;
            //        model.line = int.Parse(agvPath[i].Split(',')[0]);
            //        model.direction = 1;
            //        model.sequence = agvTmpSequence[model.line] + 1;
            //        model.backLine = 1;
            //        model.position = -1;
            //        agvTmpSequence[model.line]++;
            //        AGVStatusBLL.Add(model);
            //    }
            //}
        }