Ejemplo n.º 1
0
 public void Connect(string serverIP, int serverPort, MessageBase messageProtocol, DecodeMode mode = DecodeMode.QueueWaite)
 {
     if (socket != null)
     {
         Debug.Error("该网络类已被使用无法用以客户端连接"); return;
     }
     socket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     protocol = messageProtocol;
     try
     {
         decodeMode = mode;
         if (decodeMode == DecodeMode.QueueWaite)
         {
             decodeQueue = new Queue <Connection>();
         }
         socket.Connect(serverIP, serverPort);
         server = new Connection();
         server.Init(socket);
         socket.BeginReceive(server.readBuff, 0, Connection.BUFFER_SIZE, SocketFlags.None, ReceiveCallBack, server);
         Debug.SafeLog("链接服务器成功 接受消息中...");
     }
     catch (Exception ex)
     {
         Debug.Log(ex.ToString());
     }
 }
        public string Peek(DecodeMode mode)
        {
            switch (mode)
            {
            case DecodeMode.Numbers:
                return(GenerateNumberRange(OriginalText.Length));

            case DecodeMode.Hide:
                if (_visibleCount == 0)
                {
                    return(null);
                }

                _visibleCount--;
                break;

            case DecodeMode.Show:
                if (_visibleCount == OriginalText.Length)
                {
                    return(null);
                }

                _visibleCount++;
                break;
            }

            var text = GenerateNumberRange(OriginalText.Length - _visibleCount);

            text += OriginalText.Substring(OriginalText.Length - _visibleCount, _visibleCount);

            return(text);
        }
