Example #1
0
        public bool IsEqualSet(BitArray s1, BitArray s2)
        {
            int i;

            for (i = 0; i < s1.Length && i < s2.Length; ++i)
            {
                if (s1.Get(i) != s2.Get(i))
                {
                    return(false);
                }
            }
            for (; i < s1.Length; ++i)
            {
                if (s1.Get(i))
                {
                    return(false);
                }
            }
            for (; i < s2.Length; ++i)
            {
                if (s2.Get(i))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
        public static void Swap(this System.Collections.BitArray instance, int indexA, int indexB)
        {
            bool current = instance.Get(indexA);
            bool swap    = instance.Get(indexB);

            instance.Set(indexA, swap);
            instance.Set(indexB, current);
        }
 internal virtual void DoGet(System.Collections.BitArray a, OpenBitSet b)
 {
     int max = a.Count;
     for (int i = 0; i < max; i++)
     {
         if (a.Get(i) != b.Get(i))
         {
             Assert.Fail("mismatch: BitSet=[" + i + "]=" + a.Get(i));
         }
     }
 }
Example #4
0
 /// <summary>
 /// 消息处理
 /// </summary>
 /// <param name="message"></param>
 private void onMessage(Message message)
 {
     System.Threading.Monitor.Enter(onMessageLock);
     if (message != null && !bitArray.Get(message.Value))
     {
         bitArray.Set(message.Value, true);
         setCallback(true);
     }
     else
     {
         setCallback(false);
     }
     System.Threading.Monitor.Exit(onMessageLock);
 }
        private void DecoderThread(object wave)
        {
            IPlayableStream stream = wave as IPlayableStream;

            lock (mutex)
            {
                while (true)
                {
                    if (current != wave)
                    {
                        return;
                    }

                    // Fill any unfilled buffers
                    for (var i = 0; i < bufferStatus.Count; i++)
                    {
                        if (bufferStatus.Get(i) == false)
                        {
                            bool isDone = FillBuffer(i, stream);
                            if (isDone)
                            {
                                return;
                            }
                        }
                    }

                    // Wait to be signalled that a buffer is empty
                    System.Threading.Monitor.Wait(mutex);
                }
            }
        }
Example #6
0
                public override bool Next()
                {
                    do
                    {
                        if (!scorer.Next())
                        {
                            return(false);
                        }
                    }while (!bitset.Get(scorer.Doc()));

                    /* When skipTo() is allowed on scorer it should be used here
                     * in combination with bitset.nextSetBit(...)
                     * See the while loop in skipTo() below.
                     */
                    return(true);
                }
Example #7
0
        public static System.Collections.BitArray[] CreateResolutionArray(System.Collections.BitArray array, int bitres)
        {
            if (bitres < 4)
            {
                throw new SystemException();
            }
            int lenMod   = (array.Length % bitres);
            int addition = 0;

            if (lenMod != 0)
            {
                throw new SystemException();
            }

            int outSize = array.Length / bitres + addition;

            System.Collections.BitArray[] outArray = new System.Collections.BitArray[outSize];
            for (int i = 0; i < outSize; ++i)
            {
                outArray[i] = new System.Collections.BitArray(bitres);
                for (int res = 0; res < bitres; ++res)
                {
                    outArray[i].Set(res, array.Get(i * bitres + res));
                }
            }
            return(outArray);
        }
Example #8
0
        /// <summary>
        /// Если идентификатор еще не отмеченный, то отметим его, если идентификатор уже отмеченный, то поместим значение mT в словарь
        /// </summary>
        /// <param name="bitArr"></param>
        /// <param name="hash"></param>
        /// <param name="lastDefs"></param>
        /// <param name="id"></param>
        /// <param name="mTval">отметка времени. null - минимальное время</param>
        private static void CheckAndSet(System.Collections.BitArray bitArr, Func <string, int> hash,
                                        Dictionary <string, DateTime> lastDefs, string id, string mTval)
        {
            int code = hash(id);

            if (bitArr.Get(code))
            {
                // Добавляем пару в словарь
                DateTime mT = DateTime.MinValue;
                if (mTval != null)
                {
                    mT = DateTime.Parse(mTval);
                }

                if (lastDefs.TryGetValue(id, out DateTime last))
                {
                    if (mT > last)
                    {
                        lastDefs.Remove(id);
                        lastDefs.Add(id, mT);
                    }
                }
                else
                {
                    lastDefs.Add(id, mT);
                }
            }
            else
            {
                bitArr.Set(code, true);
            }
        }
Example #9
0
 public override void  Collect(int doc, float score)
 {
     if (bits.Get(doc))
     {
         // skip docs not in bits
         results.Collect(doc, score);
     }
 }
Example #10
0
 public System.Collections.IEnumerable getEnum(byte[] indexs)
 {
     System.Collections.BitArray aryInx = new System.Collections.BitArray(indexs);
     for (int i = 0; i < aryInx.Count; i++)
     {
         if (aryInx.Get(i))
             yield return (RGS_HW_Status_Bit_Enum)i;
     }
 }
Example #11
0
 public override void  Collect(int doc, float score)
 {
     if (score > 0.0f && (bits == null || bits.Get(doc)))
     {
         // skip docs not in bits
         totalHits[0]++;
         hq.Insert(new FieldDoc(doc, score));
     }
 }
Example #12
0
 private System.Collections.BitArray CloneBitArray(System.Collections.BitArray inBits, int start, int len)
 {
     System.Collections.BitArray rslt = new System.Collections.BitArray(len);
     for (int i = 0; i < len; i++)
     {
         rslt.Set(i, inBits.Get(i + start));
     }
     return(rslt);
 }
Example #13
0
        internal virtual void  DoGet(System.Collections.BitArray a, OpenBitSet b)
        {
            int max = a.Length;

            for (int i = 0; i < max; i++)
            {
                Assert.AreEqual(a.Get(i), b.Get(i), "mismatch: BitSet=[" + i + "]=" + a.Get(i));
            }
        }
Example #14
0
        public static string BitArrayToString(System.Collections.BitArray b)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < b.Length; i++)
            {
                sb.Append(b.Get(i) ? "1" : "0");
            }
            return(sb.ToString());
        }
Example #15
0
 //取得所有錯誤訊息的位元咧舉值
 public System.Collections.IEnumerable getEnum(byte[] indexs)
 {
     //  throw new Exception("The method or operation is not implemented.");
     System.Collections.BitArray aryInx = new System.Collections.BitArray(indexs);
     for (int i = 0; i < aryInx.Count; i++)
     {
         if (aryInx.Get(i))
             yield return (RGS_HW_Status_Bit_Enum)i;
     }
 }
Example #16
0
            /// <summary>
            /// Creates an object to hold a particular TableEntry.
            /// </summary>
            /// <param name="bytes">The bytes from which to make the TableEntry.</param>
            public TableEntry(byte[] bytes)
            {
                System.Collections.BitArray ba = new System.Collections.BitArray(bytes);
                Compressed = ba.Get(31);
                ba.Set(31, false);

                byte[] temp = new byte[4];
                ba.CopyTo(temp, 0);

                Offset = BitConverter.ToInt32(temp, 0);
            }
Example #17
0
 public bool IsEmptySet(BitArray b)
 {
     for (int i = 0; i != b.Length; ++i)
     {
         if (b.Get(i))
         {
             return(false);
         }
     }
     return(true);
 }
        public bool BitArrayContains()
        {
            var contains = false;

            foreach (var i in _idx)
            {
                // or: _bitArray[i]
                contains |= _bitArray.Get(i);
            }

            return(contains);
        }
Example #19
0
        public bool BitArrayContains()
        {
            var contains = false;

            for (var i = 0; i < Length; i++)
            {
                // or: `_bitArray[i]`
                contains |= _bitArray.Get(i);
            }

            return(contains);
        }
Example #20
0
 public override void  Collect(int doc, float score)
 {
     if (score > 0.0f && (bits == null || bits.Get(doc)))
     {
         // skip docs not in bits
         totalHits[0]++;
         if (hq.Size() < nDocs || score >= minScore)
         {
             hq.Insert(new ScoreDoc(doc, score));
             minScore = ((ScoreDoc)hq.Top()).score; // maintain minScore
         }
     }
 }
