/** * Open connection with device. Connection is opened automatically when object is created but can * be closed by user * * @throws CardReaderException * @see pl.edu.pw.mini.x1.janiszewskit.SwipeCardReader.Reader.Device#close() */ public void open() throws CardReaderException { try { device = manager.openById(vendor, id, null); } catch (IOException e) { throw new CardReaderException("Cannot open device", e.getCause()); } }
/** * Method resposible for loading native code and set up devices manager Should be called as a * first method, before start doing anything. * * @throws CardReaderException */ private void loadDriver() throws CardReaderException { com.codeminders.hidapi.ClassPathLibraryLoader.loadNativeHIDLibrary(); if (manager == null) { try { manager = HIDManager.getInstance(); } catch (IOException e) { throw new CardReaderException("Cannot initialize HIDManager", e.getCause()); } } }
private void connectToDevice(int firmwareVersion) { try { if (m_Device != null) { m_Device.close(); m_Device = null; } m_Device = m_Manager.openById(DeviceConstant.VENDOR_ID, DeviceConstant.PRODUCT_ID, serialNumber); if (m_Device != null) { IsConnected = true; m_Device.disableBlocking(); m_ButtonUI.setEnable(ButtonUI.BUTTON_START, true); m_ButtonUI.setEnable(ButtonUI.BUTTON_STOP, false); m_ButtonUI.setEnable(ButtonUI.BUTTON_PROTOCOL, true); m_PCRStatusText.setMessage(m_Device.getSerialNumberString(), 0); m_PCRTask.setTimer(NopTimer.TIMER_NUMBER); setTitle(m_Device.getSerialNumberString()); setSerialNumber(m_Device.getSerialNumberString()); gLEDOn(); if (firmwareVersion == 0) currentVersion = null; else currentVersion = ((firmwareVersion >> 8) & 0xff) + "." + (firmwareVersion & 0xff); // 150506 YJ Firmware check disable // UpdateFromServer(); } else { // ���� ���� ó�� System.out.println("Fatal Error!"); gLEDOff(); } } catch (IOException e) { e.printStackTrace(); } }
/** * UI�� �ʱ�ȭ �ϰų�, ��ü���� �ʱ�ȭ �ϴ� ������ �Ѵ�. MainUI() �����ڿ����� ȣ���� �� �ִ�. �� �ѹ��� ȣ��ȴ�. */ private void init() { // �������� ũ�� ���� setBounds( (Resolution.X * 2 / 5), Resolution.Y / 4, UIConstant.MYPCR_WIDTH, UIConstant.MYPCR_HEIGHT); // Ÿ��Ʋ ���� setTitle("MyPCR version 3.2"); // ����� ���α� ���� setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // �ִ�ȭ ���� setResizable(false); // title icon ���� setIconImage(new ImageIcon(getClass().getClassLoader().getResource("icon.png")).getImage()); // ���� ������Ʈ�� ������� Panel // ���̾ƿ��� ������ǥ�� ����ϱ� ���� null�� ���� m_Panel = new JPanel(); m_Panel.setLayout(null); m_Panel.setBackground(UIConstant.BACKGROUND_COLOR); // 3���� GroupBox�� title String[] titles = {"Serial Number", "CHAMBER", "LID HEATER"}; /** ������Ʈ ���� * */ m_ProtocolText = new ProtocolText(); m_PCRStatusText = StatusText.getInstance(UIConstant.GROUP_SIZE, titles); m_ProtocolList = ProtocolList.getInstance(); m_ButtonUI = ButtonUI.getInstance(this); m_LidText = new JTextField(); m_LidText.setLayout(null); m_LidText.setBounds(310, 55, 40, 20); m_LidText.setText("104"); m_LidText.addKeyListener(this); // �ΰ� �߰� JLabel labelLogo = new JLabel(new ImageIcon(getClass().getClassLoader().getResource("logo.jpg"))); labelLogo.setBounds(100, 385, 182, 37); // for bootloader mode labelLogo.addMouseListener( new MouseListener() { public void mouseReleased(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 3 && currentVersion != null) { String res = JOptionPane.showInputDialog( null, "Please input admin password for bootloader", "Admin Mode(Firmware V" + currentVersion + ")", JOptionPane.OK_CANCEL_OPTION); if (res != null) { if (res.equals(Constants.ADMIN_PASSWORD)) { if (m_ButtonUI.isEnable(ButtonUI.BUTTON_START)) OnHandleMessage(MESSAGE_STOP_PCR, null); Thread tempThread = new Thread() { public void run() { try { Thread.sleep(1000); OnMessage(DISCONNECTED, null, 0); Thread.sleep(1000); m_Device.write(m_PCRTask.m_TxAction.Tx_BootLoader()); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }; tempThread.start(); } else JOptionPane.showMessageDialog( null, "Wrong password!", "Admin Mode", JOptionPane.WARNING_MESSAGE); } } } }); // LED added icon_blueOff = new ImageIcon(url_blueOff); icon_blueOn = new ImageIcon(url_blueOn); icon_greenOff = new ImageIcon(url_greenOff); icon_greenOn = new ImageIcon(url_greenOn); icon_redOff = new ImageIcon(url_redOff); icon_redOn = new ImageIcon(url_redOn); ledBlue = new JLabel(icon_blueOff); ledBlue.setBounds(310, 1, 22, 29); ledRed = new JLabel(icon_redOff); ledRed.setBounds(332, 1, 22, 29); ledGreen = new JLabel(icon_greenOff); ledGreen.setBounds(354, 1, 22, 29); m_Panel.add(m_ProtocolText); m_Panel.add(m_PCRStatusText); m_Panel.add(m_ProtocolList.getPane()); m_Panel.add(m_ButtonUI.getPanel()); m_Panel.add(m_LidText); // 150509 logo and led added m_Panel.add(labelLogo); m_Panel.add(ledBlue); m_Panel.add(ledGreen); m_Panel.add(ledRed); /** ������Ʈ ���� * */ // �dz��� ���� �����ӿ� ���� add(m_Panel); // 150507 ȭ�鿡 UI �� ���� ���� ��ġ Ȯ���� ���� �ϱ� ���� ó�� // ȭ�鿡 ���̵��� // setVisible(true); // Device ���� üũ�� �ݹ� �Լ� ���� try { // DeviceManager �ν��Ͻ� ���� m_Manager = HIDManager.getInstance(); // Device ���� ���¸� ǥ�����ִ� �ݹ��Լ� ��� m_Callback_DeviceChange = CallbackDeviceChange.getInstance(m_Manager, this); m_Callback_DeviceChange.setDaemon(true); m_Callback_DeviceChange.start(); } catch (IOException e) { e.printStackTrace(); } // MyPCR ���� ����� ��� �ִ� ��ü�� �ν��Ͻ��� ���� m_PCRTask = PCR_Task.getInstance(this); }