Ejemplo n.º 3
0
        public void StartServer(string serverIP, int serverPort, int maxConnect, MessageBase messageProtocol, DecodeMode mode = DecodeMode.QueueWaite)
        {
            if (socket != null)
            {
                Debug.Error("该网络类已被使用无法以服务器模式启动"); return;
            }
            protocol   = messageProtocol;
            decodeMode = mode;
            if (decodeMode == DecodeMode.QueueWaite)
            {
                decodeQueue = new Queue <Connection>();
            }
            DecodeMethod["Network"] = DecodeNetworkMessage;
            connectionPool          = new ObjectPool <Connection>(maxConnect);

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress address = IPAddress.Parse(serverIP);

            socket.Bind(new IPEndPoint(address, serverPort));
            socket.Listen(maxConnect);
            socket.BeginAccept(AcceptCallBack, socket);
            Debug.SafeLog("服务器启动成功 接受消息中...");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads a FIT binary File
        /// </summary>
        /// <param name="fitStream">Seekable (file)stream to parse.</param>
        /// <param name="mode">Decode Mode to use for reading the file</param>
        /// <returns>
        /// Returns true if reading finishes successfully.
        /// </returns>
        public bool Read(Stream fitStream, DecodeMode mode)
        {
            bool readOK       = true;
            long fileSize     = 0;
            long filePosition = fitStream.Position;

            try
            {
                // Attempt to read header
                if (mode == DecodeMode.Normal)
                {
                    fileHeader = new Header(fitStream);
                    readOK    &= fileHeader.IsValid();

                    // Get the file size from the header
                    // When the data size is invalid set the file size to the fitstream length
                    if (!invalidDataSize)
                    {
                        fileSize = fileHeader.Size + fileHeader.DataSize + CRCSIZE;
                    }
                    else
                    {
                        fileSize = fitStream.Length;
                    }

                    if (!readOK)
                    {
                        throw new FitException("FIT decode error: File is not FIT format. Check file header data type. Error at stream position: " + fitStream.Position);
                    }
                    if ((fileHeader.ProtocolVersion & Fit.ProtocolVersionMajorMask) > (Fit.ProtocolMajorVersion << Fit.ProtocolVersionMajorShift))
                    {
                        // The decoder does not support decode accross protocol major revisions
                        throw new FitException(String.Format("FIT decode error: Protocol Version {0}.X not supported by SDK Protocol Ver{1}.{2} ", (fileHeader.ProtocolVersion & Fit.ProtocolVersionMajorMask) >> Fit.ProtocolVersionMajorShift, Fit.ProtocolMajorVersion, Fit.ProtocolMinorVersion));
                    }
                }
                else if (mode == DecodeMode.InvalidHeader)
                {
                    // When skipping the header force the stream position to be at the beginning of the data
                    // Also the fileSize is the length of the filestream.
                    fitStream.Position += Fit.HeaderWithCRCSize;
                    fileSize            = fitStream.Length;
                }
                else if (mode == DecodeMode.DataOnly)
                {
                    // When the stream is only data move the position of the stream
                    // to the start. FileSize is the length of the stream
                    fitStream.Position = 0;
                    fileSize           = fitStream.Length;
                }
                else
                {
                    throw new FitException("Invalid Decode Mode Provided to read");
                }

                // Read data messages and definitions
                while (fitStream.Position < (filePosition + fileSize - CRCSIZE))
                {
                    DecodeNextMessage(fitStream);
                }

                // Is the file CRC ok?
                if ((mode == DecodeMode.Normal) && !invalidDataSize)
                {
                    byte[] data = new byte[fileSize];
                    fitStream.Position = filePosition;
                    fitStream.Read(data, 0, data.Length);
                    readOK            &= (CRC.Calc16(data, data.Length) == 0x0000);
                    fitStream.Position = filePosition + fileSize;
                }
            }
            catch (EndOfStreamException e)
            {
                readOK = false;
                Debug.WriteLine("{0} caught and ignored. ", e.GetType().Name);
                throw new FitException("Decode:Read - Unexpected End of File at stream position" + fitStream.Position, e);
            }
            catch (FitException e)
            {
                // When attempting to decode files with invalid data size this indicates the EOF.
                if (!invalidDataSize)
                {
                    throw e;
                }
            }
            return(readOK);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Sets the mode to decode the image with
 /// </summary>
 /// <param name="mode"><see cref="DecodeMode"/></param>
 public void SetDecodeMode(DecodeMode mode)
 {
     NativeCalls.SetDecodeMode(_context, mode);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Set MAX7219 Decode Mode
 /// </summary>
 /// <param name="mode">Mode</param>
 public void SetDecode(DecodeMode mode)
 {
     led.Write(new byte[] { MAX_DECODE_REG_ADDR, (byte)mode });
 }
Ejemplo n.º 7
0
 public MAX7219(int chipSelect, DecodeMode decodeMode)
 {
     this.chipSelect = chipSelect;
     this.decodeMode = decodeMode;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Set MAX7219 Decode Mode
 /// </summary>
 /// <param name="decodeMode">Mode</param>
 public void SetDecode(DecodeMode decodeMode)
 {
     this.decodeMode = decodeMode;
     sensor.Write(new byte[] { MAX_DECODE_REG_ADDR, (byte)decodeMode });
 }
        public string Peek(DecodeMode mode)
        {
            switch (mode) {
                case DecodeMode.Numbers:
                    return GenerateNumberRange (OriginalText.Length);
                case DecodeMode.Hide:
                    if (_visibleCount == 0)
                        return null;

                    _visibleCount--;
                    break;
                case DecodeMode.Show:
                    if (_visibleCount == OriginalText.Length)
                        return null;

                    _visibleCount++;
                    break;
            }

            var text = GenerateNumberRange (OriginalText.Length - _visibleCount);

            text += OriginalText.Substring (OriginalText.Length - _visibleCount, _visibleCount);

            return text;
        }
Ejemplo n.º 10
0
 internal static IntPtr SetDecodeMode(IntPtr ctx, DecodeMode mode) => SetDecodeMode(ctx, (int)mode);
Ejemplo n.º 11
0
        private void StartBarcode()
        {
            if (m_ScanBuffer != null) return;
            VmMdVendorFactory.Instance.Log("Entered StartBarcode");

            Mot.PdaSdk.ScanAPI.Scanner.Instance.Enable();
            m_ScanBuffer = new ScanBuffer();
            Triggers.Instance.TriggerEvent += new Mot.PdaSdk.TriggersApi.Triggers.TriggerEventHandler(Instance_TriggerEvent);

            Triggers.Instance.EnableEvents();

            ScanParams scanParams = new ScanParams();
            Mot.PdaSdk.ScanAPI.Scanner.Instance.GetScanParams(scanParams);
            scanParams.ControlScanLed = true;
            scanParams.DecodeLedTime = 2000;
            scanParams.FatalLedTime = 2000;
            scanParams.NonfatalLedTime = 2000;
            Mot.PdaSdk.ScanAPI.Scanner.Instance.SetScanParams(scanParams);

            ArrayList decoders = new ArrayList();
            decoders.Add(LabelType.CODE39);
            decoders.Add(LabelType.CODE128);
            if( _allowCode93 ) decoders.Add(LabelType.CODE93);
            Mot.PdaSdk.ScanAPI.Scanner.Instance.SetEnabledDecoders(decoders);

            DecodeMode p = new DecodeMode();
            Mot.PdaSdk.ScanAPI.Scanner.Instance.GetInternalImagerParams(p);
            p.DecodingMode = DecodeModeType.ADVANCED_LINEAR;
            Mot.PdaSdk.ScanAPI.Scanner.Instance.SetInternalImagerParams(p);

            DecodeLimitTime limitTime = new DecodeLimitTime();
            Mot.PdaSdk.ScanAPI.Scanner.Instance.GetInternalImagerParams(limitTime);
            limitTime.DecodeLimit = 400;
            limitTime.SearchLimit = 400;
            Mot.PdaSdk.ScanAPI.Scanner.Instance.SetInternalImagerParams(limitTime);
        }