public retCode getTagAndWeight(int timeoutScale, out string tagUID, out double scaleWeight)
        {
            tagUID      = null;
            scaleWeight = 0.0;
            ret         = retCode.RC_Unknown;
            if (device == null)
            {
                ret = retCode.RC_RFID_Not_Connected;
            }
            else if (scale == null)
            {
                ret = retCode.RC_Scale_Not_Connected;
            }
            else if (!isRfidConnected)
            {
                ret = retCode.RC_RFID_Not_Connected;
            }
            else if (!isScaleConnected)
            {
                ret = retCode.RC_Scale_Not_Connected;
            }
            else
            {
                device.ScanDevice();
                eventEndRFID.WaitOne();
                if (device.currentInventory.nbTagAll == 0)
                {
                    ret = retCode.RC_No_Tag_Detected;
                }
                else if (device.currentInventory.nbTagAll > 1)
                {
                    ret = retCode.RC_Too_Many_Tags_Detected;
                }
                else if (device.currentInventory.nbTagAll == 1)
                {
                    tagUID = device.currentInventory.listTagAll[0].ToString();
                    eventEndScale.Reset();
                    scale.getWeight();
                    if (eventEndScale.WaitOne(timeoutScale))
                    {
                        if (scale.LastScaledWeight != null)
                        {
                            scaleWeight = scale.LastScaledWeight.WeightValue;
                            ret         = retCode.RC_succeed;
                        }
                        else
                        {
                            ret = retCode.RC_Unknown;
                        }
                    }
                    else
                    {
                        ret = retCode.RC_Scale_Not_Stabilized;
                    }
                }
            }

            return(ret);
        }
示例#2
0
        public static bool StartScan(RFID_Device localDevice, bool bUnlockAll)
        {
            if (localDevice == null)
            {
                return(false);
            }

            if ((localDevice.ConnectionStatus == ConnectionStatus.CS_Connected) &&
                (localDevice.DeviceStatus == DeviceStatus.DS_Ready))
            {
                localDevice.ScanDevice(true, bUnlockAll);
                return(true);
            }

            return(false);
        }
 private void ScanDevice()
 {
     if (_device == null)
     {
         return;
     }
     if ((_device.ConnectionStatus == ConnectionStatus.CS_Connected) &&
         (_device.DeviceStatus == DeviceStatus.DS_Ready))
     {
         //Request a scan
         //Scan status will be notified by event
         _device.ScanDevice();
     }
     else
     {
         MessageBox.Show(ResStrings.StrDeviceNotReadyOrNotConnected, ResStrings.BoxModeCreateUpdate_button1_Click_Box_Mode_Info, MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
示例#4
0
 // button Scan
 private void buttonScan_Click(object sender, EventArgs e)
 {
     if (device == null)
     {
         return;
     }
     if ((device.ConnectionStatus == ConnectionStatus.CS_Connected) &&
         (device.DeviceStatus == DeviceStatus.DS_Ready))
     {
         //Request a scan
         //Scan status will be notified by event
         device.ScanDevice();
     }
     else
     {
         MessageBox.Show("Device not ready or not connected");
     }
 }
        private void ScanDevice()
        {
            if (_currentEthernetDevice != null) // ethernet device : scan request, polling, tag blocks writing (if enabled by user)
            {
                TcpIpClient tcpClient = new TcpIpClient();
                string      status;

                if (tcpClient.getStatus(_currentEthernetDevice.IP_Server, _currentEthernetDevice.Port_Server,
                                        _currentEthernetDevice.SerialRFID, out status) != TcpIpClient.RetCode.RC_Succeed)
                {
                    MessageBox.Show(ResStrings.strErrorDevice, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                DeviceStatus currentStatus = (DeviceStatus)Enum.Parse(typeof(DeviceStatus), status);

                if (currentStatus != DeviceStatus.DS_Ready)
                {
                    MessageBox.Show(ResStrings.strDeviceEthernet_device_is_not_ready, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                InventoryData lastInventoryData;

                do // loop while we don't get a successful scan with ONE tag scanned
                {
                    if (tcpClient.requestScan(_currentEthernetDevice.IP_Server, _currentEthernetDevice.Port_Server,
                                              _currentEthernetDevice.SerialRFID) != TcpIpClient.RetCode.RC_Succeed) // scan starting has failed
                    {
                        MessageBox.Show(ResStrings.strdevice_Unable_to_start_scan);
                        return;
                    }

                    int tryIteration = 0;

                    do // loop while scan is not over (or if time limit excedeed [see Thread Sleep])
                    {
                        if (tryIteration > 4)
                        {
                            MessageBox.Show(ResStrings.strDevice_Scan_unexpectedly_long__please_retry, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }

                        ++tryIteration;
                        Thread.Sleep(600);

                        if (tcpClient.getStatus(_currentEthernetDevice.IP_Server, _currentEthernetDevice.Port_Server,
                                                _currentEthernetDevice.SerialRFID, out status) != TcpIpClient.RetCode.RC_Succeed)
                        {
                            MessageBox.Show(ResStrings.strErrorDevice, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }

                        currentStatus = (DeviceStatus)Enum.Parse(typeof(DeviceStatus), status);
                    } while (currentStatus == DeviceStatus.DS_InScan);

                    // scan terminated, now check if correct number of tag scanned (one)

                    if (tcpClient.requestGetLastScan(_currentEthernetDevice.IP_Server,
                                                     _currentEthernetDevice.Port_Server,
                                                     _currentEthernetDevice.SerialRFID, out lastInventoryData) != TcpIpClient.RetCode.RC_Succeed) // failed to get last inventorydata
                    {
                        MessageBox.Show(ResStrings.strDevice_Unable_to_get_last_scan_result, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (lastInventoryData == null) // failed to get last inventorydata
                    {
                        MessageBox.Show(ResStrings.strDevice_Unable_to_get_last_scan_result, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                } while (lastInventoryData.nbTagAll != 1);

                // we now have completed a scan with ONE tag
                string tagUid = lastInventoryData.listTagAll[0].ToString().Trim();
                toolStripStatusLabelInfo.Text = ResStrings.strScan_Completed_Tag_Scanned + tagUid;
                Invoke((MethodInvoker) delegate { textBoxTagID.Text = tagUid; });

                if (cbxAutoWrite.Checked)
                {
                    if (WriteLotId(tagUid, textBoxLotID.Text.Trim()))
                    {
                        Invoke((MethodInvoker) delegate { textBoxTagID.Text = textBoxLotID.Text; });
                        Invoke((MethodInvoker)ProcessTag);
                    }

                    else
                    {
                        Invoke((MethodInvoker) delegate { toolStripStatusLabelInfo.Text = ResStrings.ErrorWriting_new_tag_UID_failed; });
                    }
                }

                else
                {
                    Invoke((MethodInvoker)ProcessTag);
                }
            }

            else // (USB) local reader scan : requests a scan and everything is processed in RFID events
            {
                if (_device == null)
                {
                    return;
                }
                if ((_device.ConnectionStatus == ConnectionStatus.CS_Connected) &&
                    (_device.DeviceStatus == DeviceStatus.DS_Ready))
                {
                    _device.ScanDevice();
                }

                else
                {
                    MessageBox.Show(ResStrings.StrDeviceNotReadyOrNotConnected, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }