Esempio n. 1
0
        public int GetMotionSts(int id, int axis, ref int sts)
        {
            lock (this)
            {
                sts = 0;

                if (!CardAxisMotion[axis].Mdn)
                {
                    BitOperators.CLEAR_BITS(ref sts, MotionAxisDefine.MOTION_STS_MDN);
                }
                else
                {
                    BitOperators.SET_BITS(ref sts, MotionAxisDefine.MOTION_STS_MDN);
                }

                //if (_cardAxisMotion[axis].Astp || _cardAxisMotion[axis].Mel || _cardAxisMotion[axis].Pel || !_cardAxisMotion[axis].Servo)
                //{
                //    BitOperators.SET_BITS(ref sts, MotionAxisDefine.MOTION_STS_ASTP);
                //}
                //else
                //{
                //    BitOperators.CLEAR_BITS(ref sts, MotionAxisDefine.MOTION_STS_ASTP);
                //}

                return(0);
            }
        }
Esempio n. 2
0
        internal string ReadText(ChannelUsage usage, bool returnFilteredText = true, bool useThreads = true)
        {
            var values = new bool[usage.GetTotaleUsage() * _inputData.Size];
            var usages = usage.GetUsages();

            var numThreads   = useThreads ? _inputData.Size >> _threadSizeModifier | 1 : 1;
            var threadLength = _inputData.Size / numThreads;

            var threads = new Thread[numThreads];

            for (var i = 0; i < numThreads; i++)
            {
                var reader = new ReaderThread(_inputData, usages, values, i * threadLength, threadLength);
                threads[i] = new Thread(reader.ReadBooleans);
                threads[i].Start();
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            var bytes = BitOperators.BitsToBytes(values);
            var text  = Encoding.UTF8.GetString(bytes);

            return(returnFilteredText ? FindOriginalText(text) : text);
        }
Esempio n. 3
0
        internal void ReadBooleans()
        {
            var count = 0;

            for (var index = _startPosition; index < _startPosition + _length; index++)
            {
                if (_picture.Size < index)
                {
                    return;
                }

                for (var channelIndex = 0; channelIndex < 4; channelIndex++)
                {
                    var chnUsage = _usages[channelIndex];

                    for (var positionIndex = 0; positionIndex < chnUsage; positionIndex++)
                    {
                        var byteVal = _picture.GetPixelChannel(index, (Channel)channelIndex);
                        var bitVal  = BitOperators.ReadOutByte(byteVal, positionIndex, 1, true);

                        _targetArray[_startPosition + count] = bitVal == 1;
                        count++;
                    }
                }
            }
        }
Esempio n. 4
0
        internal void InsertText(string text, ChannelUsage usage, bool useTags = true)
        {
            if (useTags)
            {
                text = "<start>" + text + "<end>";
            }

            //counters
            var pixelIndex    = 0;
            var channelIndex  = 0;
            var positionIndex = 0;

            //other info
            var currentChannelUsage = usage.GetChannelUsage(0);

            var bytes = Encoding.UTF8.GetBytes(text.ToCharArray());

            for (var bitIndex = 0; bitIndex < bytes.Length * 8; bitIndex++, positionIndex++)
            {
                //get correct position
                while (positionIndex >= currentChannelUsage)
                {
                    channelIndex++;
                    positionIndex = 0;
                    if (channelIndex >= 4)
                    {
                        pixelIndex++;
                        channelIndex = 0;
                    }
                    currentChannelUsage = usage.GetChannelUsage((Channel)channelIndex);
                }

                //insert
                int data = _workingData.GetPixelChannel(pixelIndex, (Channel)channelIndex);

                var valByte = bytes[bitIndex >> 3];
                var val     = BitOperators.ReadOutByte(valByte, 7 ^ (bitIndex & 7), 1, true) == 1;

                var result = BitOperators.InsertBit((byte)data, positionIndex, val);

                _workingData.SetPixelChannel(pixelIndex, (Channel)channelIndex, result);
            }
        }
Esempio n. 5
0
        public int GetMotionIO(int id, int axis, ref int sts)
        {
            lock (this)
            {
                sts = 0;

                if (CardAxisMotion[axis].Alarm)
                {
                    BitOperators.SET_BITS(ref sts, MotionAxisDefine.MOTION_IO_ALM);
                }
                else
                {
                    BitOperators.CLEAR_BITS(ref sts, MotionAxisDefine.MOTION_IO_ALM);
                }

                if (CardAxisMotion[axis].Pel)
                {
                    BitOperators.SET_BITS(ref sts, MotionAxisDefine.MOTION_IO_PEL);
                }
                else
                {
                    BitOperators.CLEAR_BITS(ref sts, MotionAxisDefine.MOTION_IO_PEL);
                }

                if (CardAxisMotion[axis].Mel)
                {
                    BitOperators.SET_BITS(ref sts, MotionAxisDefine.MOTION_IO_MEL);
                }
                else
                {
                    BitOperators.CLEAR_BITS(ref sts, MotionAxisDefine.MOTION_IO_MEL);
                }

                if (CardAxisMotion[axis].Org)
                {
                    BitOperators.SET_BITS(ref sts, MotionAxisDefine.MOTION_IO_ORG);
                }
                else
                {
                    BitOperators.CLEAR_BITS(ref sts, MotionAxisDefine.MOTION_IO_ORG);
                }

                if (CardAxisMotion[axis].Astp)
                {
                    BitOperators.SET_BITS(ref sts, MotionAxisDefine.MOTION_IO_EMG);
                }
                else
                {
                    BitOperators.CLEAR_BITS(ref sts, MotionAxisDefine.MOTION_IO_EMG);
                }

                if (CardAxisMotion[axis].Servo)
                {
                    BitOperators.SET_BITS(ref sts, MotionAxisDefine.MOTION_IO_SVON);
                }
                else
                {
                    BitOperators.CLEAR_BITS(ref sts, MotionAxisDefine.MOTION_IO_SVON);
                }

                return(0);
            }
        }