private void Search() { toolStripStatusInfo.Text = ResStrings.str_Status; if (textBoxIPAddress.Text.Contains(".")) { _ip = textBoxIPAddress.Text; } else { _ip = System.Net.Dns.GetHostEntry(textBoxIPAddress.Text).AddressList[0].ToString(); } if (TcpIP_class.tcpUtils.CheckIp(_ip)) { _port = 0; int.TryParse(textBoxPort.Text, out _port); if (TcpIP_class.tcpUtils.PingAddress(_ip, 1000)) { TcpIP_class.TcpIpClient tcp = new TcpIP_class.TcpIpClient(); if (tcp.pingServer(_ip, _port) == TcpIP_class.TcpIpClient.RetCode.RC_Succeed) { toolStripStatusInfo.Text = ResStrings.str_Ping_Server_OK; tcp.getDevice(_ip, _port, out _dev); UpdateListReader(); } else { toolStripStatusInfo.Text = string.Format(ResStrings.str_Unable_to_connect_to_server, _ip, _port); } } else { toolStripStatusInfo.Text = string.Format(ResStrings.str_Unable_to_connect_to_machine, _ip); } } else { toolStripStatusInfo.Text = string.Format(ResStrings.str_Enter_a_valid_IP_or_DNS_Not_Resolve_adress, textBoxIPAddress.Text); } }
private void button1_Click(object sender, EventArgs e) { WriteCode codeResult = WriteCode.WC_Error; string newUid = textBoxNewUID.Text.Trim(); string initialUid = _db.GetInitialUID(newUid); if (!string.IsNullOrEmpty(initialUid)) { List <UidWriteHistory> tmpList = _db.GetUidHistory(initialUid); if (tmpList != null) { if (tmpList[0]._writtenUid == newUid) { MessageBox.Show(ResStrings.str_UID_already_in_use_Please_Change_UID); return; } } } if (comboBoxSelWrite.SelectedIndex == 0) { if ((!SDK_SC_RfidReader.DeviceBase.SerialRFID.isStringValidToWrite(textBoxNewUID.Text.Trim()) || (textBoxNewUID.Text.Length > 17))) { MessageBox.Show(ResStrings.str_Invalid_Tag_ID, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (comboBoxSelWrite.SelectedIndex == 1) { System.Text.RegularExpressions.Regex myRegex = new Regex(@"^[0-9]+$"); if ((!myRegex.IsMatch(textBoxNewUID.Text)) || (textBoxNewUID.Text.Length > 12)) { MessageBox.Show(ResStrings.str_Invalid_Tag_ID, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (!_isEthernetDevice) // (USB) local reader { if ((_currentDevice.ConnectionStatus == ConnectionStatus.CS_Connected) && (_currentDevice.DeviceStatus == DeviceStatus.DS_Ready)) { if (comboBoxSelWrite.SelectedIndex == 0) //SPCE2 With family { codeResult = _currentDevice.WriteNewUidWithFamily(_previousUid, newUid); } else if (comboBoxSelWrite.SelectedIndex == 1) // SPCE2 Decimal { codeResult = _currentDevice.WriteNewUidDecimal(_previousUid, newUid); } else { MessageBox.Show(ResStrings.str_RFID_device_not_ready); return; } } } else // (Ethernet) Remote reader { TcpIP_class.TcpIpClient tcpClient = new TcpIP_class.TcpIpClient(); tcpClient.RequestWriteBlock(_currentDeviceClass.infoDev.IP_Server, _currentDeviceClass.infoDev.Port_Server, _previousUid, newUid, out codeResult, comboBoxSelWrite.SelectedIndex); } 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.str_Tag_blocked_or_not_well_supplied__Operation_failed); break; case WriteCode.WC_TagBlocked: MessageBox.Show(ResStrings.str_Tag_blocked__Operation_failed); break; case WriteCode.WC_TagNotSupplied: MessageBox.Show(ResStrings.str_Tag_not_well_supplied__Operation_failed); break; case WriteCode.WC_ConfirmationFailed: MessageBox.Show(ResStrings.str_Updated_tag_confirmation_has_failed); break; case WriteCode.WC_Success: _db.AddUidHistory(string.IsNullOrEmpty(_initialUid) ? _previousUid : _initialUid, newUid); if (_initialUid != null) { UpdateHistoryTable(_initialUid); } Application.DoEvents(); Thread.Sleep(200); MessageBox.Show(ResStrings.str_Tag_UID_succesfully_updated_); break; } Close(); }
private void toolStripButtonACreateNew_Click(object sender, EventArgs e) { toolStripStatusInfo.Text = ResStrings.str_Status; if (textBoxIPAddress.Text.Contains(".")) { _ip = textBoxIPAddress.Text; } else { _ip = System.Net.Dns.GetHostEntry(textBoxIPAddress.Text).AddressList[0].ToString(); } if (TcpIP_class.tcpUtils.CheckIp(_ip)) { _port = 0; int.TryParse(textBoxPort.Text, out _port); if (TcpIP_class.tcpUtils.PingAddress(_ip, 1000)) { TcpIP_class.TcpIpClient tcp = new TcpIP_class.TcpIpClient(); if (tcp.pingServer(_ip, _port) == TcpIP_class.TcpIpClient.RetCode.RC_Succeed) { _dev[listBoxReader.SelectedIndex].IP_Server = _serverIp; _dev[listBoxReader.SelectedIndex].Port_Server = _serverPort; //if (tcp.enableRemoteAccess(IP, port, dev[listBoxReader.SelectedIndex]) == TcpIP_class.TcpIpClient.RetCode.RC_Succeed) //{ MainDBClass db = new MainDBClass(); if (db.OpenDB()) { _dev[listBoxReader.SelectedIndex].IP_Server = _ip; _dev[listBoxReader.SelectedIndex].Port_Server = _port; if (db.StoreDevice(_dev[listBoxReader.SelectedIndex], true)) { MessageBox.Show(ResStrings.str_DATA_SAVED, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(ResStrings.str_Error_while_Saving_Data, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); } db.CloseDB(); } // } //else //{ // toolStripStatusInfo.Text = "Status : Error while set Remote On server"; //} } else { toolStripStatusInfo.Text = string.Format(ResStrings.Rstr_Unable_to_connect_to_server__0__on_port__1, _ip, _port); } } else { toolStripStatusInfo.Text = string.Format(ResStrings.str_Unable_to_connect_to_machine__0, _ip); } } else { toolStripStatusInfo.Text = string.Format(ResStrings.str_Status___Enter_a_valid_IP_or_DNS_Not_Resolve_adress__0_, textBoxIPAddress.Text); } UpdateGrid(); }
public void CanStartScan() { bIsWaitingScan = true; if (bUseSynchonisation) { LogToFile.LogMessageToFile("------ Sync Scan ------"); bool bFirstPass = true; int bQuitValue = 0; int bQuitCondition = 0; int waitRight = 0; int waitLeft = 0; int doorOpen = 0; if (!string.IsNullOrEmpty(DeviceIpRight)) { bQuitCondition++; } if (!string.IsNullOrEmpty(DeviceIpLeft)) { bQuitCondition++; } TcpIpClient tcp = new TcpIP_class.TcpIpClient(); TcpIpClient.RetCode ret; expiredTime = DateTime.Now.AddSeconds(TimeoutInSec); //time to quit in any case Random rnd = new Random(); do { if (!bIsWaitingScan) { return; //quit if requested } //remove for LED /* * TimeSpan ts = expiredTime - DateTime.Now; * if (ts.TotalSeconds < 0) * { * bIsWaitingScan = false; * return; * } */ bQuitValue = 0; if (!string.IsNullOrEmpty(DeviceIpLeft)) // J'ai un device à gauche { // if (tcpUtils.PingAddress(DeviceIpLeft, 1000)) //{ ret = tcp.pingServer(DeviceIpLeft, DevicePortLeft); if (ret == TcpIpClient.RetCode.RC_Succeed) { DeviceStatus ds = DeviceStatus.DS_NotReady; string status; ret = tcp.getStatus(DeviceIpLeft, DevicePortLeft, null, out status); if (ret == TcpIpClient.RetCode.RC_Succeed) { ds = (DeviceStatus)Enum.Parse(typeof(DeviceStatus), status); if ((ds == DeviceStatus.DS_WaitForScan) || (ds == DeviceStatus.DS_WaitForLed)) { waitLeft++; } else { waitLeft = 0; } if (bFirstPass) { if (ds == DeviceStatus.DS_DoorOpen) { doorOpen++; if (doorOpen > 2) { bQuitValue++; } } else if ((ds == DeviceStatus.DS_InScan) || (ds == DeviceStatus.DS_LedOn) || (ds == DeviceStatus.DS_WaitForScan) || (ds == DeviceStatus.DS_WaitForLed)) { // need to wait if (waitLeft > 4) //gauche en wait depuis long temps on lance { bQuitValue++; } } else { bQuitValue++; } } else { if (ds == DeviceStatus.DS_DoorOpen) { doorOpen++; if (doorOpen > 2) { bQuitValue++; } } else if ((ds == DeviceStatus.DS_InScan) || (ds == DeviceStatus.DS_LedOn) || (ds == DeviceStatus.DS_WaitForScan) || (ds == DeviceStatus.DS_WaitForLed)) { // need to wait if (waitLeft > 4) //gauche en wait depuis long temps on lance { bQuitValue++; } } else { bQuitValue++; } } } else { bQuitValue++; } } else { bQuitValue++; } // } // else //pas de ping // bQuitValue++; } if (!string.IsNullOrEmpty(DeviceIpRight)) // J'ai un device à droite { //if (tcpUtils.PingAddress(DeviceIpRight, 1000)) //{ ret = tcp.pingServer(DeviceIpRight, DevicePortRight); if (ret == TcpIpClient.RetCode.RC_Succeed) { DeviceStatus ds = DeviceStatus.DS_NotReady; string status; ret = tcp.getStatus(DeviceIpRight, DevicePortRight, null, out status); if (ret == TcpIpClient.RetCode.RC_Succeed) { ds = (DeviceStatus)Enum.Parse(typeof(DeviceStatus), status); if ((ds == DeviceStatus.DS_WaitForScan) || (ds == DeviceStatus.DS_WaitForLed)) { waitRight++; } else { waitRight = 0; } if ((ds == DeviceStatus.DS_InScan) || (ds == DeviceStatus.DS_LedOn) || (ds == DeviceStatus.DS_WaitForScan) || (ds == DeviceStatus.DS_WaitForLed)) { // need to wait if (waitRight > 2) //droite en wait depuis long temps on lance { bQuitValue++; } } else { bQuitValue++; } } else { bQuitValue++; } } else { bQuitValue++; } //} //else //pas de ping // bQuitValue++; } if (bFirstPass) { bFirstPass = false; } else { tcpUtils.NonBlockingSleep(rnd.Next(1000, 3000)); } }while (bQuitValue != bQuitCondition); } bIsWaitingScan = false; LogToFile.LogMessageToFile("------ End Sync Scan ------"); }