/// <summary> /// GetSingulationAlgorithmParms /// </summary> /// <param name="alg"></param> /// <param name="parms"></param> /// <returns></returns> public Result GetSingulationAlgorithmParms(SingulationAlgorithm alg, SingulationAlgorithmParms parms) { const int RFID_18K6C_SINGULATION_ALGORITHM_FIXEDQ = 0; const int RFID_18K6C_SINGULATION_ALGORITHM_DYNAMICQ = 3; UInt32 parm0Register = 0; UInt32 parm1Register = 0; UInt32 parm2Register = 0; switch (alg) { case SingulationAlgorithm.FIXEDQ: { FixedQParms m_fixedQ = (FixedQParms)parms; // Tell the MAC which singulation algorithm selector to use and then // read the singulation algorithm registers MacWriteRegister(MACREGISTER.HST_INV_SEL, RFID_18K6C_SINGULATION_ALGORITHM_FIXEDQ); MacReadRegister(MACREGISTER.HST_INV_ALG_PARM_0, ref parm0Register); MacReadRegister(MACREGISTER.HST_INV_ALG_PARM_1, ref parm1Register); MacReadRegister(MACREGISTER.HST_INV_ALG_PARM_2, ref parm2Register); // Set up the fixed Q singulation algorithm structure //m_fixedQ.length = sizeof(FixedQParms); m_fixedQ.qValue = parm0Register & 0x0f; m_fixedQ.retryCount = parm1Register & 0xff; m_fixedQ.toggleTarget = (parm2Register & 0x01) != 0 ? (uint)1 : (uint)0; m_fixedQ.repeatUntilNoTags = (parm2Register & 0x02) != 0 ? (uint)1 : (uint)0; } break; case SingulationAlgorithm.DYNAMICQ: { DynamicQParms m_dynQ = (DynamicQParms)parms; // Tell the MAC which singulation algorithm selector to use and then // read the singulation algorithm registers MacWriteRegister(MACREGISTER.HST_INV_SEL, RFID_18K6C_SINGULATION_ALGORITHM_DYNAMICQ); MacReadRegister(MACREGISTER.HST_INV_ALG_PARM_0, ref parm0Register); MacReadRegister(MACREGISTER.HST_INV_ALG_PARM_1, ref parm1Register); MacReadRegister(MACREGISTER.HST_INV_ALG_PARM_2, ref parm2Register); // Extract the dynamic-Q with Q-adjustment threshold singulation algorithm // parameters //m_dynQ.length = sizeof(DynamicQParms); m_dynQ.startQValue = parm0Register & 0x0f; m_dynQ.minQValue = (parm0Register >> 8) & 0x0f; m_dynQ.maxQValue = (parm0Register >> 4) & 0x0f; m_dynQ.thresholdMultiplier = (parm0Register >> 12) & 0x3f; m_dynQ.retryCount = parm1Register; m_dynQ.toggleTarget = (parm2Register & 0x01) != 0 ? (uint)1 : (uint)0; } break; default: return(Result.INVALID_PARAMETER); } return(Result.OK); }
private void Set18K6CSingulationAlgorithmParameters(int radioHandle) { // Fixed. // See RFID_18K6C_SINGULATION_FIXEDQ_PARMS FixedQParms fqp = new FixedQParms { qValue = 1, retryCount = 1, repeatUntilNoTags = 1, toggleTarget = options.IsTagFocusEnabled ? 0U : 1 }; var result = link.Set18K6CSingulationAlgorithmParameters(radioHandle, SingulationAlgorithm.FIXEDQ, fqp); logger.Information("link.Set18K6CSingulationAlgorithmParameters Fixed Q => {Result}", result); // Dynamic. DynamicQParms dqp = new DynamicQParms { startQValue = 3, minQValue = 0, maxQValue = 7, retryCount = 1, thresholdMultiplier = 4, toggleTarget = options.IsTagFocusEnabled ? 0U : 1 }; result = link.Set18K6CSingulationAlgorithmParameters(radioHandle, SingulationAlgorithm.DYNAMICQ, dqp); logger.Information("link.Set18K6CSingulationAlgorithmParameters Dynamic Q => {Result}", result); }
/// <summary> /// The parameters for the fixed-Q algorithm, MAC singulation algorithm 0 /// If running a same operation, it only need to config once times /// </summary> /// <returns></returns> public Result SetFixedQParms() { FixedQParms FixedQParm = new FixedQParms(); FixedQParm.qValue = 7; //if only 1 tag read and write, otherwise use 7 FixedQParm.retryCount = 0; FixedQParm.toggleTarget = 1; FixedQParm.repeatUntilNoTags = 1; return(m_Result = SetSingulationAlgorithmParms(SingulationAlgorithm.FIXEDQ, FixedQParm)); }
/// <summary> /// The parameters for the fixed-Q algorithm, MAC singulation algorithm 0 /// If running a same operation, it only need to config once times /// </summary> /// <param name="QValue">The Q value to use. Valid values are 0-15, inclusive.</param> /// <param name="RetryCount">Specifies the number of times to try another execution /// of the singulation algorithm for the specified /// session/target before either toggling the target (if /// toggleTarget is non-zero) or terminating the /// inventory/tag access operation. Valid values are 0- /// 255, inclusive. Valid values are 0-255, inclusive.</param> /// <param name="ToggleTarget"> A non-zero value indicates that the target should /// be toggled.A zero value indicates that the target should not be toggled. /// Note that if the target is toggled, retryCount and repeatUntilNoTags will also apply /// to the new target. </param> /// <param name="RepeatUnitNoTags">A flag that indicates whether or not the singulation /// algorithm should continue performing inventory rounds /// until no tags are singulated. A non-zero value indicates /// that, for each execution of the singulation algorithm, /// inventory rounds should be performed until no tags are /// singulated. A zero value indicates that a single /// inventory round should be performed for each /// execution of the singulation algorithm.</param> public Result SetFixedQParms(uint QValue, uint RetryCount, uint ToggleTarget, uint RepeatUnitNoTags) { FixedQParms FixedQParm = new FixedQParms(); FixedQParm.qValue = QValue; //if only 1 tag read and write, otherwise use 7 FixedQParm.retryCount = RetryCount; FixedQParm.toggleTarget = ToggleTarget; FixedQParm.repeatUntilNoTags = RepeatUnitNoTags; return(m_Result = SetSingulationAlgorithmParms(SingulationAlgorithm.FIXEDQ, FixedQParm)); }
/// <summary> /// SetSingulationAlgorithmParms /// </summary> /// <param name="alg"></param> /// <param name="parms"></param> /// <returns></returns> public Result SetSingulationAlgorithmParms(SingulationAlgorithm alg, SingulationAlgorithmParms parms) { const uint RFID_18K6C_SINGULATION_ALGORITHM_FIXEDQ = 0; const uint RFID_18K6C_SINGULATION_ALGORITHM_DYNAMICQ = 3; if (alg == SingulationAlgorithm.UNKNOWN) { return(Result.INVALID_PARAMETER); } try { switch (alg) { case SingulationAlgorithm.FIXEDQ: { FixedQParms p = (FixedQParms)parms; // Write the inventory algorithm parameter registers MacWriteRegister(MACREGISTER.HST_INV_SEL, RFID_18K6C_SINGULATION_ALGORITHM_FIXEDQ); MacWriteRegister(MACREGISTER.HST_INV_ALG_PARM_0, p.qValue); MacWriteRegister(MACREGISTER.HST_INV_ALG_PARM_1, p.retryCount); MacWriteRegister(MACREGISTER.HST_INV_ALG_PARM_2, (uint)(p.toggleTarget != 0 ? 1 : 0) | (uint)(p.repeatUntilNoTags != 0 ? 2 : 0)); MacWriteRegister(MACREGISTER.HST_INV_ALG_PARM_3, 0); } break; case SingulationAlgorithm.DYNAMICQ: { DynamicQParms p = (DynamicQParms)parms; // Write the inventory algorithm parameter registers. For register // zero, remember to preserve values that we aren't exposing MacWriteRegister(MACREGISTER.HST_INV_SEL, RFID_18K6C_SINGULATION_ALGORITHM_DYNAMICQ); MacWriteRegister(MACREGISTER.HST_INV_ALG_PARM_0, p.startQValue | (p.maxQValue << 4) | (p.minQValue << 8) | (p.thresholdMultiplier << 12)); MacWriteRegister(MACREGISTER.HST_INV_ALG_PARM_1, p.retryCount); MacWriteRegister(MACREGISTER.HST_INV_ALG_PARM_2, (uint)(p.toggleTarget != 0 ? 1 : 0)); MacWriteRegister(MACREGISTER.HST_INV_ALG_PARM_3, 0); } break; default: return(Result.INVALID_PARAMETER); } // switch (algorithm) } catch (Exception ex) { } return(m_Result = SetCurrentSingulationAlgorithm(alg)); }
public Singulation_FixedQ(SingulationAlgorithmParms fixedQ) { InitializeComponent(); if (fixedQ.GetType() == typeof(FixedQParms)) { FixedQ = (FixedQParms)fixedQ; } else { FixedQ.qValue = 7; FixedQ.retryCount = 0; FixedQ.toggleTarget = 1; FixedQ.repeatUntilNoTags = 0; } Refresh(); }
private void btn_apply_Click(object sender, EventArgs e) { Text = "Applying configuration : Please wait..."; this.Enabled = false; //Start to apply all settings try { UInt16 ms = UInt16.Parse(textBox1.Text); Program.ReaderXP.SetTxOnTime(ms); } catch (Exception ex) { MessageBox.Show("Can not set Tx On Time"); } //Set PowerLevel Result res = Result.OK; if ((cb_custInvtryBlocking.Checked && cb_custInvtryCont.Checked)) { if (MessageBox.Show("Please don't run in blocking and continuous mode in the same time, otherwise you can't abort the operation", "warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { } else { goto ERROR; } } #if nouse if (nb_power.Enabled == true) { if ((res = Program.ReaderXP.SetPowerLevel((uint)nb_power.Value)) != Result.OK) { ts_status.Text = string.Format("SetPowerLevel fail with err {0}", res); goto ERROR; } } #endif //Set LinkProfile if ((res = Program.ReaderXP.SetCurrentLinkProfile(uint.Parse(cb_linkprofile.Text))) != Result.OK) { ts_status.Text = string.Format("SetCurrentLinkProfile fail with err {0}", res); goto ERROR; } //Set Region and Frequency if (cb_fixed.Checked) { if (!checkBoxFreqAgile.Checked) { //if (freq.ListItems.SelectedIndices.Count == 0 || freq.ListItems.SelectedIndices[0] < 0 || freq.ListItems.SelectedIndices[0] >= freq.ListItems.Items.Count) if (cb_freqlist.SelectedIndex < 0 || cb_freqlist.SelectedIndex >= cb_freqlist.Items.Count) { ts_status.Text = "Please select a channel first"; goto ERROR; } //if ((res = Program.ReaderXP.SetFixedChannel(Program.ReaderXP.GetActiveRegionCode()[cb_country.SelectedIndex], (uint)freq.ListItems.SelectedIndices[0], cb_lbt.Checked ? LBT.ON : LBT.OFF)) != CSLibrary.Constants.Result.OK) if ((res = Program.ReaderXP.SetFixedChannel(Program.ReaderXP.GetActiveRegionCode()[cb_country.SelectedIndex], (uint)cb_freqlist.SelectedIndex, cb_lbt.Checked ? LBT.SCAN : LBT.OFF)) != CSLibrary.Constants.Result.OK) { ts_status.Text = string.Format("SetFixedChannel fail with err {0}", res); goto ERROR; } } else { res = Program.ReaderXP.SetAgileChannels(Program.ReaderXP.GetActiveRegionCode()[cb_country.SelectedIndex]); if (res != CSLibrary.Constants.Result.OK) { ts_status.Text = string.Format("SetAgileChannel fail with err {0}", res); goto ERROR; } } } else { if ((res = Program.ReaderXP.SetHoppingChannels(Program.ReaderXP.GetActiveRegionCode()[cb_country.SelectedIndex])) != CSLibrary.Constants.Result.OK) { ts_status.Text = string.Format("SetHoppingChannels fail with err {0}", res); goto ERROR; } } { Program.appSetting.Cfg_blocking_mode = cb_custInvtryBlocking.Checked; //Program.appSetting.Singulation = (SingulationAlgorithm)cb_algorithm. switch (cb_algorithm.SelectedIndex) { case 0: Program.appSetting.Singulation = SingulationAlgorithm.FIXEDQ; break; default: Program.appSetting.Singulation = SingulationAlgorithm.DYNAMICQ; break; } Program.appSetting.Cfg_continuous_mode = cb_custInvtryCont.Checked; Program.appSetting.FixedChannel = cb_fixed.Checked; #if nouse Program.appSetting.tagGroup = new TagGroup ( (Selected)cb_selected.SelectedItem, (Session)cb_session.SelectedItem, (SessionTarget)cb_target.SelectedItem ); #endif Program.appSetting.tagGroup = new TagGroup ( ((cb_selected.SelectedIndex == 1) ? Selected.ASSERTED : (cb_selected.SelectedIndex == 2) ? Selected.DEASSERTED : Selected.ALL), (Session)cb_session.SelectedIndex, (cb_target.SelectedIndex == 2) ? SessionTarget.A : (SessionTarget)cb_target.SelectedIndex ); switch (Program.appSetting.Singulation) { case SingulationAlgorithm.DYNAMICQ: DynamicQParms dynQ = new DynamicQParms(); dynQ.startQValue = (uint)nb_startqvalue.Value; dynQ.minQValue = (uint)nb_minqvalue.Value; dynQ.maxQValue = (uint)nb_maxqvalue.Value; dynQ.retryCount = (uint)numericUpDown_Retry.Value; dynQ.toggleTarget = (checkBox_Toggle.Checked) ? 1U : 0U; dynQ.thresholdMultiplier = (uint)nb_thresholdMultiplier.Value; Program.appSetting.SingulationAlg = dynQ; break; /*case SingulationAlgorithm.DYNAMICQ_ADJUST: * Program.appSetting.SingulationAlg = singulation_dynamicQAdjust.DynamicQAdjust; * break; * case SingulationAlgorithm.DYNAMICQ_THRESH: * Program.appSetting.SingulationAlg = singulation_dynamicQThreshold.DynamicQThreshold; * break;*/ case SingulationAlgorithm.FIXEDQ: FixedQParms m_fixedQ = new FixedQParms(); m_fixedQ.qValue = (uint)nb_qvalue.Value; m_fixedQ.retryCount = (uint)nb_retry.Value; m_fixedQ.toggleTarget = cb_toggle.Checked ? 1U : 0U; m_fixedQ.repeatUntilNoTags = cb_repeat.Checked ? 1U : 0U; Program.appSetting.SingulationAlg = m_fixedQ; break; } #if nouse switch (Program.appSetting.Singulation) { case SingulationAlgorithm.DYNAMICQ: Program.appSetting.SingulationAlg = singulation_dynamicQ.DynamicQ; break; /*case SingulationAlgorithm.DYNAMICQ_ADJUST: * Program.appSetting.SingulationAlg = singulation_dynamicQAdjust.DynamicQAdjust; * break; * case SingulationAlgorithm.DYNAMICQ_THRESH: * Program.appSetting.SingulationAlg = singulation_dynamicQThreshold.DynamicQThreshold; * break;*/ case SingulationAlgorithm.FIXEDQ: Program.appSetting.SingulationAlg = singulation_fixedQ.FixedQ; break; } #endif } Program.appSetting.Lbt = cb_lbt.Checked; Program.appSetting.FreqAgile = checkBoxFreqAgile.Checked; //CSLibrary.Diagnostics.CoreDebug.Enable = Program.appSetting.Debug_log = this.cb_debug_log.Checked; #if NET_BUILD Program.ReaderXP.ReconnectTimeout = Program.appSetting.ReconnectTimeout = (uint)this.nb_reconnectTimeout.Value; #endif Program.appSetting.EnableRssiFilter = cbRssiFilterEnable.Checked; Program.appSetting.RssiFilterThreshold = (uint)nbRssiFilter.Value; Program.appSetting.MaskBank = (uint)comboBox_MaskBank.SelectedIndex; Program.appSetting.MaskOffset = (uint.Parse)(textBox_MaskOffset.Text); Program.appSetting.MaskBitLength = (uint.Parse)(textBox_MaskLength.Text); Program.appSetting.Mask = textBox_Mask.Text; //#region === Antenna Port setting === // //Program.ReaderXP.AntennaList.Store(Program.ReaderXP); // //#endregion === Antenna Port setting === #region === Antenna Sequence setting === Program.appSetting.AntennaSequenceMode = Program.ReaderXP.AntennaSequenceMode; Program.appSetting.AntennaSequenceSize = Program.ReaderXP.AntennaSequenceSize; Program.appSetting.AntennaPortSequence = Program.ReaderXP.AntennaPortSequence; if (Program.ReaderXP.SetOperationMode( Program.appSetting.Cfg_continuous_mode ? RadioOperationMode.CONTINUOUS : RadioOperationMode.NONCONTINUOUS, Program.appSetting.AntennaSequenceMode, (int)Program.appSetting.AntennaSequenceSize ) != CSLibrary.Constants.Result.OK) { MessageBox.Show("SetOperationMode failed"); } if ((Program.ReaderXP.AntennaSequenceMode & AntennaSequenceMode.SEQUENCE) != 0) { byte[] seq = new byte[Program.appSetting.AntennaPortSequence.Length]; for (int i = 0; i < Program.appSetting.AntennaSequenceSize; i++) { seq[i] = (byte)Program.appSetting.AntennaPortSequence[i]; //MessageBox.Show(Program.appSetting.AntennaPortSequence[i].ToString()); } if (Program.ReaderXP.SetAntennaSequence(seq, (uint)Program.appSetting.AntennaSequenceSize, Program.appSetting.AntennaSequenceMode) != CSLibrary.Constants.Result.OK) { MessageBox.Show("SetAntennaSequence failed"); } } #endregion === Antenna Sequence setting === //Save all settings to config file if (cb_save.Checked) { Program.SaveSettings(); } ts_status.Text = string.Format("Apply Configuration Successful"); this.Enabled = true; this.DialogResult = DialogResult.OK; Text = "Apply Configuration Successful"; return; ERROR: //ts_status.Text = string.Format("Apply Configuration failed"); this.Enabled = true; //this.DialogResult = DialogResult.Cancel; Text = "Apply Configuration failed"; }
private void SettingForm_Load(object sender, EventArgs e) { //RFID Initial start here { //Load DataSource UInt16 ms = 0; Program.ReaderXP.GetTxOnTime(ref ms); textBox1.Text = ms.ToString("D"); this.cb_linkprofile.DataSource = Program.ReaderXP.GetActiveLinkProfile(); this.cb_country.DataSource = Program.ReaderXP.GetActiveRegionCode(); //this.cb_algorithm.DataSource = EnumGetValues(typeof(SingulationAlgorithm)); //this.cb_selected.DataSource = EnumGetValues(typeof(Selected)); //this.cb_session.DataSource = EnumGetValues(typeof(Session)); //this.cb_target.DataSource = EnumGetValues(typeof(SessionTarget)); if (Program.ReaderXP.IsFixedChannelOnly) { cb_fixed.Enabled = false; cb_fixed.Checked = true; } else { cb_fixed.Enabled = true; cb_fixed.Checked = Program.appSetting.FixedChannel; } //Load Setting if (Program.ReaderXP.SelectedRegionCode == CSLibrary.Constants.RegionCode.JP) { cb_lbt.Enabled = true; cb_lbt.Checked = Program.appSetting.Lbt; } else { cb_lbt.Enabled = Program.appSetting.Lbt; } if (Program.ReaderXP.SelectedRegionCode == CSLibrary.Constants.RegionCode.ETSI || Program.ReaderXP.SelectedRegionCode == CSLibrary.Constants.RegionCode.JP) { checkBoxFreqAgile.Enabled = true; checkBoxFreqAgile.Checked = Program.appSetting.FreqAgile; } else { checkBoxFreqAgile.Enabled = false; } if (cb_fixed.Checked && !checkBoxFreqAgile.Checked) { cb_freqlist.Enabled = cb_fixed.Checked; } else { cb_freqlist.Enabled = false; } //highlight the current link profile cb_linkprofile.SelectedItem = Program.appSetting.Link_profile; //current select frequency profile index cb_country.SelectedItem = Program.ReaderXP.SelectedRegionCode; //this.cb_algorithm.SelectedItem = Program.appSetting.Singulation; switch (Program.appSetting.Singulation) { case SingulationAlgorithm.FIXEDQ: this.cb_algorithm.SelectedIndex = 0; break; case SingulationAlgorithm.DYNAMICQ: this.cb_algorithm.SelectedIndex = 1; break; } //this.cb_selected.SelectedItem = Program.appSetting.tagGroup.selected; switch (Program.appSetting.tagGroup.selected) { case Selected.ASSERTED: this.cb_selected.SelectedIndex = 1; break; case Selected.DEASSERTED: this.cb_selected.SelectedIndex = 2; break; default: this.cb_selected.SelectedIndex = 0; break; } //this.cb_session.SelectedItem = Program.appSetting.tagGroup.session; switch (Program.appSetting.tagGroup.session) { case Session.S1: this.cb_session.SelectedIndex = 1; break; case Session.S2: this.cb_session.SelectedIndex = 2; break; case Session.S3: this.cb_session.SelectedIndex = 3; break; default: this.cb_session.SelectedIndex = 0; break; } //this.cb_target.SelectedItem = Program.appSetting.tagGroup.target; if (Program.appSetting.Singulation == SingulationAlgorithm.DYNAMICQ) { DynamicQParms dq = (DynamicQParms)Program.appSetting.SingulationAlg; if (dq.toggleTarget != 0) { this.cb_target.SelectedIndex = 2; } else { this.cb_target.SelectedIndex = (int)Program.appSetting.tagGroup.target; } nb_startqvalue.Value = dq.startQValue; nb_minqvalue.Value = dq.minQValue; nb_maxqvalue.Value = dq.maxQValue; nb_thresholdMultiplier.Value = dq.thresholdMultiplier; numericUpDown_Retry.Value = dq.retryCount; checkBox_Toggle.Checked = (dq.toggleTarget != 0); } else { FixedQParms fq = (FixedQParms)Program.appSetting.SingulationAlg; if (fq.toggleTarget != 0) { this.cb_target.SelectedIndex = 2; } else { this.cb_target.SelectedIndex = (int)Program.appSetting.tagGroup.target; } nb_qvalue.Value = fq.qValue; nb_retry.Value = fq.retryCount; cb_toggle.Checked = (fq.toggleTarget != 0); cb_repeat.Checked = (fq.repeatUntilNoTags != 0); } this.cb_custInvtryCont.Checked = Program.appSetting.Cfg_continuous_mode; this.cb_custInvtryBlocking.Checked = Program.appSetting.Cfg_blocking_mode; if (Program.appSetting.FixedChannel) { cb_freqlist.SelectedItem = CurrentFreqList[(int)Program.appSetting.Channel_number]; } this.cb_debug_log.Checked = Program.appSetting.Debug_log; cbRssiFilterEnable.Checked = Program.appSetting.EnableRssiFilter; nbRssiFilter.Value = Program.appSetting.RssiFilterThreshold; //Update maximum power UpdateMaxPower(); //Update Frequency list UpdateFreqList(); #if nouse //get power level nb_power.Value = Program.appSetting.Power; if (Program.ReaderXP.OEMDeviceType == Machine.CS203) { nb_power.Enabled = true; lk_antenna_port_cfg.Enabled = false; } else { nb_power.Enabled = false; lk_antenna_port_cfg.Enabled = true; } #endif nb_reconnectTimeout.Value = Program.appSetting.ReconnectTimeout; comboBox_MaskBank.SelectedIndex = (int)Program.appSetting.MaskBank; textBox_MaskOffset.Text = Program.appSetting.MaskOffset.ToString(); textBox_MaskLength.Text = Program.appSetting.MaskBitLength.ToString(); textBox_Mask.Text = Program.appSetting.Mask; } tabControl1.SelectedIndex = 0; AttachCallback(true); #if ENGINEERING_MODE btnRegister.Visible = true; #else btnRegister.Visible = false; #endif }
/// <summary> /// The parameters for the fixed-Q algorithm, MAC singulation algorithm 0 /// If running a same operation, it only need to config once times /// </summary> /// <returns></returns> public Result SetFixedQParms(FixedQParms fixedQParm) { return(m_Result = SetSingulationAlgorithmParms(SingulationAlgorithm.FIXEDQ, fixedQParm)); }
public Singulation_FixedQ(FixedQParms fixedQ) { InitializeComponent(); FixedQ = fixedQ; }
public Result API_l8K6CGetSingulationAlgorithmParameters( [In] SingulationAlgorithm r_Algorithm, [In, Out] ref SingulationAlgorithmParms r_Parms ) { #if _TRACE_OUT_PUT PrintMagToTxt("API_l8K6CGetSingulationAlgorithmParameters"); #endif if (null == r_Parms) { return Result.INVALID_PARAMETER; } // Instead of the following, could simply make the native call // with given fields and catch the resulting marshal exception // when trying to do ptr to structure Type algoType = r_Parms.GetType(); if ( (SingulationAlgorithm.UNKNOWN == r_Algorithm) || (SingulationAlgorithm.FIXEDQ == r_Algorithm && r_Parms.GetType() != typeof(FixedQParms)) || (SingulationAlgorithm.DYNAMICQ == r_Algorithm && r_Parms.GetType() != typeof(DynamicQParms)) ) { return Result.INVALID_PARAMETER; } Result result = Result.OK; ENUM_CMD TxCmd = ENUM_CMD.NOTHING; object objParams = r_Parms; byte[] buf = new byte[10]; Array.Clear(buf, 0, buf.Length); TxCmd = ENUM_CMD.l8K6C_GET_SINGULATION_ALGORITHM_PARAMETERS; buf[0] = (byte)TxCmd; buf[1] = (byte)r_Algorithm; if ( false == SendData(buf) ) return Result.FAILURE; Array.Clear(buf, 0, buf.Length); //Check receive data if ( false == ReceiveData( TxCmd, ref buf ) ) return Result.FAILURE; //Check result result = ConvertResult(buf[1]); if (Result.OK != result) return result; switch (r_Algorithm) { case SingulationAlgorithm.FIXEDQ: { FixedQParms fixParams = new FixedQParms(); fixParams.qValue = buf[2]; fixParams.retryCount = buf[3]; fixParams.toggleTarget = buf[4]; fixParams.repeatUntilNoTags = buf[5]; objParams = fixParams; } break; case SingulationAlgorithm.DYNAMICQ: { DynamicQParms dynamicParams = new DynamicQParms(); dynamicParams.startQValue = buf[2]; dynamicParams.minQValue = buf[3]; dynamicParams.maxQValue = buf[4]; dynamicParams.retryCount = buf[5]; dynamicParams.toggleTarget = buf[6]; dynamicParams.thresholdMultiplier = buf[7]; objParams = dynamicParams; } break; default: return Result.INVALID_PARAMETER; }//end switch //Copy data to the reference structure IntPtr pstrcData = IntPtr.Zero; Int32 Size = 0; Size = Marshal.SizeOf(objParams); pstrcData = Marshal.AllocHGlobal(Size); if (0 >= Size || pstrcData == IntPtr.Zero) return Result.INVALID_PARAMETER; Marshal.StructureToPtr(objParams, pstrcData, true); Marshal.PtrToStructure(pstrcData, r_Parms); return Result.OK; }