RFID.RFIDInterface.Source_QueryParms.loadForAlgorithm C# (CSharp) Method

loadForAlgorithm() public method

public loadForAlgorithm ( rfid transport, UInt32 readerHandle, rfid algorithm ) : rfid.Constants.Result
transport rfid
readerHandle System.UInt32
algorithm rfid
return rfid.Constants.Result
        public rfid.Constants.Result loadForAlgorithm(
            rfid.Linkage                        transport,
            UInt32                              readerHandle,
            rfid.Constants.SingulationAlgorithm algorithm
        )
        {
            // Need to do lower level register manipulation for this one...

            UInt32 reg_0x0901 = 0;

            Result result = Result.OK;

            try
            {
                // Set the algo on the board ~ maintaining all other fields

                result = transport.API_ConfigReadRegister
                (
                    ( UInt16 ) 0x0901, ref reg_0x0901
                );

                if ( rfid.Constants.Result.OK != result )
                {
                    throw new Exception( result.ToString( ) );
                }

                result = transport.API_ConfigWriteRegister
                (
                    ( UInt16 ) 0x0901, ( reg_0x0901 & 0xFFFFFFC0 ) | ( UInt32 ) algorithm
                );

                if ( rfid.Constants.Result.OK != result )
                {
                    throw new Exception( result.ToString( ) );
                }

                // Set for the algo register bank on the board

                result = transport.API_ConfigWriteRegister
                (
                    ( UInt16 ) 0x0902, ( UInt32 ) algorithm
                );

                if ( rfid.Constants.Result.OK != result )
                {
                    throw new Exception( result.ToString( ) );
                }

                result = this.load( transport, readerHandle );

                if ( rfid.Constants.Result.OK != result )
                {
                    throw new Exception( result.ToString( ) );
                }

                // Restore algo bank reg to original value

                result = transport.API_ConfigWriteRegister
                (
                    ( UInt16 ) 0x0901, reg_0x0901
                );

                if ( rfid.Constants.Result.OK != result )
                {
                    throw new Exception( result.ToString( ) );
                }

            }
            catch ( Exception )
            {
                // NOP - let fall thru to result check & msg display
            }

            // If we did ok, our source for the underlying singulation
            // parameters must also now be changed here AND grabbed at
            // the gui level ...

            if ( Result.OK == result )
            {
                switch( algorithm )
                {
                    case SingulationAlgorithm.FIXEDQ:
                    {
                        sourceParameters = new Source_SingulationParametersFixedQ
                            (
                                ( rfid.Structures.FixedQParms ) this.nativeSingulationParms
                            );
                    }
                    break;

                    case SingulationAlgorithm.DYNAMICQ:
                    {
                        sourceParameters = new Source_SingulationParametersDynamicQ
                            (
                                ( rfid.Structures.DynamicQParms ) this.nativeSingulationParms
                            );
                    }
                    break;

                    default:
                        Console.WriteLine( "ERR : Algorithm.Copy( Source_QueryParms from )" );

                    break;
                };
            }

            return result;
        }