//If your device supports the USBCLient, you can refer to this. //Not all series devices can support this kind of connection.Please make sure your device supports USBClient. //Connect the device via the virtual serial port created by USBClient private void btnUSBConnect_Click(object sender, EventArgs e) { int idwErrorCode = 0; Cursor = Cursors.WaitCursor; if (btnUSBConnect.Text == "Disconnect") { axCZKEM1.Disconnect(); bIsConnected = false; btnUSBConnect.Text = "Connect"; btnUSBConnect.Refresh(); lblState.Text = "Current State:Disconnected"; Cursor = Cursors.Default; return; } SearchforUSBCom usbcom = new SearchforUSBCom(); string sCom = ""; bool bSearch = usbcom.SearchforCom(ref sCom);//modify by Darcy on Nov.26 2009 if (bSearch == false)//modify by Darcy on Nov.26 2009 { MessageBox.Show("Can not find the virtual serial port that can be used", "Error"); Cursor = Cursors.Default; return; } int iPort; for (iPort = 1; iPort < 10; iPort++) { if (sCom.IndexOf(iPort.ToString()) > -1) { break; } } iMachineNumber = Convert.ToInt32(txtMachineSN2.Text.Trim()); if (iMachineNumber == 0 || iMachineNumber > 255) { MessageBox.Show("The Machine Number is invalid!", "Error"); Cursor = Cursors.Default; return; } int iBaudRate = 115200;//115200 is one possible baudrate value(its value cannot be 0) bIsConnected = axCZKEM1.Connect_Com(iPort, iMachineNumber, iBaudRate); if (bIsConnected == true) { btnUSBConnect.Text = "Disconnect"; btnUSBConnect.Refresh(); lblState.Text = "Current State:Connected"; axCZKEM1.RegEvent(iMachineNumber, 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all) } else { axCZKEM1.GetLastError(ref idwErrorCode); MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error"); } Cursor = Cursors.Default; }
//If your device supports the USBCLient, you can refer to this. //Not all series devices can support this kind of connection.Please make sure your device supports USBClient. //Connect the device via the virtual serial port created by USBClient private void btnUSBConnect_Click(object sender, EventArgs e) { int idwErrorCode = 0; Cursor = Cursors.WaitCursor; if (btnUSBConnect.Text == "Disconnect") { axCZKEM1.Disconnect(); bIsConnected = false; btnUSBConnect.Text = "Connect"; btnUSBConnect.Refresh(); lblState.Text = "Current State:Disconnected"; Cursor = Cursors.Default; return; } SearchforUSBCom usbcom = new SearchforUSBCom(); string sCom = ""; bool bSearch = usbcom.SearchforCom(ref sCom); //modify by Darcy on Nov.26 2009 if (bSearch == false) //modify by Darcy on Nov.26 2009 { MessageBox.Show("Can not find the virtual serial port that can be used", "Error"); Cursor = Cursors.Default; return; } int iPort; for (iPort = 1; iPort < 10; iPort++) { if (sCom.IndexOf(iPort.ToString()) > -1) { break; } } iMachineNumber = Convert.ToInt32(txtMachineSN2.Text.Trim()); if (iMachineNumber == 0 || iMachineNumber > 255) { MessageBox.Show("The Machine Number is invalid!", "Error"); Cursor = Cursors.Default; return; } int iBaudRate = 115200;//115200 is one possible baudrate value(its value cannot be 0) bIsConnected = axCZKEM1.Connect_Com(iPort, iMachineNumber, iBaudRate); if (bIsConnected == true) { btnUSBConnect.Text = "Disconnect"; btnUSBConnect.Refresh(); lblState.Text = "Current State:Connected"; axCZKEM1.RegEvent(iMachineNumber, 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all) } else { axCZKEM1.GetLastError(ref idwErrorCode); MessageBox.Show("Unable to connect the device,ErrorCode=" + idwErrorCode.ToString(), "Error"); } Cursor = Cursors.Default; }