コード例 #1
0
 public void AppendWaitForValueRising(byte channel, UInt16 latency, UInt16 targetValue)
 {
     bl.Add(9);
     bl.Add(channel);
     bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(latency));
     bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(targetValue));
 }
コード例 #2
0
        public void AppendWaitForValueRising(byte channel, UInt16 latency, float targetValue)
        {
            // targt value is given in mV
            if (targetValue < 0)
            {
                targetValue = 0;
            }

            if (targetValue > 3300)
            {
                targetValue = 3300 - delta;
            }

            /*
             * maxValue = 32767
             *
             *
             * signed int offsetCorrectedValue = (signed int)rawData - SDOffset;
             * signed int offsetCorrectedValue = (signed int)rawData;
             * Now gain correction
             * float offsetAndGainValue = (float)offsetCorrectedValue * SDGain;
             * ADC is 15bits plus sign bit which are 32767 different values
             * currentValue/maxPossibleValue = x/3300  in mV
             * float fValue = offsetAndGainValue*3300/32768;
             *
             * offsetAndGainValue = fValue * 32768 / 3300
             */
            // Now convert to uint16
            UInt16 uValue = (UInt16)(targetValue * 32768 / 3300);

            bl.Add(9);
            bl.Add(channel);
            bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(latency));
            bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(uValue));
        }
コード例 #3
0
 public void AppendReadFromAddress(int address, int numOfBytes)
 {
     bl.Add(6);
     // Append address
     byte[] bAddress = CustomConvertorClass.ConvertIntTo4Bytes(address);
     bl.AddRange(bAddress);
     // Get and append length
     byte[] bLen = CustomConvertorClass.ConvertIntTo2Bytes(numOfBytes);
     bl.AddRange(bLen);
 }
コード例 #4
0
        /// <summary>
        /// Calculate checksum, and append it at the end of message
        /// </summary>
        /// <returns></returns>
        public byte[] GetFinalCommandList()
        {
            var num = bl.Count;

            // First 2 bytes are skipped but checksum should be counted so overall length is unchanged, +2 - 2 = 0
            bl.InsertRange(2, CustomConvertorClass.ConvertIntTo2Bytes(num));

            UInt16 csum = ChecksumClass.CalculateChecksum(bl.ToArray());

            bl.AddRange(CustomConvertorClass.ConvertIntTo2BytesBE(csum));

            return(bl.ToArray());
        }
コード例 #5
0
        /// <summary>
        /// Remove checksum from data packet, and updates data length accordingly
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static byte[] RemoveChecksumFromMessage(byte[] msg)
        {
            // Copy whole array except last two bytes
            byte[] newMsg = new byte[msg.Length - 2];

            for (int i = 0; i < newMsg.Length; i++)
            {
                newMsg[i] = msg[i];
            }

            // Remove checksum count from message header
            int len = newMsg.Length - 2; // number of data bytes

            byte[] temp = CustomConvertorClass.ConvertIntTo2Bytes(len);
            newMsg[0] = temp[1];
            newMsg[1] = temp[0];

            return(newMsg);
        }
コード例 #6
0
        public void SetCutoffValueCH1(float targetValue)
        {
            // targt value is given in mV

            if (targetValue > 3300)
            {
                targetValue = 3300 - delta;
            }
            else if (targetValue < 0)
            {
                targetValue = 0;
            }
            targetValue = targetValue * 32768 / 3300;
            // Now convert to uint16
            UInt16 uValue = (UInt16)(targetValue);

            bl.Add(31);
            bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(uValue));
        }
コード例 #7
0
        public void AppendSetCriticalLow(float targetValue, byte channel)
        {
            // targt value is given in mV
            if (targetValue > 3300)
            {
                targetValue = 3300 - delta;
            }
            else if (targetValue < 0)
            {
                targetValue = 0;
            }

            // Now convert to uint16
            UInt16 uValue = (UInt16)(targetValue * 32768 / 3300);


            bl.Add(11);
            bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(uValue));
            bl.Add(channel);
        }
コード例 #8
0
        public void AppendWaitForValueFalling(byte channel, UInt16 latency, float targetValue)
        {
            // targt value is given in mV
            if (targetValue < 0)
            {
                targetValue = 0;
            }

            if (targetValue > 3300)
            {
                targetValue = 3300 - delta;
            }

            // Now convert to uint16
            UInt16 uValue = (UInt16)(targetValue * 32768 / 3300);

            bl.Add(10);
            bl.Add(channel);
            bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(latency));
            bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(uValue));
        }
コード例 #9
0
 public void SetCutoffValueCH1(ushort uValue)
 {
     bl.Add(31);
     bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(uValue));
 }
コード例 #10
0
 public void AppendSetCriticalHigh(UInt16 targetValue, byte channel)
 {
     bl.Add(12);
     bl.AddRange(CustomConvertorClass.ConvertIntTo2Bytes(targetValue));
     bl.Add(channel);
 }