Example #21
0
       void IOTask()
       {

           byte[] m_status=new byte[2];
           int cnt=0;
          // bool IsSucess;
           while (true)
           {
               if (IOCard != null)
               {

                   lock (IOCard)
                   {
                       if (IOCard.GetPlayStatus(1, out m_status[0], out m_status[1], out cnt))
                       {
                           System.Collections.BitArray ary = new System.Collections.BitArray(m_status);
                           Status.Set((int)StatusIndex.AC, ary.Get((int)StatusIndex.AC));
                           Status.Set((int)StatusIndex.DC, ary.Get((int)StatusIndex.DC));
                          Status.Set((int)StatusIndex.AMP, ary.Get((int)StatusIndex.AMP));
                           //Status.Set((int)StatusIndex.BUSY, ary.Get((int)StatusIndex.BUSY));
                           Status.Set((int)StatusIndex.Door, ary.Get((int)StatusIndex.Door));
                           if (m_status[1] > SpeakerOut)
                               SpeakerOut = m_status[1];

                       //    Status.Set((int)StatusIndex.SPEAKER, ary.Get((int)StatusIndex.SPEAKER));
                       }
                   }

                   Console.WriteLine("擴大機輸出讀值:{0:X2}", m_status[1]);

               }


               System.Threading.Thread.Sleep(1000);

           }
       }
Example #22
0
        private static void AppendOneOrMoreToEnd(StringBuilder pattern, BitArray requiredPatterns, List <string> patterns, int startIndex)
        {
            if (startIndex < 0)
            {
                throw new ArgumentOutOfRangeException("startIndex cannot be negative", "startIndex");
            }
            if (startIndex >= patterns.Count)
            {
                throw new ArgumentException("startIndex cannot be greater than the number of patterns.", "startIndex");
            }

            pattern.Append("(?:");

            if (requiredPatterns.Get(startIndex))
            {
                // include the required first item
                pattern.Append(patterns[startIndex]);

                if (startIndex < patterns.Count - 1)
                {
                    // optionally include at least one more from there to the end
                    pattern.Append("(?:,");
                    AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
                    pattern.Append(")?");
                }
            }
            else
            {
                if (startIndex < patterns.Count - 1)
                {
                    // include the first item and at least one more from there to the end
                    pattern.Append(patterns[startIndex]).Append(",");
                    AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
                    pattern.Append("|");
                }

                // include the first item alone
                pattern.Append(patterns[startIndex]);

                if (startIndex < patterns.Count - 1)
                {
                    // don't include the first item, but do include one or more to the end
                    pattern.Append("|");
                    AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
                }
            }

            pattern.Append(")");
        }
Example #23
0
            public virtual Explanation Explain(IndexReader ir, int i)
            {
                Explanation inner = weight.Explain(ir, i);
                Filter      f     = Enclosing_Instance.filter;

                System.Collections.BitArray matches = f.Bits(ir);
                if (matches.Get(i))
                {
                    return(inner);
                }
                Explanation result = new Explanation(0.0f, "failure to match filter: " + f.ToString());

                result.AddDetail(inner);
                return(result);
            }
Example #24
0
        public static string DumpSet(BitArray ba)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            for (int i = 0; i < ba.Length; ++i)
            {
                if (ba.Get(i))
                {
                    sb.Append(' ');
                    sb.Append(i);
                }
            }
            sb.Append(" }");
            return(sb.ToString());
        }
Example #25
0
        public static bool[] BitArrayToBoolArray(System.Collections.BitArray b)
        {
            // TODO: When we switch to .net 3,5..
            if (b == null)
            {
                return new bool[] { }
            }
            ;

            bool[] tmp = new bool[b.Count - 1];
            for (int i = 0; i < b.Length; i++)
            {
                tmp[i] = b.Get(i);
            }
            return(tmp);
        }
Example #26
0
        public virtual int getSelectedMonomerIndex(Monomer monomer)
        {
            int selectedMonomerIndex = 0;

            for (int i = 0; i < monomerCount; ++i)
            {
                if (bsSelectedMonomers.Get(i))
                {
                    if (monomers[i] == monomer)
                    {
                        return(selectedMonomerIndex);
                    }
                    ++selectedMonomerIndex;
                }
            }
            return(-1);
        }
Example #27
0
        private byte rotateBitsLeft(byte data, int rotate)
        {
            byte[] temp = new byte[1];
            temp[0] = data;
            System.Collections.BitArray ba = new System.Collections.BitArray(temp);
            byte b = 0;

            for (int i = 0; i < ba.Length; ++i)
            {
                if (ba.Get(i) == true)
                {
                    b += (byte)(0x1 << (rotate + i) % 8);
                }
            }

            return(b);
        }
Example #28
0
        private int countbits(byte data)
        {
            int result = 0;

            byte[] temp = new byte[1];
            temp[0] = data;
            System.Collections.BitArray ba = new System.Collections.BitArray(temp);
            for (int i = 0; i < ba.Length; ++i)
            {
                if (ba.Get(i) == true)
                {
                    result++;
                }
            }

            return(result);
        }
Example #29
0
        private void GetBitView(byte value)
        {
            try
            {
                System.Collections.BitArray myBA = new System.Collections.BitArray(BitConverter.GetBytes(value).ToArray());

                lblBit0.Text = GetBool(myBA.Get(0));
                lblBit1.Text = GetBool(myBA.Get(1));
                lblBit2.Text = GetBool(myBA.Get(2));
                lblBit3.Text = GetBool(myBA.Get(3));
                lblBit4.Text = GetBool(myBA.Get(4));
                lblBit5.Text = GetBool(myBA.Get(5));
                lblBit6.Text = GetBool(myBA.Get(6));
                lblBit7.Text = GetBool(myBA.Get(7));
            }
            catch (Exception)
            {
            }
        }
Example #30
0
 /// <summary>
 /// Returns the next un-set bit at or after index, or -1 if no such bit exists.
 /// </summary>
 /// <param name="bitArray"></param>
 /// <param name="index">the index of bit array at which to start checking</param>
 /// <returns>the next set bit or -1</returns>
 public static int NextClearBit(System.Collections.BitArray bitArray, int index)
 {
     while (index < bitArray.Length)
     {
         // if index bit is not set, return it
         // otherwise check next index bit
         if (!bitArray.Get(index))
         {
             return(index);
         }
         else
         {
             index++;
         }
     }
     // if no bits are set at or after index, return -1
     return(-1);
 }
Example #31
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal byte GetFaceType()
        {
            bool[] faceBits = new bool[] { Topology, FaceMaterial, FaceUVs, FaceVertexUVs,
                                           FaceNormals, VertexNormals, FaceColor, VertexColors };
            System.Collections.BitArray bits = new System.Collections.BitArray(faceBits);

            byte b = 0;

            if (bits.Get(0))
            {
                b++;
            }
            if (bits.Get(1))
            {
                b += 2;
            }
            if (bits.Get(2))
            {
                b += 4;
            }
            if (bits.Get(3))
            {
                b += 8;
            }
            if (bits.Get(4))
            {
                b += 16;
            }
            if (bits.Get(5))
            {
                b += 32;
            }
            if (bits.Get(6))
            {
                b += 64;
            }
            if (bits.Get(7))
            {
                b += 128;
            }
            return(b);
        }
