Example #1
0
        private List <int> RegToIntList(uint rtReg)
        {
            ushort enValue;

            enValue = ReadShortReg(rtReg);
            return(RTConverters.UInt16ToIntList(enValue));
        }
Example #2
0
        private void IntListToReg(uint rtReg, List <int> setBits)
        {
            ushort wValue;

            wValue = RTConverters.IntListToUInt16(setBits);
            WriteShortReg(rtReg, wValue);
        }
Example #3
0
        /// <summary>
        /// Read the sample data from the tag using specified antenna.
        /// </summary>
        /// <param name="fromAntenna">The antenna to use. If the value is -1 the the antenna selection is made by the module.</param>
        /// <returns>Return the sample data from the tag if available.</returns>
        /// <exception cref="FormatException">Exception can be thrown if there is no sample data available.</exception>
        public RTConst.SAMPLEDATA GetSamples(int fromAntenna)
        {
            ushort[]      tmp;
            List <double> dTemp;

            RTConst.SAMPLEDATA ret;

            dTemp = new List <double>();
            tmp   = GetRawSamples(fromAntenna);

            if (tmp == null || tmp.Length == 0)
            {
                throw new FormatException("RT0005::GetAllSamples: no samples found");
            }

            // The application needs to catch if invalid value is found...
            foreach (ushort w in tmp)
            {
                dTemp.Add(RTConverters.FixedToDouble(w));
            }

            ret = new RTConst.SAMPLEDATA();

            ret.values = dTemp.ToArray();

            ret.min = RTConverters.FindMinTemp(ret.values);
            ret.max = RTConverters.FindMaxTemp(ret.values);

            return(ret);
        }
Example #4
0
        private void ByteArrToUshort(byte[] src, ushort[] dest, int destOffset)
        {
            int i;

            for (i = 0; i < src.Length; i += 2)
            {
                dest[destOffset++] = RTConverters.BytesToUInt16(src, i);
            }
        }
Example #5
0
        /// <summary>
        /// Read a 32-bit register value.
        /// </summary>
        /// <param name="rtReg">Register pair's  (2 x 16-bit register) address</param>
        /// <returns>The 32-bit register value.</returns>
        /// <remarks>The result is in little-endian format so there is no need to do any additional conversions.</remarks>
        /// <exception cref="NurApiException">
        /// <para>This exception is thrown when the underlying physical read fails.</para>
        /// <para>Exception can also be thrown if the tag reports an error e.g. "out of range"</para>
        /// </exception>
        /// <exception cref="IndexOutOfRangeException">This exception is thrown if the read is out of the register address space.</exception>
        public uint ReadUInt32Reg(uint rtReg)
        {
            RTConst.RegRangeCheck(rtReg, "ReadUInt32Reg", RTConst.RW_32BIT);

            byte[] b;

            b = ReadTag(mPassword, mSecured, NurApi.BANK_USER, rtReg, 4);

            return(RTConverters.BytesToUInt32(b));
        }
Example #6
0
        /// <summary>
        /// Write a single 16-bit register.
        /// </summary>
        /// <param name="rtReg">Register to write, <seealso cref="RTRegs"/>.</param>
        /// <param name="wValue">Value to write.</param>
        /// <remarks>
        /// <para>See also: <seealso cref="Secured"/>, <seealso cref="Password"/></para>
        /// <para>The data to write is internally converted to the tag's big-endian format so there is no need for additional conversions.</para>
        /// </remarks>
        /// <exception cref="NurApiException">
        /// <para>This exception is thrown when the underlying physical write fails.</para>
        /// <para>Exception can also be thrown if the tag reports an error e.g. "out of range"</para>
        /// </exception>
        public void WriteShortReg(uint rtReg, ushort wValue)
        {
            RTConst.RegRangeCheck(rtReg, "WriteShortReg", RTConst.RW_16BIT);

            byte[] b;

            b = RTConverters.UInt16ToBytes(wValue);

            WriteTag(mPassword, mSecured, NurApi.BANK_USER, rtReg, b);
        }
Example #7
0
        /// <summary>
        /// Read a 16-bit register.
        /// </summary>
        /// <param name="rtReg">Register value to read, <seealso cref="RTRegs"/>.</param>
        /// <returns>This call returns the 16-bit value of the register.</returns>
        /// <remarks>NOTE: this result is internally converted to little-endian format; no need to re-convert.</remarks>
        /// <exception cref="NurApiException">
        /// <para>This exception is thrown when the underlying physical read fails.</para>
        /// <para>Exception can also be thrown if the tag reports an error e.g. "out of range"</para>
        /// </exception>
        public ushort ReadShortReg(uint rtReg)
        {
            RTConst.RegRangeCheck(rtReg, "ReadShortReg", RTConst.RW_16BIT);

            byte[] b;

            b = ReadTag(mPassword, mSecured, NurApi.BANK_USER, rtReg, 2);

            return(RTConverters.BytesToUInt16(b));
        }
