private void btnConnect_Click(object sender, EventArgs e) { try { device = new Device(); device.DN = 1; device.Password = "******"; device.Model = "A-C030"; device.ConnectionModel = 5;//等于5时才能正确加载ZD2911通讯模块 if (rdb_Network.Checked == true) { //ip address if (string.IsNullOrEmpty(txt_IP.Text.Trim())) { MessageBox.Show("Please Input IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_IP.Focus(); return; } if (false == ConvertObject.IsCorrenctIP(txt_IP.Text.Trim())) { MessageBox.Show("Illegal IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_IP.Focus(); return; } device.IpAddress = txt_IP.Text.Trim(); device.IpPort = int.Parse(txt_Port.Text); device.CommunicationType = CommunicationType.Tcp; } else { device.CommunicationType = CommunicationType.Usb; } deviceConnection = DeviceConnection.CreateConnection(ref device); if (deviceConnection.Open() > 0) { deviceEty = new DeviceComEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; MessageBox.Show("Device successfully connected", "System", MessageBoxButtons.OK, MessageBoxIcon.Information); btnBiometricData.Enabled = true; btnDisconnect.Enabled = true; btnConnect.Enabled = false; } else { MessageBox.Show("Failed to Connect to Device", "System", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_ParamSet_Click(object sender, EventArgs e) { if (-1 == cbo_Param.SelectedIndex) { MessageBox.Show("Please Select Parameter", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); cbo_Param.Focus(); return; } try { int paramValue = -1; switch (cbo_Param.SelectedIndex) { case 26: case 27: case 28: case 29: if (false == ConvertObject.IsCorrenctIP(txt_ParamValue.Text.Trim())) { MessageBox.Show("Illegal IP address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_ParamValue.Focus(); return; } paramValue = ConvertObject.ConvertIPAddressToNumber(txt_ParamValue.Text.Trim()); break; default: paramValue = Convert.ToInt32(txt_ParamValue.Text.Trim()); break; } object extraProperty = new object(); object extraData = new object(); byte[] data = new byte[8]; Array.Copy(BitConverter.GetBytes(cbo_Param.SelectedIndex), 0, data, 0, 4); Array.Copy(BitConverter.GetBytes(paramValue), 0, data, 4, 4); extraData = data; bool result = deviceConnection.SetProperty(DeviceProperty.SysParam, extraProperty, device, extraData); if (result) { MessageBox.Show("Set Parameter Success", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Set Parameter Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_OpenDevice_Click(object sender, EventArgs e) { try { device = new Device(); device.DN = (int)nud_DN.Value; device.Password = nud_Pwd.Value.ToString(); device.Model = "ZDC2911"; device.ConnectionModel = 5;//等于5时才能正确加载ZD2911通讯模块 if (rdb_USB.Checked) { device.CommunicationType = CommunicationType.Usb; } else if (rdb_TCP.Checked) { if (string.IsNullOrEmpty(txt_IP.Text.Trim())) { MessageBox.Show("Please Input IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_IP.Focus(); return; } if (false == ConvertObject.IsCorrenctIP(txt_IP.Text.Trim())) { MessageBox.Show("Illegal IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_IP.Focus(); return; } device.IpAddress = txt_IP.Text.Trim(); device.IpPort = (int)nud_Port.Value; device.CommunicationType = CommunicationType.Tcp; } else if (rdb_COMM.Checked) { device.SerialPort = Convert.ToInt32(cbo_COMM.SelectedItem.ToString().Replace("COM", string.Empty)); device.Baudrate = Convert.ToInt32(cbo_BaudRate.SelectedItem); device.CommunicationType = CommunicationType.Serial; } else if (p2pRadioButton.Checked) { device.CommunicationType = CommunicationType.P2P; device.SerialNumber = p2pAddrTextBox.Text.Trim(); //20130819 Riss.Devices.P2pUtils.SetP2pServerIpAddress(p2pServerTextBox.Text.Trim()); } deviceConnection = DeviceConnection.CreateConnection(ref device); if (deviceConnection.Open() > 0) { deviceEty = new DeviceCommEty(); deviceEty.Device = device; deviceEty.DeviceConnection = deviceConnection; btn_CloseDevice.Enabled = true; SetButtonEnabled(true); btn_OpenDevice.Enabled = false; } else { MessageBox.Show("Connect Device Fail", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error1", MessageBoxButtons.OK, MessageBoxIcon.Error); } }