Example #32
0
        public virtual int DoNestedTermConjunctions(IndexSearcher s, int termsInIndex, int maxOuterClauses, int maxClauses, int iter)
        {
            int  ret      = 0;
            long nMatches = 0;

            for (int i = 0; i < iter; i++)
            {
                int          oClauses = r.Next(maxOuterClauses - 1) + 2;
                BooleanQuery oq       = new BooleanQuery();
                for (int o = 0; o < oClauses; o++)
                {
                    int          nClauses = r.Next(maxClauses - 1) + 2;            // min 2 clauses
                    BooleanQuery bq       = new BooleanQuery();
                    System.Collections.BitArray termflag = new System.Collections.BitArray((termsInIndex % 64 == 0?termsInIndex / 64:termsInIndex / 64 + 1) * 64);
                    for (int j = 0; j < nClauses; j++)
                    {
                        int tnum;
                        // don't pick same clause twice
                        tnum = r.Next(termsInIndex);
                        if (termflag.Get(tnum))
                        {
                            tnum = SupportClass.BitSetSupport.NextClearBit(termflag, tnum);
                        }
                        if (tnum < 0 || tnum >= 25)
                        {
                            tnum = SupportClass.BitSetSupport.NextClearBit(termflag, 0);
                        }
                        termflag.Set(tnum, true);
                        Query tq = new TermQuery(terms[tnum]);
                        bq.Add(tq, BooleanClause.Occur.MUST);
                    }                     // inner

                    oq.Add(bq, BooleanClause.Occur.MUST);
                }                 // outer


                CountingHitCollector hc = new CountingHitCollector();
                s.Search(oq, hc);
                nMatches += hc.GetCount();
                ret      += hc.GetSum();
            }
            System.Console.Out.WriteLine("Average number of matches=" + (nMatches / iter));
            return(ret);
        }
        private static void AppendZeroOrMoreToEnd(StringBuilder pattern, BitArray requiredPatterns, List <string> patterns, int startIndex)
        {
            if (startIndex < 0)
            {
                throw new ArgumentOutOfRangeException("startIndex cannot be negative", "startIndex");
            }
            if (startIndex >= patterns.Count)
            {
                throw new ArgumentException("startIndex cannot be greater than the number of patterns.", "startIndex");
            }

            for (int i = startIndex; i < patterns.Count; i++)
            {
                pattern.Append("(?:/").Append(patterns[i]).Append(")");
                if (!requiredPatterns.Get(i))
                {
                    pattern.Append('?');
                }
            }
        }
		public virtual void  Test()
		{
			PositionBasedTermVectorMapper mapper = new PositionBasedTermVectorMapper();
			
			mapper.SetExpectations("test", tokens.Length, true, true);
			//Test single position
			for (int i = 0; i < tokens.Length; i++)
			{
				System.String token = tokens[i];
				mapper.Map(token, 1, null, thePositions[i]);
			}
			System.Collections.IDictionary map = mapper.GetFieldToTerms();
			Assert.IsTrue(map != null, "map is null and it shouldn't be");
			Assert.IsTrue(map.Count == 1, "map Size: " + map.Count + " is not: " + 1);
			System.Collections.IDictionary positions = (System.Collections.IDictionary) map["test"];
			Assert.IsTrue(positions != null, "thePositions is null and it shouldn't be");
			
			Assert.IsTrue(positions.Count == numPositions, "thePositions Size: " + positions.Count + " is not: " + numPositions);
			System.Collections.BitArray bits = new System.Collections.BitArray((numPositions % 64 == 0?numPositions / 64:numPositions / 64 + 1) * 64);
			for (System.Collections.IEnumerator iterator = new System.Collections.Hashtable(positions).GetEnumerator(); iterator.MoveNext(); )
			{
				System.Collections.DictionaryEntry entry = (System.Collections.DictionaryEntry) iterator.Current;
				PositionBasedTermVectorMapper.TVPositionInfo info = (PositionBasedTermVectorMapper.TVPositionInfo) entry.Value;
				Assert.IsTrue(info != null, "info is null and it shouldn't be");
				int pos = ((System.Int32) entry.Key);
				bits.Set(pos, true);
				Assert.IsTrue(info.GetPosition() == pos, info.GetPosition() + " does not equal: " + pos);
				Assert.IsTrue(info.GetOffsets() != null, "info.getOffsets() is null and it shouldn't be");
				if (pos == 0)
				{
					Assert.IsTrue(info.GetTerms().Count == 2, "info.getTerms() Size: " + info.GetTerms().Count + " is not: " + 2); //need a test for multiple terms at one pos
					Assert.IsTrue(info.GetOffsets().Count == 2, "info.getOffsets() Size: " + info.GetOffsets().Count + " is not: " + 2);
				}
				else
				{
					Assert.IsTrue(info.GetTerms().Count == 1, "info.getTerms() Size: " + info.GetTerms().Count + " is not: " + 1); //need a test for multiple terms at one pos
					Assert.IsTrue(info.GetOffsets().Count == 1, "info.getOffsets() Size: " + info.GetOffsets().Count + " is not: " + 1);
				}
			}
			int cardinality = 0;
			for (int i = 0; i < bits.Count; i++)
			{
				if (bits.Get(i)) cardinality++;
			}
			Assert.IsTrue(cardinality == numPositions, "Bits are not all on");
		}
Example #35
0
		/// <summary>
        /// Implements the operator >>, 
        /// </summary>
        /// <param name="a">A.</param>
        /// <param name="shift">The shift.</param>
        /// <returns>The result of the operator.</returns>
        public static NodeId operator >>(NodeId a, int shift)
        {
            if (((object)a == null) || shift == 0)
            {
                return a;
            }
            System.Collections.BitArray input = new System.Collections.BitArray(a.Data);
            System.Collections.BitArray resultarray = new System.Collections.BitArray(a.Digits * 8);

            byte[] result = new byte[a.Digits];

            for (int i = a.Digits * 8 - 1; i >= a.Digits * 8 - 1 - shift; i--)
            {
                resultarray[i] = false;
            }

            for (int i = a.Digits * 8 - 1 - shift; i >= 0; i--)
            {
                resultarray.Set(i, input.Get(i + shift));
            }

            resultarray.CopyTo(result, 0);

            Array.Reverse(result);

            return new NodeId(result);
        }
Example #36
0
		public  System.Drawing.Point[] findWayTo4( Point ori, Point dest, byte terrain, byte player, bool attack )
		{

			if ( ori.X == -1 || ori.Y == -1 || dest.X == -1 || dest.Y == -1 )
				return new Point[ 1 ] { new Point( -1, -1 ) };
			
			if ( 
				game.grid[ ori.X, ori.Y ].continent != game.grid[ dest.X, dest.Y ].continent && 
				game.grid[ ori.X, ori.Y ].continent != 0 &&
				game.grid[ dest.X, dest.Y ].continent != 0 
				)
				return new Point[ 1 ] { new Point( -1, -1 ) };

			if ( ori.X == dest.X && ori.Y == dest.Y )
				return new Point[ 1 ] { new Point( -2, -2 ) };

			Point[] pnt1 = new Point[ game.width * game.height ]; 
			int pos = 0; 
			int indOri = 0, indDest = 0; 

			byte[] pols = returnRelationTypeList( !attack, true, true, false, false, false ); 

			if ( terrain == 1 ) 
			{ 
				for ( int x = 0; x < game.width; x ++ )
					for ( int y = 0; y < game.height; y ++ )
					{
						if ( ori.X == x && ori.Y == y )
						{
							pnt1[ pos ] = new Point( x, y ); 
							indOri = pos; 
							pos ++; 
						}
						else if ( dest.X == x && dest.Y == y )
						{
							pnt1[ pos ] = new Point( x, y ); 
							indDest = pos; 
							pos ++; 
						}
						else if ( 
							game.grid[ x, y ].continent == game.grid[ ori.X, ori.Y ].continent &&
							(
							game.grid[ x, y ].territory - 1 == player ||
							game.grid[ x, y ].territory == 0 ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector
							) &&
							!caseOccupiedByRelationType( x, y, player, pols )
							)
						{
							pnt1[ pos ] = new Point( x, y ); 
							pos ++; 
						}
					}
			}
			else
			{ // water
				for ( int x = 0; x < game.width; x ++ )
					for ( int y = 0; y < game.height; y ++ )
						if ( ori.X == x && ori.Y == y )
						{
							pnt1[ pos ] = new Point( x, y ); 
							indOri = pos; 
							pos ++; 
						}
						else if ( dest.X == x && dest.Y == y )
						{
							pnt1[ pos ] = new Point( x, y ); 
							indDest = pos; 
							pos ++; 
						}
						else if ( 
							game.grid[ x, y ].continent == 0 || 
							(
							game.grid[ x, y ].city > 0 &&
							(
							game.grid[ x, y ].territory - 1 == player ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector
							)
							) &&
							!caseOccupiedByRelationType( x, y, player, pols )
							)
						{
							pnt1[ pos ] = new Point( x, y ); 
							pos ++; 
						}
			}
			
			Point[] pnt = new Point[ pos ]; 
			int[] cost = new int[ pos ], prevPnt = new int[ pos ], order = new int[ pos ]; 
			Int16[][] inRange =  new Int16[ pos ][];

			for ( int i = 0; i < pos; i ++ ) 
			{
				pnt[ i ] = pnt1[ i ]; 
				order[ i ] = -1; 
			}

			System.Collections.BitArray alreadyWorked = new System.Collections.BitArray( pos, false );

			order[ indOri ] = 0; 
			cost[ indOri ] = 0; 
			Point[] way; 

			bool mod = true, modInRad = false; 

			for ( int rad = 0; mod; rad ++ ) 
			{ 
				mod = false; 
				modInRad = true; 

				while ( modInRad )
				{
					modInRad = false; 

					for ( int i = 0; i < pos; i ++ ) 
						if ( order[ i ] == rad ) 
						{
							if ( !alreadyWorked.Get( i ) ) 
							{ 
								Int16[] temp = new Int16[ pos ];
								int tot = 0;

								for ( int j = 0; j < pos; j ++ ) 
									if ( isNextTo( pnt[ i ], pnt[ j ] ) ) 
									{ 
										temp[ tot ] = (Int16)j;
										tot ++;
									} 

								inRange[ i ] = new Int16[ tot ];
								
								for ( int j = 0; j < tot; j ++ ) 
									inRange[ i ][ j ] = temp[ j ];

								alreadyWorked.Set( i, true ); 
							} 

							for ( int j = 0; j < inRange[ i ].Length; j ++ ) 
								if ( 
									order[ inRange[ i ][ j ] ] == -1 || 
									( 
									order[ inRange[ i ][ j ] ] > rad && 
									order[ inRange[ i ][ j ] ] > rad + costBetween( pnt[ i ], pnt[ inRange[ i ][ j ] ] ) 
									) 
									) 
								{ 
									order[ i ] --;
									order[ inRange[ i ][ j ] ] = rad + costBetween( pnt[ i ], pnt[ inRange[ i ][ j ] ] ); 
									prevPnt[ inRange[ i ][ j ] ] = i; 
									mod = true; 
									modInRad = true; 

									if ( inRange[ i ][ j ] == indDest ) 
									{ 
										way = new Point[ pos ]; 
										int[] wayInt = new int[ pos ]; 
										way[ 0 ] = dest; 
										wayInt[ 0 ] = indDest; //inRange[ i ][ j ]; 

										for ( int c = 0; c < pos - 1; c ++ ) 
										{ 
											if ( prevPnt[ wayInt[ c ] ] == indOri )
											{
												Point[] finalWay = new Point[ c + 1 ];

												for ( int f = 0; f < finalWay.Length; f ++ ) 
													finalWay[ f ] = way[ finalWay.Length - f - 1 ]; 

												return finalWay;
											}

											wayInt[ c + 1 ] = prevPnt[ wayInt[ c ] ]; 
											way[ c + 1 ] = pnt[ prevPnt[ wayInt[ c ] ] ]; 
										} 

										return way; 
									} 
								} 
						} 
						else if ( order[ i ] < rad ) 
						{ 
							mod = true; 
						} 
				} 
			} 

			return new Point[] { new Point( -1, -1 ) };	
		}
