Ejemplo n.º 1
0
        /// <summary>
        /// Buffer to Dictionary
        /// </summary>
        /// <param name="daq"></param>
        /// <param name="buffer"></param>
        /// <param name="start"></param>
        /// <param name="size"></param>
        /// <param name="area"></param>
        /// <param name="Wordlen"></param>
        public static void BufferDump(PlcDAQCommunicationObject daq, byte[] buffer, int start, int size, string area, int Wordlen)
        {
            if (buffer == null)
            {
                return;
            }

            string key;

            for (int i = 0; i < size; i = i + Wordlen)
            {
                int value = 0;
                if (area.Equals("I"))
                {
                    key = area + (start + i).ToString();
                }
                else
                {
                    key = area + wtype[Wordlen - 1] + (start + i).ToString();
                }
                byte[] bytes = new byte[Wordlen];
                Array.Copy(buffer, i, bytes, 0, Wordlen);
                Array.Reverse(bytes);
                for (int j = 0; j < Wordlen; j++)
                {
                    value = value + (bytes[j] << 8 * j);
                }
                daq.aream_data[key] = value;
                daq.bytes_data[key] = bytes;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 模具ID判定
        /// </summary>
        /// <param name="data">模具位置状态寄存器值</param>
        /// <param name="no1pos">模具1的位置</param>
        /// <returns>6组模具对应的位置编号</returns>
        public void ModuleID(PlcDAQCommunicationObject data)
        {
            int VD80 = data.aream_data["VB83"] + (data.aream_data["VB82"] << 8) + (data.aream_data["VB81"] << 16) + (data.aream_data["VB80"] << 24);

            if (NumOf1inBit(VD80) != 6)
            {
                typelabel.Text = Convert.ToString(VD80, 2).PadLeft(32, '0');
                return;
                //throw new Exception("非6");
            }
            int no1pos = data.aream_data["VB84"];

            lock (poslocker)
            {
                no1pos--;
                NointPos[0] = no1pos;
                if (IsOdd(no1pos))
                {
                    NostringPos[0] = process_seq[no1pos / 2] + "-" + process_seq[(no1pos / 2 + 1) % 10];
                }
                else
                {
                    NostringPos[0] = process_seq[no1pos / 2];
                }
                int pos     = no1pos + 1;
                int counter = 1;
                int max     = 0;
                while (counter <= 5 && max < 19) //剩下的五个模
                {
                    if (IsBitTrue(VD80, pos))    //如果为1
                    {
                        NointPos[counter] = pos; //counter 1-5
                        if (IsOdd(pos))
                        {
                            NostringPos[counter] = process_seq[pos / 2] + "-" + process_seq[(pos / 2 + 1) % 10];
                        }
                        else
                        {
                            NostringPos[counter] = process_seq[pos / 2];
                        }
                        counter++;
                    }
                    pos = (pos + 1) % 20;
                    max++;
                }
                return;  //pos 0 -19
            }
        }