public static extern int hfReaderDefaultConfig(int h, ushort srcAddr, ushort targetAddr, ref HFREADER_CONFIG pConfig, Byte[] pTxFrame, Byte[] pRxFrame);
private void buttonReadConfiguration_Click(object sender, EventArgs e) { if (serialDevice < 0) { MessageBox.Show("请先打开串口"); return; } Byte[] buffer = new Byte[255]; ushort[] addrArray = new ushort[2]; HFREADER_CONFIG pReaderConfig = new HFREADER_CONFIG(); Byte[] sendBuffer = new Byte[1024]; Byte[] rcvBuffer = new Byte[1024]; if (!GetDeviceAddr(addrArray)) { return; } LockUart(); int rlt = hfReaderDll.hfReaderGetConfig(serialDevice, addrArray[0], addrArray[1], ref pReaderConfig, sendBuffer, rcvBuffer); UnlockUart(); if (rlt > 0) { this.radioButtonCfgRltOpOK.Checked = false; this.radioButtonCfgRltOpFail.Checked = false; //if (pReaderConfig.Flag == 0) { Byte mode = (Byte)(pReaderConfig.workMode); if ((mode & hfReaderDll.HFREADER_CFG_TYPE_MASK) == hfReaderDll.HFREADER_CFG_TYPE_ISO15693) { this.radioButtonISO15693.Checked = true; } else if ((mode & hfReaderDll.HFREADER_CFG_TYPE_MASK) == hfReaderDll.HFREADER_CFG_TYPE_ISO14443A) { this.radioButtonISO14443A.Checked = true; } else if ((mode & hfReaderDll.HFREADER_CFG_TYPE_MASK) == hfReaderDll.HFREADER_CFG_TYPE_ISO14443B) { this.radioButtonISO14443B.Checked = true; } else if ((mode & hfReaderDll.HFREADER_CFG_TYPE_MASK) == hfReaderDll.HFREADER_CFG_TYPE_FELICA) { this.radioButtonFelica.Checked = true; } else if ((mode & hfReaderDll.HFREADER_CFG_TYPE_MASK) == hfReaderDll.HFREADER_CFG_TYPE_NFCTYPE2TAG) { this.radioButtonNfcType2Tag.Checked = true; } if ((mode & hfReaderDll.HFREADER_CFG_WM_MASK) == hfReaderDll.HFREADER_CFG_WM_INVENTORY) { this.radioButtonWorkModeInventory.Checked = true; } else { this.radioButtonWorkModeEAS.Checked = true; } if (pReaderConfig.cmdMode == hfReaderDll.HFREADER_CFG_INVENTORY_AUTO) { this.radioButtonCmdModeAuto.Checked = true; } else { this.radioButtonCmdModeTrigle.Checked = true; } if (pReaderConfig.uidSendMode == hfReaderDll.HFREADER_CFG_UID_ACTIVE) { this.radioButtonUIDModeAuto.Checked = true; } else { this.radioButtonUIDModeUnauto.Checked = true; } if (pReaderConfig.beepStatus == hfReaderDll.HFREADER_CFG_BUZZER_ENABLE) { this.radioButtonBeepModeEnable.Checked = true; } else { this.radioButtonBeepModeDisable.Checked = true; } if (pReaderConfig.afiCtrl == hfReaderDll.HFREADER_CFG_AFI_ENABLE) { this.radioButtonAFIModeEnable.Checked = true; } else { this.radioButtonAFIModeDisable.Checked = true; } //标签静默 if (pReaderConfig.tagStatus == hfReaderDll.HFREADER_CFG_TAG_QUIET) { this.radioButtonTagModeQuiet.Checked = true; } else { this.radioButtonTagModeUnquiet.Checked = true; } if (pReaderConfig.baudrate == hfReaderDll.HFREADER_CFG_BAUDRATE9600) { this.radioButtonBR9600.Checked = true; } else if (pReaderConfig.baudrate == hfReaderDll.HFREADER_CFG_BAUDRATE115200) { this.radioButtonBR115200.Checked = true; } else { this.radioButtonBR38400.Checked = true; } this.textBoxReaderAddr.Text = pReaderConfig.readerAddr.ToString("X").PadLeft(4, '0'); this.textBoxAFI.Text = pReaderConfig.afi.ToString("X").PadLeft(2, '0'); } this.textBoxCfgRltSrcAddr.Text = pReaderConfig.result.srcAddr.ToString("X").PadLeft(4, '0'); this.textBoxCfgRltDestAddr.Text = pReaderConfig.result.srcAddr.ToString("X").PadLeft(4, '0'); } DisplayRcvInf(rcvBuffer, "读取读写器配置参数返回:"); DisplaySendInf(sendBuffer, "读取读写器配置参数:"); }
private void buttonDftConfiguration_Click(object sender, EventArgs e) { if (serialDevice < 0) { MessageBox.Show("请先打开串口"); return; } Byte[] buffer = new Byte[255]; ushort[] addrArray = new ushort[2]; ushort ReaderAddr = 0; HFREADER_CONFIG pReaderConfig = new HFREADER_CONFIG(); Byte[] sendBuffer = new Byte[1024]; Byte[] rcvBuffer = new Byte[1024]; if (!GetDeviceAddr(addrArray)) { return; } if (GetHexInput(this.textBoxReaderAddr.Text, buffer, 2) > 0) { ReaderAddr = (ushort)(buffer[0] * 256 + buffer[1]); } else { return; } LockUart(); int rlt = 0; rlt = hfReaderDll.hfReaderDefaultConfig(serialDevice, addrArray[0], addrArray[1], ref pReaderConfig, sendBuffer, rcvBuffer); UnlockUart(); if (rlt > 0) { this.radioButtonWorkModeInventory.Checked = true; this.radioButtonCmdModeAuto.Checked = true; this.radioButtonUIDModeUnauto.Checked = true; this.radioButtonBeepModeEnable.Checked = true; this.radioButtonTagModeQuiet.Checked = true; this.radioButtonBR38400.Checked = true; this.textBoxReaderAddr.Text = "0001"; if (pReaderConfig.result.flag == 0) { this.radioButtonCfgRltOpOK.Checked = true; } else { this.radioButtonCfgRltOpFail.Checked = true; } this.textBoxCfgRltSrcAddr.Text = pReaderConfig.result.srcAddr.ToString("X").PadLeft(4, '0'); this.textBoxCfgRltDestAddr.Text = pReaderConfig.result.targetAddr.ToString("X").PadLeft(4, '0'); } DisplayRcvInf(rcvBuffer, "设置默认读写器配置参数返回:"); DisplaySendInf(sendBuffer, "设置默认读写器配置参数:"); buttonReadConfiguration_Click(sender, e); }
private void buttonConfigReader_Click(object sender, EventArgs e) { if (serialDevice < 0) { MessageBox.Show("请先打开串口"); return; } Byte[] buffer = new Byte[255]; ushort[] addrArray = new ushort[2]; Byte WorkMode = 0; ushort ReaderAddr = 0; Byte cmdMode = 0; Byte AFICtrl = 0; Byte UIDSendMode = 0; Byte tagStatus = 0; Byte baudrate = 0; Byte BeepStatus = 0; Byte AFI = 0; HFREADER_CONFIG pReaderConfig = new HFREADER_CONFIG(); Byte[] sendBuffer = new Byte[1024]; Byte[] rcvBuffer = new Byte[1024]; if (!GetDeviceAddr(addrArray)) { return; } if (this.radioButtonISO15693.Checked) { WorkMode |= hfReaderDll.HFREADER_CFG_TYPE_ISO15693; } else if (this.radioButtonISO14443A.Checked) { WorkMode |= hfReaderDll.HFREADER_CFG_TYPE_ISO14443A; } else if (this.radioButtonISO14443B.Checked) { WorkMode |= hfReaderDll.HFREADER_CFG_TYPE_ISO14443B; } else if (this.radioButtonFelica.Checked) { WorkMode |= hfReaderDll.HFREADER_CFG_TYPE_FELICA; } else if (this.radioButtonNfcType2Tag.Checked) { WorkMode |= hfReaderDll.HFREADER_CFG_TYPE_NFCTYPE2TAG; } if (this.radioButtonWorkModeInventory.Checked) { WorkMode |= hfReaderDll.HFREADER_CFG_WM_INVENTORY; } else { WorkMode |= hfReaderDll.HFREADER_CFG_WM_EAS; } pReaderConfig.workMode = WorkMode; if (this.radioButtonCmdModeAuto.Checked) { cmdMode = hfReaderDll.HFREADER_CFG_INVENTORY_AUTO; } else { cmdMode = hfReaderDll.HFREADER_CFG_INVENTORY_TRIGGER; } pReaderConfig.cmdMode = cmdMode; if (this.radioButtonUIDModeAuto.Checked) { UIDSendMode = hfReaderDll.HFREADER_CFG_UID_ACTIVE; } else { UIDSendMode = hfReaderDll.HFREADER_CFG_UID_POSITIVE; } pReaderConfig.uidSendMode = UIDSendMode; if (this.radioButtonBeepModeEnable.Checked) { BeepStatus = hfReaderDll.HFREADER_CFG_BUZZER_ENABLE; } else { BeepStatus = hfReaderDll.HFREADER_CFG_BUZZER_DISABLE; } pReaderConfig.beepStatus = BeepStatus; if (this.radioButtonAFIModeEnable.Checked) { AFICtrl = hfReaderDll.HFREADER_CFG_AFI_ENABLE; } else { AFICtrl = hfReaderDll.HFREADER_CFG_AFI_DISABLE; } pReaderConfig.afiCtrl = AFICtrl; if (this.radioButtonTagModeQuiet.Checked) { tagStatus = hfReaderDll.HFREADER_CFG_TAG_QUIET; } else { tagStatus = hfReaderDll.HFREADER_CFG_TAG_NOQUIET; } pReaderConfig.tagStatus = tagStatus; if (this.radioButtonBR9600.Checked) { baudrate = hfReaderDll.HFREADER_CFG_BAUDRATE9600; } else if (this.radioButtonBR115200.Checked) { baudrate = hfReaderDll.HFREADER_CFG_BAUDRATE115200; } else { baudrate = hfReaderDll.HFREADER_CFG_BAUDRATE38400; } pReaderConfig.baudrate = baudrate; if (GetHexInput(this.textBoxAFI.Text, buffer, 1) > 0) { AFI = buffer[0]; } else { return; } pReaderConfig.afi = AFI; if (GetHexInput(this.textBoxReaderAddr.Text, buffer, 2) > 0) { ReaderAddr = (ushort)(buffer[0] * 256 + buffer[1]); } else { return; } pReaderConfig.readerAddr = ReaderAddr; LockUart(); int rlt = hfReaderDll.hfReaderSetConfig(serialDevice, addrArray[0], addrArray[1], ref pReaderConfig, sendBuffer, rcvBuffer); UnlockUart(); if (rlt > 0) { if (pReaderConfig.result.flag == 0) { this.radioButtonCfgRltOpOK.Checked = true; } else { this.radioButtonCfgRltOpFail.Checked = true; } this.textBoxCfgRltSrcAddr.Text = pReaderConfig.result.srcAddr.ToString("X").PadLeft(4, '0'); this.textBoxCfgRltDestAddr.Text = pReaderConfig.result.targetAddr.ToString("X").PadLeft(4, '0'); } DisplayRcvInf(rcvBuffer, "设置读写器配置参数返回:"); DisplaySendInf(sendBuffer, "设置读写器配置参数:"); }