Example #37
0
        private void DirtyJob()
        {
            VentsTools VT = new VentsTools();
            bool refreshValues = false;
            if (VT.ReadConfigFromDB(VentsConst.connectionString, VentsConst._CONFtb, ref _ventsData))
                if (ReadDataFromPLC())
                {
                    //проверим нет ли значений превышающих _MAX_ENERGY_COUNTER (*100 квтч), если есть - добавим число к общему значению счетчика (ventEnergyConf.tb 'countvalue')
                    //также проверим нет ли нулевых значений (что может означать неисправность, например "нет связи")
                    //если есть ноль, проверим сообщение об ошибке, и если есть ошибка заменим значение на -1
                    foreach(Vents record in _ventsData)
                    {
                        
                        if (record.value >= VentsConst._MAX_ENERGY_COUNTER)
                        {
                            #region лямбда
                            ventdel vd = (DB, start, size) =>
                            {
                                string RDY_REF_state = "";
                                try
                                {
                                    if (_client.ConnectTo(VentsConst._ipPLC, VentsConst._RACK, VentsConst._SLOT) != 0)
                                        throw new Exception("Cant connect to PLC");

                                    int result;
                                    byte[] buffer = new byte[1];
                                    System.Collections.BitArray ba;

                                    result = _client.DBRead(DB, start+1, size, buffer); //vent.startBit+1,- secont byte of Input Stateword (RDY_REF bit is a 3rd bit)
                                    if (result != 0)
                                        ShowError(result);
                                    else
                                    {
                                        _client.Disconnect();
                                        ba = new System.Collections.BitArray(new byte[] { buffer[0] });
                                        return ba.Get(2) ? RDY_REF_state = "Ebabled" : RDY_REF_state = "Disabled";
                                    }
                                    return RDY_REF_state;
                                }
                                catch (Exception ex)
                                {
                                    _log.Error(ex.Message);
                                    return RDY_REF_state;
                                }
                            };
                        #endregion
                            //обновим значение счетчика в БД, перед этим проверим не включен ли вентилятор
                            if (vd(record.DB, record.startBit, 1) == "Disabled")
                            {
                                if (VT.UpdateCountValuesConfTB(record))
                                    //сбросим счетчик на частотном преобразователе
                                    if (SendResetBitToPLC(record.resetM))
                                    {
                                        refreshValues = true;
                                        Thread.Sleep(1000);
                                    }
                            }
                        }
                        if(record.value == 0)
                        {

                        }
                    }
                    //если обнаружено превышение счетчика, то не будем записывать считанные данные, а подождем немного и выполним "грязную работу" еще раз
                    if (refreshValues)
                    {
                        Thread.Sleep(1000);
                        new Thread(DirtyJob).Start();
                    }
                    else
                    {
                        //сохраним значения в БД, если за этот час не было записей
                        int LRCHres = VT.LastRecordCurrentHour(System.DateTime.Now);
                        if(LRCHres== 0 )
                            VT.WriteDataToDB(_ventsData);
                        else if (_debugBit)
                            VT.WriteDataToDB(_ventsData);
                    }
                }
        }
        private static void AppendZeroOrMoreToEnd(StringBuilder pattern, BitArray requiredPatterns, List<string> patterns, int startIndex)
        {
            if (startIndex < 0)
                throw new ArgumentOutOfRangeException("startIndex cannot be negative", "startIndex");
            if (startIndex >= patterns.Count)
                throw new ArgumentException("startIndex cannot be greater than the number of patterns.", "startIndex");

            for (int i = startIndex; i < patterns.Count; i++)
            {
                pattern.Append(@"(?:\.").Append(patterns[i]).Append(")");
                if (!requiredPatterns.Get(i))
                    pattern.Append('?');
            }
        }
Example #39
0
		public  int findCostTo( Point ori, Point dest, byte terrain, byte player, bool attack )
		{
			if ( ori.X == dest.X && ori.Y == dest.Y )
				return 0;

			if ( ori.X == -1 || ori.Y == -1 || dest.X == -1 || dest.Y == -1 )
				return 10000;
			
			if ( 
				game.grid[ ori.X, ori.Y ].continent != game.grid[ dest.X, dest.Y ].continent && 
				game.grid[ ori.X, ori.Y ].continent != 0 &&
				game.grid[ dest.X, dest.Y ].continent != 0 
				)
				return 10000;

			Point[] pnt1 = new Point[ game.width * game.height ]; 
			int pos = 0; 
			int indOri = 0, indDest = 0; 

			byte[] pols = returnRelationTypeList( !attack, true, true, false, false, false ); 
			bool onNeutralTerritory = false;

			if ( 
				game.grid[ ori.X, ori.Y ].territory - 1 != player &&
				game.grid[ ori.X, ori.Y ].territory != 0 &&
				(
				game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.ceaseFire ||
				game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.peace  ||
				game.playerList[ player ].foreignRelation[ game.grid[ ori.X, ori.Y ].territory - 1 ].politic == (byte)Form1.relationPolType.war 
				)
				)
				onNeutralTerritory = true;

			if ( terrain == 1 ) 
			{ 
				for ( int x = 0; x < game.width; x ++ )
					for ( int y = 0; y < game.height; y ++ )
					{
						if ( ori.X == x && ori.Y == y )
						{
							pnt1[ pos ] = new Point( x, y ); 
							indOri = pos; 
							pos ++; 
						}
						else if ( dest.X == x && dest.Y == y )
						{
							pnt1[ pos ] = new Point( x, y ); 
							indDest = pos; 
							pos ++; 
						}
						else if ( 
							game.grid[ x, y ].continent == game.grid[ ori.X, ori.Y ].continent &&
							(
							game.grid[ x, y ].territory - 1 == player || 
							game.grid[ x, y ].territory == 0 || 
							(
							onNeutralTerritory && 
							game.grid[ x, y ].city == 0 
							) ||
							(
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector 
							) || 
							(
							attack &&
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.war 
							)
							) &&
							!caseOccupiedByRelationType( x, y, player, pols )
							)
						{
							pnt1[ pos ] = new Point( x, y ); 
							pos ++; 
						}
					}
			}
			else
			{ // water
				for ( int x = 0; x < game.width; x ++ )
					for ( int y = 0; y < game.height; y ++ )
						if ( ori.X == x && ori.Y == y )
						{
							pnt1[ pos ] = new Point( x, y ); 
							indOri = pos; 
							pos ++; 
						}
						else if ( dest.X == x && dest.Y == y )
						{
							pnt1[ pos ] = new Point( x, y ); 
							indDest = pos; 
							pos ++; 
						}
						else if ( 
							game.grid[ x, y ].continent == 0 || 
							( 
							game.grid[ x, y ].city > 0 && 
							( 
							onNeutralTerritory ||
							game.grid[ x, y ].territory - 1 == player || 
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.alliance ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protected ||
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.Protector || 
							(
							game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.war && 
							attack
							)
							) 
							) && 
							!caseOccupiedByRelationType( x, y, player, pols ) 
							) 
						{ 
							pnt1[ pos ] = new Point( x, y ); 
							pos ++; 
						} 
			}
			
			Point[] pnt = new Point[ pos ]; 
			int[] cost = new int[ pos ], prevPnt = new int[ pos ], order = new int[ pos ]; 
			System.Collections.BitArray[] inRange = new System.Collections.BitArray[ pos ]; 

			for ( int i = 0; i < pos; i ++ ) 
			{
				pnt[ i ] = pnt1[ i ]; 
				order[ i ] = -1; 

				inRange[ i ] = new System.Collections.BitArray( i );
			}

			System.Collections.BitArray alreadyWorked = new System.Collections.BitArray( pos, false );
			order[ indOri ] = 0; 
			cost[ indOri ] = 0; 

			bool mod = true, modInRad = false; 

			for ( int rad = 0; mod && rad < 3 * game.width; rad ++ ) 
			{ 
				mod = false; 
				modInRad = true; 

				while ( modInRad )
				{
					modInRad = false; 

					for ( int i = 0; i < pos; i ++ ) 
						if ( order[ i ] == rad ) 
						{
							if ( !alreadyWorked.Get( i ) ) 
							{ 
								for ( int j = 0; j < pos; j ++ ) 
									if ( isNextTo( pnt[ i ], pnt[ j ] ) ) 
									{ 
										if ( i < j ) 
											inRange[ j ].Set( i, true ); 
										else if ( i > j ) 
											inRange[ i ].Set(j, true ); 
									} 

								alreadyWorked.Set( i, true ); 
							} 

							for ( int j = 0; j < pos; j ++ ) 
								if ( 
									(
									( 
									i < j &&
									inRange[ j ].Get( i )
									) ||
									( 
									i > j &&
									inRange[ i ].Get( j )
									)
									)
									&& 
									( 
									order[ j ] == -1 || 
									( 
									order[ j ] > rad && 
									order[ j ] > rad + costBetween( pnt[ i ], pnt[ j ] ) 
									) 
									) 
									) 
								{ 
									order[ i ] --;
									order[ j ] = rad + costBetween( pnt[ i ], pnt[ j ] ); 

									prevPnt[ j ] = i; 
									mod = true; 
									modInRad = true; 

									if ( j == indDest ) 
										return order[ j ];
								} 
						} 
						else if ( order[ i ] > rad ) 
						{ 
							mod = true; 
						} 
				} 
			} 

			return 10000;
		}