Example #8
0
        /// <summary>
        /// Read multiple 16-bit registers at once.
        /// </summary>
        /// <param name="firstAddr">First register to read, <seealso cref="RTRegs"/>.</param>
        /// <param name="regCount">Number of registers to read.</param>
        /// <returns>An array of unsigned 16-bit register that were read.</returns>
        /// <remarks></remarks>
        /// <exception cref="NurApiException">This exception is thrown when the underlying physical read fails.</exception>
        /// <exception cref="RTException">
        /// <para>This exception is thrown when the number of registers is out of range, <seealso cref="RTConst.MIN_RD_COUNT"/>, <seealso cref="RTConst.MAX_RD_COUNT"/>.</para>
        /// </exception>
        /// <exception cref="RTException">
        /// <para>This exception is thrown if the total reading exceeds the last memory position, <seealso cref="RTConst.LOG_AREA_LAST"/></para>
        /// </exception>
        public ushort [] ReadMultipleRegs(uint firstAddr, int regCount)
        {
            RTConst.RegRangeCheck(firstAddr, "ReadMultipleRegs", RTConst.RW_16BIT);
            RTConst.RegRangeCheck((uint)(firstAddr + regCount), "ReadMultipleRegs: read length is out of range.", RTConst.RW_16BIT);
            RTConst.RWCountCheck(regCount, "ReadMultipleRegs");

            byte [] data;

            data = ReadTag(mPassword, mSecured, NurApi.BANK_USER, firstAddr, (regCount * 2));

            return(RTConverters.BytesToUInt16Arr(data));
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startDelay"></param>
        /// <param name="samplingInterval"></param>
        public void StartSimpleLog(RTConst.LOGINTERVAL startDelay, RTConst.LOGINTERVAL samplingInterval)
        {
            ushort wIntVal = 0;
            ushort wDelay  = 0;

            List <int> enList = new List <int>();

            if (samplingInterval == RTConst.LOGINTERVAL.INT_NONE)
            {
                throw new RTException("StartSimpleLog: interval cannot be 0.");
            }

            wIntVal = RTConverters.IntervalToUIn16(samplingInterval);
            wDelay  = RTConverters.IntervalToUIn16(startDelay);

            ResetAll();

            try
            {
                BINLimit[0]      = RTConst.FIXED_70LIM;
                BINThreshold[0]  = RTConst.FIXED_MINUS20LIM;
                BINSampleTime[0] = wIntVal;
            }
            catch
            {
                throw new RTException("StartSimpleLog: BIN setup failed.");
            }

            enList.Add(0);

            try
            {
                BINEnable       = enList;
                BINEnableSample = enList;
            }
            catch
            {
                throw new RTException("StartSimpleLog: BIN enable failed.");
            }

            /* Disable time stamp store */
            try
            {
                WriteShortReg(RTRegs.BIN_ENA_TIME_STORE, 0);
            }
            catch
            {
                throw new RTException("StartSimpleLog: timestamp store disable failed.");
            }

            try
            {
                /* Setup delay time */
                if (wDelay == 0)                        // Disable ?
                {
                    int dummy = RTConst.CTL_DLYEN_MASK;
                    dummy            = ~dummy;
                    ControlRegister &= (ushort)(dummy);
                }
                else
                {
                    ControlRegister |= RTConst.CTL_DLYEN_MASK;
                }
            }
            catch
            {
                throw new RTException("StartSimpleLog: start delay control failed.");
            }

            try
            {
                WriteShortReg(RTRegs.SAMPLING_DELAY, wDelay);
            }
            catch
            {
                throw new RTException("StartSimpleLog: writing sampling delay failed.");
            }

            /* Start logging. */
            try
            {
                ResetStart();
            }
            catch
            {
                throw new RTException("StartSimpleLog: reset + start failed.");
            }
        }
Example #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <param name="wData"></param>
 public void SetReservedExtra(uint offset, ushort wData)
 {
     byte[] bData = RTConverters.UInt16ToBytes(wData);
     WriteTag(mPassword, mSecured, NurApi.BANK_PASSWD, RTConst.PASSWD_EXTRA_ADDR + offset, bData);
 }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="offset"></param>
 /// <returns></returns>
 public ushort GetReservedExtra(uint offset)
 {
     byte [] bData = ReadTag(mPassword, mSecured, NurApi.BANK_PASSWD, RTConst.PASSWD_EXTRA_ADDR + offset, 2);
     return(RTConverters.BytesToUInt16(bData));
 }