/// <summary> /// <c>buttonCreateDevice_Click</c> is called when user clicks on Create button. /// This function initializes <c>_currentUSBDevice</c> by creating a new RFID_Device. /// </summary> private void buttonCreateDevice_Click(object sender, EventArgs e) { if (_currentUSBDevice != null) { if (_currentUSBDevice.ConnectionStatus != ConnectionStatus.CS_Connected) { _currentUSBDevice.ReleaseDevice(); // Release previous object if not connected } } _currentUSBDevice = new RFID_Device(); // Create a new object UpdateStatusBar("Info : In connection "); buttonCreateDevice.Enabled = false; _currentUSBDevice.NotifyRFIDEvent += (rfidDev_NotifyRFIDEvent); // Let's create appropriate smartboard device // The task is under a threadpool because scanning all ports (if you decide to do so) makes the UI freeze. ThreadPool.QueueUserWorkItem( delegate { // Give the COM port as second parameter to avoid looking for all com ports again => faster connection. _currentUSBDevice.Create_NoFP_Device(_arrayOfPluggedDevice[_selectedDevice].SerialRFID, _arrayOfPluggedDevice[_selectedDevice].portCom); // Remove the second parameter if you want to force the program to look for all COM ports again if (_currentUSBDevice.get_RFID_Device.FirmwareVersion.StartsWith("1")) { MessageBox.Show("Invalid firmware version"); _currentUSBDevice.ReleaseDevice(); } }); }
public bool ConnectRFIDandScale(string serialRFID, string portCom) { this.serialRFID = serialRFID; isScaleConnected = false; isRfidConnected = false; // release previous object if not connected if (device != null) { device.ReleaseDevice(); } //Create a new object device = new RFID_Device(); //subscribe the event device.NotifyRFIDEvent += new NotifyHandlerRFIDDelegate(rfidDev_NotifyRFIDEvent); //Create a d device eventEndConnection.Reset(); device.Create_NoFP_Device(serialRFID, portCom); eventEndConnection.WaitOne(); if (isRfidConnected && isScaleConnected) { return(true); } else { return(false); } }
private void buttonCreate_Click(object sender, EventArgs e) { if (_arrayOfPluggedDevice.Length - 1 < _selectedDeviceIndex) // Ethernet devices are added (in comboBox) after USB devices. Their index is greater than _arrayOfPluggedDevice length { MessageBox.Show(ResStrings.str_create_Ethernet_devices, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // release previous object if not connected if (_device != null) { if (_device.ConnectionStatus != ConnectionStatus.CS_Connected) { _device.ReleaseDevice(); } } _device = new RFID_Device(); toolStripStatusLabelInfo.Text = ResStrings.str_In_Connection_; buttonCreate.Enabled = false; _device.NotifyRFIDEvent += new NotifyHandlerRFIDDelegate(rfidDev_NotifyRFIDEvent); ThreadPool.QueueUserWorkItem( delegate { switch (_arrayOfPluggedDevice[_selectedDeviceIndex].deviceType) { case DeviceType.DT_SBR: case DeviceType.DT_STR: _device.Create_NoFP_Device(_arrayOfPluggedDevice[_selectedDeviceIndex].SerialRFID, _arrayOfPluggedDevice[_selectedDeviceIndex].portCom); _currentEthernetDevice = null; break; default: MessageBox.Show(ResStrings.str_OnlySBR_STR, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } }); }
private void comboBoxReader_SelectedIndexChanged(object sender, EventArgs e) { if (_arrayOfPluggedDevice == null) { return; } // release previous object if not connected if (_device != null) { if (_device.ConnectionStatus != ConnectionStatus.CS_Connected) { _device.ReleaseDevice(); } } //Create a new object _device = new RFID_Device(); toolStripStatusLabelInfo.Text = ResStrings.str_In_Connection_; //subscribe the event _device.NotifyRFIDEvent += new NotifyHandlerRFIDDelegate(rfidDev_NotifyRFIDEvent); //Create a smartboard device //As the function search on all the serial port of the PC, this connection can //take some time and is under a thread pool to avoid freeze of the GUI switch (_arrayOfPluggedDevice[selectedDevice].deviceType) { case DeviceType.DT_SBR: case DeviceType.DT_STR: // Use create with portcom parameter for speed connection (doesn't search again the reader at is is previouly done; _device.Create_NoFP_Device(_arrayOfPluggedDevice[selectedDevice].SerialRFID, _arrayOfPluggedDevice[selectedDevice].portCom); //device.Create_NoFP_Device(arrayOfPluggedDevice[selectedDevice].SerialRFID); break; default: MessageBox.Show(ResStrings.str_OnlySBR_STR, ResStrings.BoxModeCreateUpdate_button1_Click_Box_Mode_Info, MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } }
private void FindDeviceAndConnect(string serial) { arrayOfPluggedDevice = null; RFID_Device tmp = new RFID_Device(); arrayOfPluggedDevice = tmp.getRFIDpluggedDevice(false); tmp.ReleaseDevice(); if (arrayOfPluggedDevice != null) { foreach (rfidPluggedInfo dev in arrayOfPluggedDevice) { if (dev.SerialRFID.Equals(serial)) { if (device != null) { if (device.ConnectionStatus != ConnectionStatus.CS_Connected) { device.ReleaseDevice(); } } //Create a new object device = new RFID_Device(); updatelabel("Info : In Connection"); //subscribe the event device.NotifyRFIDEvent += new NotifyHandlerRFIDDelegate(rfidDev_NotifyRFIDEvent); device.Create_NoFP_Device(dev.SerialRFID, dev.portCom); break; } } } else { updatelabel("Info : No Device Detected!"); } }