Example #40
0
		public static string DumpSet(BitArray ba)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append("{");
			for (int i = 0; i < ba.Length; ++i)
			{
				if (ba.Get(i))
				{
					sb.Append(' ');
					sb.Append(i);
				}
			}
			sb.Append(" }");
			return sb.ToString();
		}
		public virtual int DoNestedTermConjunctions(IndexSearcher s, int termsInIndex, int maxOuterClauses, int maxClauses, int iter)
		{
			int ret = 0;
			long nMatches = 0;
			for (int i = 0; i < iter; i++)
			{
				int oClauses = r.Next(maxOuterClauses - 1) + 2;
				BooleanQuery oq = new BooleanQuery();
				for (int o = 0; o < oClauses; o++)
				{
					
					int nClauses = r.Next(maxClauses - 1) + 2; // min 2 clauses
					BooleanQuery bq = new BooleanQuery();
					System.Collections.BitArray termflag = new System.Collections.BitArray((termsInIndex % 64 == 0 ? termsInIndex / 64 : termsInIndex / 64 + 1) * 64);
					for (int j = 0; j < nClauses; j++)
					{
						int tnum;
						// don't pick same clause twice
						tnum = r.Next(termsInIndex);
						if (termflag.Get(tnum))
						{
							int nextClearBit = -1;
							for (int k = tnum + 1; k < termflag.Count; k++)
							{
								if (!termflag.Get(k))
								{
									nextClearBit = k;
									break;
								}
							}
							tnum = nextClearBit;
						}
						if (tnum < 0 || tnum >= 25)
						{
							int nextClearBit = -1;
							for (int k = 0; k < termflag.Count; k++)
							{
								if (!termflag.Get(k))
								{
									nextClearBit = k;
									break;
								}
							}
							tnum = nextClearBit;
						}
						termflag.Set(tnum, true);
						Query tq = new TermQuery(terms[tnum]);
						bq.Add(tq, BooleanClause.Occur.MUST);
					} // inner
					
					oq.Add(bq, BooleanClause.Occur.MUST);
				} // outer
				
				
				CountingHitCollector hc = new CountingHitCollector();
				s.Search(oq, hc);
				nMatches += hc.GetCount();
				ret += hc.GetSum();
			}
			System.Console.Out.WriteLine("Average number of matches=" + (nMatches / iter));
			return ret;
		}
Example #42
0
		public bool IsEqualSet(BitArray s1, BitArray s2)
		{
			int i;
			for (i = 0; i < s1.Length && i < s2.Length; ++i)
			{
				if (s1.Get(i) != s2.Get(i))
					return false;
			}
			for (; i < s1.Length; ++i)
			{
				if (s1.Get(i))
					return false;
			}
			for (; i < s2.Length; ++i)
			{
				if (s2.Get(i))
					return false;
			}
			return true;
		}
Example #43
0
            /// <summary>
            /// Creates an object to hold a particular TableEntry.
            /// </summary>
            /// <param name="bytes">The bytes from which to make the TableEntry.</param>
            public TableEntry(byte[] bytes)
            {
                System.Collections.BitArray ba = new System.Collections.BitArray(bytes);
                Compressed = ba.Get(31);
                ba.Set(31, false);

                byte[] temp = new byte[4];
                ba.CopyTo(temp, 0);

                Offset = BitConverter.ToInt32(temp, 0);
            }
