Example #1
0
        public static WriteCode WriteNewUID(RFID_Device localDevice, string oldUID, string newUID, int writeMode)
        {
            if (writeMode == 0)
            {
                return(localDevice.WriteNewUID(oldUID, newUID));
            }
            if (writeMode == 1)
            {
                return(localDevice.WriteNewUidWithFamily(oldUID, newUID));
            }
            if (writeMode == 2)
            {
                return(localDevice.WriteNewUidDecimal(oldUID, newUID));
            }

            return(WriteCode.WC_Error);
        }
        private bool WriteLotId(string tagId, string lotId)
        {
            lotId = lotId.Trim().ToUpper();

            if ((tagId.Length == 10) && (tagId.StartsWith("30")) && (_myRegexUid.IsMatch(tagId)))
            {
                MessageBox.Show(ResStrings.str_Tag_not_compatible_for_writing, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            if (!SDK_SC_RfidReader.DeviceBase.SerialRFID.isStringValidToWrite(lotId))
            {
                MessageBox.Show(ResStrings.str_Tag_Invalid_Tag_ID, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            WriteCode codeResult = WriteCode.WC_Error;

            if (_currentEthernetDevice == null) // (USB) local reader
            {
                if ((_device.ConnectionStatus == ConnectionStatus.CS_Connected) && (_device.DeviceStatus == DeviceStatus.DS_Ready))
                {
                    codeResult = _device.WriteNewUID(tagId, lotId);
                }

                else
                {
                    MessageBox.Show(ResStrings.str_device_not_ready, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            else
            {
                TcpIpClient tcpClient = new TcpIpClient();
                tcpClient.RequestWriteBlock(_currentEthernetDevice.IP_Server, _currentEthernetDevice.Port_Server, tagId, lotId, out codeResult);
            }


            switch (codeResult)
            {
            case WriteCode.WC_Error:
                MessageBox.Show(ResStrings.strWriteStatusUnexpectedError);
                break;

            case WriteCode.WC_TagNotDetected:
                MessageBox.Show(ResStrings.strWriteStatusOperation_failed);
                break;

            case WriteCode.WC_TagNotConfirmed:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_not_confirmed);
                break;

            case WriteCode.WC_TagBlockedOrNotSupplied:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_blocked_or_not_well_supplied);
                break;

            case WriteCode.WC_TagBlocked:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_blocked);
                break;

            case WriteCode.WC_TagNotSupplied:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_not_well_supplied);
                break;

            case WriteCode.WC_ConfirmationFailed:
                MessageBox.Show(ResStrings.strWriteStatus_Updated_tag_confirmation_has_failed);
                return(true);

            case WriteCode.WC_Success:
            {
                string initialUid = _db.GetInitialUID(tagId);
                _db.AddUidHistory(string.IsNullOrEmpty(initialUid) ? tagId : initialUid, lotId);
            }
                return(true);
            }

            return(false);
        }