Example #44
0
       void ReadingTask()
       {
           byte[] tempdata = new byte[data.Length];
           while (true)
           {

               try
               {
                   if (RTUDevice!=null && RTUDevice.connected != IsConnected)
                   {
                       IsConnected = RTUDevice.connected;
                      using( SecureDBEntities1 db = new SecureDBEntities1())
                       {
                           tblPDConfig pdc = db.tblPDConfig.Where(n => n.PDName == this.PDName).FirstOrDefault();
                           if (pdc != null)
                           {
                               pdc.Comm_state = IsConnected ? 1 : 0;
                               db.SaveChanges();
                           }

                           db.tblPDAlarmLog.Add(new tblPDAlarmLog() { Timestamp = DateTime.Now, PDItem = "Comm_state", PDName = this.PDName, Status = IsConnected ? 1 : 0 , UserMemo=pdc.Memo});
                           db.SaveChanges();
                       }
                   }

                   if (RTUDevice != null && RTUDevice.connected)
                   {
                       lock (lockobj)
                       {
                         
                                RTUDevice.ReadDiscreteInputs(1, 0, 0, 12, ref tempdata);
                                if (tempdata == null)
                                {
                                    Console.WriteLine(this.PDName + "讀取資料失敗");
                                    reading_fail_cnt++;
                                    continue;
                                }
                                else
                                    reading_fail_cnt = 0;

                                if ((tblPDConfig.type ?? 1) == 2)  //R11
                                {
                                    for (int i = 0; i < tempdata.Length; i++)
                                        tempdata[i] = (byte)(~tempdata[i]);

                                    System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]);
                                    System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata);
                                    baryD.Set(0, baryS.Get(4));  //r0
                                    baryD.Set(1, baryS.Get(5));  //s0
                                    baryD.Set(2, baryS.Get(6));  // t0
                                    baryD.Set(3, baryS.Get(0));  //r1
                                    baryD.Set(4, baryS.Get(1)); //s1
                                    baryD.Set(5, baryS.Get(2));  //t1
                                    baryD.Set(6, baryS.Get(7));  // L0
                                    baryD.Set(7, baryS.Get(8));  // L1
                                    baryD.Set(8, baryS.Get(9));  // L2
                                    baryD.Set(9, baryS.Get(10));  // L3
                                    baryD.Set(10, baryS.Get(11));  // L4
                                    baryD.Set(11, baryS.Get(3));  // cab
                                    baryD.CopyTo(tempdata, 0);
                                }
                                else if((tblPDConfig.type ?? 1) == 7)
                                {

                                    //for (int i = 0; i < tempdata.Length; i++)
                                    //    tempdata[i] = (byte)(~tempdata[i]);

                                    System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]);
                                    System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata);
                                    baryD.Set(0, baryS.Get(4));  //r0
                                    baryD.Set(1, baryS.Get(5));  //s0
                                    baryD.Set(2, baryS.Get(6));  // t0
                                    baryD.Set(3, baryS.Get(0));  //r1
                                    baryD.Set(4, baryS.Get(1)); //s1
                                    baryD.Set(5, baryS.Get(2));  //t1
                                    baryD.Set(6, baryS.Get(7));  // L0
                                    baryD.Set(7, baryS.Get(8));  // L1
                                    baryD.Set(8, baryS.Get(9));  // L2
                                    baryD.Set(9, baryS.Get(10));  // L3
                                    baryD.Set(10, baryS.Get(11));  // L4
                                    baryD.Set(11, !baryS.Get(3));  // cab
                                    baryD.CopyTo(tempdata, 0);
                                }
                           else if ((tblPDConfig.type ?? 1) == 5)  //R13
                                {
                                    for (int i = 0; i < tempdata.Length; i++)
                                        tempdata[i] = (byte)(~tempdata[i]);

                                    System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]);
                                    System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata);
                                    baryD.Set(0, baryS.Get(4));  //r0
                                    baryD.Set(1, baryS.Get(5));  //s0
                                    baryD.Set(2, baryS.Get(6));  // t0
                                    baryD.Set(3, baryS.Get(0));  //r1
                                    baryD.Set(4, baryS.Get(1)); //s1
                                    baryD.Set(5, baryS.Get(2));  //t1
                                    baryD.Set(6, baryS.Get(7));  // L0
                                    baryD.Set(7, baryS.Get(8));  // L1
                                    baryD.Set(8, baryS.Get(9));  // L2
                                    baryD.Set(9, baryS.Get(10));  // L3
                                    baryD.Set(10, baryS.Get(11));  // L4
                                    baryD.Set(11, !baryS.Get(3));  // cab
                                    baryD.CopyTo(tempdata, 0);
                                }
                                else if ((tblPDConfig.type ?? 1) == 3) //R12
                                {

                                    for (int i = 0; i < tempdata.Length; i++)
                                        tempdata[i] = (byte)(~tempdata[i]);

                                    System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]);
                                    System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata);
                                    baryD.Set(0, baryS.Get(6));  //r0
                                    baryD.Set(1, baryS.Get(7));  //s0
                                    baryD.Set(2, baryS.Get(8));  // t0
                                    baryD.Set(3, baryS.Get(0));  //r1
                                    baryD.Set(4, baryS.Get(1)); //s1
                                    baryD.Set(5, baryS.Get(2));  //t1
                                    baryD.Set(6, baryS.Get(9));  // L0
                                    baryD.Set(7, baryS.Get(10));  // L1
                                    baryD.Set(8, baryS.Get(11));  // L2
                                    //baryD.Set(9, 0baryS.Get(10));  // L3
                                    //baryD.Set(10,0 baryS.Get(11));  // L4
                                    baryD.Set(11, baryS.Get(3) && baryS.Get(4) && baryS.Get(5));  // cab
                                    baryD.CopyTo(tempdata, 0);
                                }

                                else if ((tblPDConfig.type ?? 1) == 4) //R23 T74
                                {
                                    System.Collections.BitArray baryD = new System.Collections.BitArray(tempdata);
                                    baryD.Set(11,! baryD.Get(11));
                                    baryD.CopyTo(tempdata, 0);
                                }
                                else if ((tblPDConfig.type ?? 1) == 6)
                                {
                                    System.Collections.BitArray bard = new System.Collections.BitArray(tempdata);
                                    for (int i = 0; i < 11; i++)
                                        bard.Set(i, !bard.Get(i));

                                    bard.CopyTo(tempdata, 0);
                                }

                                
                           //  RTUDevice.ReadHoldingRegister((ushort)this.DevID, (byte)255, (ushort)(StartAddress - 1), this.RegisterLength, ref tempdata);
                           if (tempdata != null && tempdata.Length != 0)
                           {
                               CheckDataChange(tempdata);
                               System.Array.Copy(tempdata, data, 2);
                               //for (int i = 0; i < tempdata.Length; i++)
                               //{


                               //    data[i] = tempdata[i];
                               //}
                           }
                       }
                   }


                   

               }
               catch (Exception ex)
               {
                 Console.WriteLine(this.PDName+","+((tempdata==null)?"突然斷線":ex.Message) + "," + ex.StackTrace);
               }
               finally
               {
                   System.Threading.Thread.Sleep(1000);
               }

           }
       }
Example #45
0
		public bool IsEmptySet(BitArray b)
		{
			for (int i = 0; i != b.Length; ++i)
			{
				if (b.Get(i))
					return false;
			}
			return true;
		}
Example #46
0
		public virtual int DoTermConjunctions(IndexSearcher s, int termsInIndex, int maxClauses, int iter)
		{
			int ret = 0;
			
			long nMatches = 0;
			for (int i = 0; i < iter; i++)
			{
				int nClauses = r.Next(maxClauses - 1) + 2; // min 2 clauses
				BooleanQuery bq = new BooleanQuery();
				System.Collections.BitArray termflag = new System.Collections.BitArray((termsInIndex % 64 == 0?termsInIndex / 64:termsInIndex / 64 + 1) * 64);
				for (int j = 0; j < nClauses; j++)
				{
					int tnum;
					// don't pick same clause twice
					tnum = r.Next(termsInIndex);
					if (termflag.Get(tnum))
						tnum = BitSetSupport.NextClearBit(termflag, tnum);
					if (tnum < 0 || tnum >= termsInIndex)
						tnum = BitSetSupport.NextClearBit(termflag, 0);
					termflag.Set(tnum, true);
					Query tq = new TermQuery(terms[tnum]);
					bq.Add(tq, Occur.MUST);
				}
				
				CountingHitCollector hc = new CountingHitCollector();
				s.Search(bq, hc);
				nMatches += hc.GetCount();
				ret += hc.GetSum();
			}
			System.Console.Out.WriteLine("Average number of matches=" + (nMatches / iter));
			
			return ret;
		}
Example #47
0
		internal virtual void  DoRandomSets(int maxSize, int iter, int mode)
		{
			System.Collections.BitArray a0 = null;
			OpenBitSet b0 = null;
			
			for (int i = 0; i < iter; i++)
			{
				int sz = rand.Next(maxSize);
				System.Collections.BitArray a = new System.Collections.BitArray(sz);
				OpenBitSet b = new OpenBitSet(sz);
				
				// test the various ways of setting bits
				if (sz > 0)
				{
					int nOper = rand.Next(sz);
					for (int j = 0; j < nOper; j++)
					{
						int idx;
						
						idx = rand.Next(sz);
						a.Set(idx, true);
						b.FastSet(idx);
						idx = rand.Next(sz);
						a.Set(idx, false);
						b.FastClear(idx);
						idx = rand.Next(sz);
						a.Set(idx, !a.Get(idx));
						b.FastFlip(idx);
						
						bool val = b.FlipAndGet(idx);
						bool val2 = b.FlipAndGet(idx);
						Assert.IsTrue(val != val2);
						
						val = b.GetAndSet(idx);
						Assert.IsTrue(val2 == val);
						Assert.IsTrue(b.Get(idx));
						
						if (!val)
							b.FastClear(idx);
						Assert.IsTrue(b.Get(idx) == val);
					}
				}
				
				// test that the various ways of accessing the bits are equivalent
				DoGet(a, b);
				
                // {{dougsale-2.4.0}}
                //
                // Java's java.util.BitSet automatically grows as needed - i.e., when a bit is referenced beyond
                // the size of the BitSet, an exception isn't thrown - rather, the set grows to the size of the 
                // referenced bit.
                //
                // System.Collections.BitArray does not have this feature, and thus I've faked it here by
                // "growing" the array explicitly when necessary (creating a new instance of the appropriate size
                // and setting the appropriate bits).
                //

                // test ranges, including possible extension
                int fromIndex, toIndex;
                fromIndex = rand.Next(sz + 80);
                toIndex = fromIndex + rand.Next((sz >> 1) + 1);

                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSets 'a'
                // and 'aa' to the same cardinality as 'j+1' when 'a.Count < j+1' and 'fromIndex < toIndex':
                //BitArray aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j));
                // So, if necessary, lets explicitly grow 'a' now; then 'a' and its clone, 'aa', will be of the required size.
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    System.Collections.BitArray tmp = new System.Collections.BitArray(toIndex, false);
                    for (int k = 0; k < a.Count; k++)
                        tmp.Set(k, a.Get(k));
                    a = tmp;
                }
                // {{dougsale-2.4.0}}: now we can invoke this statement without going 'out-of-bounds'
                System.Collections.BitArray aa = (System.Collections.BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j));
                OpenBitSet bb = (OpenBitSet)b.Clone(); bb.Flip(fromIndex, toIndex);

                DoIterate(aa, bb, mode); // a problem here is from flip or doIterate

                fromIndex = rand.Next(sz + 80);
                toIndex = fromIndex + rand.Next((sz >> 1) + 1);
                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa'
                // when 'a.Count < j+1' and 'fromIndex < toIndex'
                //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
                // So, if necessary, lets explicitly grow 'aa' now
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    aa = new System.Collections.BitArray(toIndex);
                    for (int k = 0; k < a.Count; k++)
                        aa.Set(k, a.Get(k));
                }
                else
                {
                    aa = (System.Collections.BitArray)a.Clone();
                }
                for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
                bb = (OpenBitSet)b.Clone(); bb.Clear(fromIndex, toIndex);

                DoNextSetBit(aa, bb); // a problem here is from clear() or nextSetBit

                fromIndex = rand.Next(sz + 80);
                toIndex = fromIndex + rand.Next((sz >> 1) + 1);
                // {{dougsale-2.4.0}}:
                // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa'
                // when 'a.Count < j+1' and 'fromIndex < toIndex'
                //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false);
                // So, if necessary, lets explicitly grow 'aa' now
                if (a.Count < toIndex && fromIndex < toIndex)
                {
                    aa = new System.Collections.BitArray(toIndex);
                    for (int k = 0; k < a.Count; k++)
                        aa.Set(k, a.Get(k));
                }
                else
                {
                    aa = (System.Collections.BitArray)a.Clone();
                }
                for (int j = fromIndex; j < toIndex; j++) aa.Set(j, true);
                bb = (OpenBitSet)b.Clone(); bb.Set(fromIndex, toIndex);
				
				DoNextSetBit(aa, bb); // a problem here is from set() or nextSetBit     
				
				
				if (a0 != null)
				{
                    Assert.AreEqual(a.Equals(a0), b.Equals(b0));

                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a), b.Cardinality());

                    // {{dougsale-2.4.0}}
                    //
                    // The Java code used java.util.BitSet, which grows as needed.
                    // When a bit, outside the dimension of the set is referenced,
                    // the set automatically grows to the necessary size.  The
                    // new entries default to false.
                    //
                    // BitArray does not grow automatically and is not growable.
                    // Thus when BitArray instances of mismatched cardinality
                    // interact, we must first explicitly "grow" the smaller one.
                    //
                    // This growth is acheived by creating a new instance of the
                    // required size and copying the appropriate values.
                    //

                    //BitArray a_and = (BitArray)a.Clone(); a_and.And(a0);
                    //BitArray a_or = (BitArray)a.Clone(); a_or.Or(a0);
                    //BitArray a_xor = (BitArray)a.Clone(); a_xor.Xor(a0);
                    //BitArray a_andn = (BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);

                    System.Collections.BitArray a_and;
                    System.Collections.BitArray a_or;
                    System.Collections.BitArray a_xor;
                    System.Collections.BitArray a_andn;

                    if (a.Count < a0.Count)
                    {
                        // the Java code would have implicitly resized 'a_and', 'a_or', 'a_xor', and 'a_andn'
                        // in this case, so we explicitly create a resized stand-in for 'a' here, allowing for
                        // a to keep its original size while 'a_and', 'a_or', 'a_xor', and 'a_andn' are resized
                        System.Collections.BitArray tmp = new System.Collections.BitArray(a0.Count, false);
                        for (int z = 0; z < a.Count; z++)
                            tmp.Set(z, a.Get(z));

                        a_and = (System.Collections.BitArray)tmp.Clone(); a_and.And(a0);
                        a_or = (System.Collections.BitArray)tmp.Clone(); a_or.Or(a0);
                        a_xor = (System.Collections.BitArray)tmp.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)tmp.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
                    }
                    else if (a.Count > a0.Count)
                    {
                        // the Java code would have implicitly resized 'a0' in this case, so
                        // we explicitly do so here:
                        System.Collections.BitArray tmp = new System.Collections.BitArray(a.Count, false);
                        for (int z = 0; z < a0.Count; z++)
                            tmp.Set(z, a0.Get(z));
                        a0 = tmp;

                        a_and = (System.Collections.BitArray)a.Clone(); a_and.And(a0);
                        a_or = (System.Collections.BitArray)a.Clone(); a_or.Or(a0);
                        a_xor = (System.Collections.BitArray)a.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
                    }
                    else
                    {
                        // 'a' and 'a0' are the same size, no explicit growing necessary
                        a_and = (System.Collections.BitArray)a.Clone(); a_and.And(a0);
                        a_or = (System.Collections.BitArray)a.Clone(); a_or.Or(a0);
                        a_xor = (System.Collections.BitArray)a.Clone(); a_xor.Xor(a0);
                        a_andn = (System.Collections.BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false);
                    }

                    OpenBitSet b_and = (OpenBitSet)b.Clone(); Assert.AreEqual(b, b_and); b_and.And(b0);
                    OpenBitSet b_or = (OpenBitSet)b.Clone(); b_or.Or(b0);
                    OpenBitSet b_xor = (OpenBitSet)b.Clone(); b_xor.Xor(b0);
                    OpenBitSet b_andn = (OpenBitSet)b.Clone(); b_andn.AndNot(b0);

                    DoIterate(a_and, b_and, mode);
                    DoIterate(a_or, b_or, mode);
                    DoIterate(a_xor, b_xor, mode);
                    DoIterate(a_andn, b_andn, mode);

                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_and), b_and.Cardinality());
                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_or), b_or.Cardinality());
                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_xor), b_xor.Cardinality());
                    Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_andn), b_andn.Cardinality());

                    // test non-mutating popcounts
                    Assert.AreEqual(b_and.Cardinality(), OpenBitSet.IntersectionCount(b, b0));
                    Assert.AreEqual(b_or.Cardinality(), OpenBitSet.UnionCount(b, b0));
                    Assert.AreEqual(b_xor.Cardinality(), OpenBitSet.XorCount(b, b0));
                    Assert.AreEqual(b_andn.Cardinality(), OpenBitSet.AndNotCount(b, b0));
                }
				
				a0 = a;
				b0 = b;
			}
		}
Example #48
0
 public System.Collections.IEnumerable getEnum()
 {
     System.Collections.BitArray aryInx = new System.Collections.BitArray(diff);
     for (int i = 0; i < aryInx.Count; i++)
     {
         if (aryInx.Get(i))
             yield return (SCM_HW_Status_Bit_Enum)i;
     }
 }
Example #49
0
        public void SetEttuFail(DateTime dt, byte[] f)
        {
            bool isChange = false;

               byte[] xor_f = new byte[f.Length];

               try
               {
               for (int i = 0; i < f.Length; i++)
               {
                   xor_f[i] = (byte)(this.f[i] ^ f[i]);
                   if (xor_f[i] != 0)
                       isChange = true;
               }

               if (isChange)
               {
                   string sql = "update tblETConfig set f1={0},f2={1},f3={2} where devicename='{3}'";
                   Program.mfcc_ettu.ExecuteSql(string.Format(sql,  f[0], f[1], f[2], m_devicename));
               }
               string timeStamp = Comm.DB2.Db2.getTimeStampString(dt);
               System.Collections.BitArray xorBitmap = new System.Collections.BitArray(xor_f);
               System.Collections.BitArray fBitmap = new System.Collections.BitArray(f);
               for (int i = 0; i < xor_f.Length * 8; i++)
               {

                   string sql = "insert into tblEtStatelog (devicename,timestamp,type,failno,result) values('{0}','{1}','{2}',{3},{4})";
                   if (xorBitmap.Get(i))
                   {
                       Program.mfcc_ettu.ExecuteSql(string.Format(sql, this.m_devicename, timeStamp, "F", i, fBitmap.Get(i) ? 1 : 0));

                   }

               }

               }
               catch (Exception ex)
               {
               RemoteInterface.ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
               }
               finally
               {
               this.f = f;
               this.x = f;
               }
        }
        private static void AppendOneOrMoreToEnd(StringBuilder pattern, BitArray requiredPatterns, List<string> patterns, int startIndex)
        {
            if (startIndex < 0)
                throw new ArgumentOutOfRangeException("startIndex cannot be negative", "startIndex");
            if (startIndex >= patterns.Count)
                throw new ArgumentException("startIndex cannot be greater than the number of patterns.", "startIndex");

            pattern.Append("(?:");

            if (requiredPatterns.Get(startIndex))
            {
                // include the required first item
                pattern.Append(patterns[startIndex]);

                if (startIndex < patterns.Count - 1)
                {
                    // optionally include at least one more from there to the end
                    pattern.Append("(?:,");
                    AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
                    pattern.Append(")?");
                }
            }
            else
            {
                if (startIndex < patterns.Count - 1)
                {
                    // include the first item and at least one more from there to the end
                    pattern.Append(patterns[startIndex]).Append(",");
                    AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
                    pattern.Append("|");
                }

                // include the first item alone
                pattern.Append(patterns[startIndex]);

                if (startIndex < patterns.Count - 1)
                {
                    // don't include the first item, but do include one or more to the end
                    pattern.Append("|");
                    AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
                }
            }

            pattern.Append(")");
        }
Example #51
0
        /// <summary>  Builds the initial extension set. This is the
        /// set of node tha may be used as seed for the
        /// RGraph parsing. This set depends on the constrains
        /// defined by the user.
        /// </summary>
        /// <param name="c1"> constraint in the graph G1
        /// </param>
        /// <param name="c2"> constraint in the graph G2
        /// </param>
        /// <returns>     
        /// </returns>
        private System.Collections.BitArray buildB(System.Collections.BitArray c1, System.Collections.BitArray c2)
        {
            this.c1 = c1;
            this.c2 = c2;

            System.Collections.BitArray bs = new System.Collections.BitArray(64);

            // only nodes that fulfill the initial constrains
            // are allowed in the initial extension set : B
            //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
            for (System.Collections.IEnumerator i = graph.GetEnumerator(); i.MoveNext(); )
            {
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                RNode rn = (RNode)i.Current;

                if ((c1.Get(rn.rMap.id1) || isEmpty(c1)) && (c2.Get(rn.rMap.id2) || isEmpty(c2)))
                {
                    SupportClass.BitArraySupport.Set(bs, graph.IndexOf(rn));
                }
            }
            return bs;
        }
Example #52
0
        public void DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            _TempString += Port.ReadExisting();

            //Get number of samples on meter
            if (!_NumResultsRead && (_TempString.Contains(Statics.GetStringFromAsciiCode((byte)AsciiCodes.ENQ)) || _TempString.Contains(Statics.GetStringFromAsciiCode((byte)AsciiCodes.ACK))))
            {
                switch (_CountStep)
                {
                    case 0: Port.Write(new byte[] { 0x15 }, 0, 1);
                        _CountStep++;
                        break;
                    case 1: Port.Write(new byte[] { 0x05 }, 0, 1);
                        _CountStep++;
                        break;
                    case 2: Port.Write("R|");
                        _CountStep++;
                        break;
                    case 3: Port.Write("M|");
                        _CountStep++;
                        break;
                    case 4: Port.Write(new byte[] { 0x39, 0x37, 0x0d, 0x0a }, 0, 4);
                        _CountStep++;
                        System.Threading.Thread.Sleep(1000);
                        break;
                    case 5: _NumResultsRead = true;
                        try
                        {
                            byte[] temp = Statics.StrToByteArray(_TempString);
                            string tempCount = _TempString.Substring(_TempString.IndexOf("|") + 1, _TempString.LastIndexOf("|") - _TempString.IndexOf("|") - 1);
                            SampleCount = Convert.ToInt32(tempCount);
                            Port.Write(new byte[] { 0x04 }, 0, 1);
                            _TempString = string.Empty;
                            _CountStep = 0;
                            System.Threading.Thread.Sleep(100);
                        }
                        catch
                        {
                            Port.DataReceived += null;
                            Port.DiscardInBuffer();
                            Port.DiscardOutBuffer();
                            _TestFailed = true;
                            return;
                        }
#if DEBUG
                        Console.WriteLine("SampleCount: " + SampleCount);
#endif
                        break;
                    default: break;
                }//switch

                return;
            }//if
            else if (_NumResultsRead && !_ConfigRead && (_TempString.Contains(Statics.GetStringFromAsciiCode((byte)AsciiCodes.ENQ)) || _TempString.Contains(Statics.GetStringFromAsciiCode((byte)AsciiCodes.ACK))))
            {
                switch (_CountStep)
                {
                    case 0: Port.Write(new byte[] { 0x15 }, 0, 1);
                        _CountStep++;
                        break;
                    case 1: Port.Write(new byte[] { 0x05 }, 0, 1);
                        _CountStep++;
                        break;
                    case 2: Port.Write("R|");
                        _CountStep++;
                        break;
                    case 3: Port.Write("C|");
                        _CountStep++;
                        break;
                    case 4: Port.Write(new byte[] { 0x38, 0x44, 0x0d, 0x0a }, 0, 4);
                        _CountStep++;
                        System.Threading.Thread.Sleep(1000);
                        break;
                    case 5: _ConfigRead = true;
                        try
                        {
                            string[] splitData = _TempString.Split(new char[] { '|' });
                            System.Collections.BitArray bitary = new System.Collections.BitArray(Byte.Parse(splitData[1]));
                            SampleFormat = (bitary.Get(2)) ? SampleFormat.MMOL : SampleFormat.MGDL;
                            Port.Write(new byte[] { 0x04 }, 0, 1);
                            _CountStep = 0;
                            _TempString = string.Empty;
                        }
                        catch
                        {
                            Port.DataReceived += null;
                            Port.DiscardInBuffer();
                            Port.DiscardOutBuffer();
                            _TestFailed = true;
                            return;
                        }
#if DEBUG
                        Console.WriteLine("SampleFormat: " + SampleFormat.ToString());
#endif
                        break;
                    default: break;
                }//switch

                return;
            }//else
            //if data received is the ENQ to start communications
            else if (!_HeaderRead && _TempString.Contains(Statics.GetStringFromAsciiCode((byte)AsciiCodes.ENQ)))
            {
                Port.Write(Statics.GetStringFromAsciiCode((byte)AsciiCodes.ACK));

                RawData += _TempString;
                _TempString = String.Empty;

                return;
            }//if

            //if data contains an STX and a following LF then a full frame can be trimmed
            else if (_TempString.Contains(Statics.GetStringFromAsciiCode((byte)AsciiCodes.STX)) && _TempString.Substring(_TempString.IndexOf(Statics.GetStringFromAsciiCode((byte)AsciiCodes.STX))).Contains(Statics.GetStringFromAsciiCode((byte)AsciiCodes.LF)))
            {
                RawData += _TempString;

                //full frame encountered (cut out full frame, and remove the STX on the front)
                string fullframe = _TempString.Split(new string[] { Statics.GetStringFromAsciiCode((byte)AsciiCodes.CR) }, StringSplitOptions.None)[0].Replace(Statics.GetStringFromAsciiCode((byte)AsciiCodes.STX), "");

                //trim off the frame as more data may be in the buffer
                _TempString = _TempString.Substring(_TempString.LastIndexOf(Statics.GetStringFromAsciiCode((byte)AsciiCodes.LF)) + 1);

                #region HeaderRecord
                if (fullframe[1] == 'H')
                {
                    _HeaderRead = true;
                    string[] headerrecord = fullframe.Split(new char[] { '|' });
                    string[] typeandserial = headerrecord[4].Split(new char[] { '^' });

                    string accesspassword = headerrecord[3];
                    string softwareversion = typeandserial[1].Split(new char[] { '\\' })[0];
                    string eepromversion = typeandserial[1].Split(new char[] { '\\' })[1];
                    MeterDescription = typeandserial[0];

                    string MeterType = typeandserial[0];
                    SerialNumber = typeandserial[2];

                    //breeze meters have a product number of 6115
                    _MeterFound = (MeterType.ToLowerInvariant() == "bayer6115");

                    if (_TestMode)
                    {
                        Port.DataReceived += null;
                        return;
                    }

                    OnHeaderRead(new HeaderReadEventArgs(SampleCount, this));

                    Console.WriteLine("Header: " + fullframe);
                }//if
                #endregion

                #region Glucose Record
                else if (fullframe[1] == 'R')
                {
                    string[] splitrecord = fullframe.Split(new char[] { '|' });

                    //only if glucose record
                    if (splitrecord.Length > 10)
                    {
                        int year = int.Parse(splitrecord[11].Substring(0, 4));
                        int month = int.Parse(splitrecord[11].Substring(4, 2));
                        int day = int.Parse(splitrecord[11].Substring(6, 2));
                        int hour = int.Parse(splitrecord[11].Substring(8, 2));
                        int minute = int.Parse(splitrecord[11].Substring(10, 2));
                        int glucose = int.Parse(splitrecord[3]);
                        string units = splitrecord[4].Split(new char[] { '^' })[0];

                        DateTime dtTimeStamp = new DateTime(year, month, day, hour, minute, 0);

                        //put the record in the dataset and raise the read event
                        try
                        {
                            if (Records.FindByTimestamp(dtTimeStamp) == null)
                            {
#if DEBUG
                                Console.WriteLine("Record: " + fullframe);
#endif
                                OnRecordRead(new RecordReadEventArgs(this._Records.AddRecordRow(dtTimeStamp, glucose, units)));
                            }//if
                            else
                            {
#if DEBUG
                                Console.WriteLine("DUPLIC: " + fullframe);
#endif
                            }//else
                        }//try
                        catch
                        {
                        }//catch
                    }//if
                }//elseif
                #endregion
            }//else

            //end of transmission encountered after a header record is read
            else if (_HeaderRead && _TempString.Contains(Statics.GetStringFromAsciiCode((byte)AsciiCodes.EOT)))
            {
                _HeaderRead = false;
                Port.DataReceived -= new System.IO.Ports.SerialDataReceivedEventHandler(DataReceived);
                OnReadFinished(new ReadFinishedEventArgs(this));
                Close();
                Dispose();
                return;
            }//elseif

            //send response
            if (_NumResultsRead)
                Port.Write(Statics.GetStringFromAsciiCode((byte)AsciiCodes.ACK));
        }