Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Enumeration commports = CommPortIdentifier.getPortIdentifiers();
- CommPortIdentifier myCPI = null;
- Scanner mySC = null;
- while (commports.hasMoreElements()) {
- myCPI = (CommPortIdentifier) commports.nextElement();
- if (myCPI.getName().equals("COM3"));
- break;
- }
- CommPort puerto = null;
- try {
- puerto = myCPI.open("Puerto Serial",1000);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(jPanel1, "Error B1", "ERROR", JOptionPane.ERROR_MESSAGE);
- }
- SerialPort mySP = (SerialPort) puerto;
- try {
- mySP.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_2, SerialPort.PARITY_NONE);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(jPanel1, "Error B2", "ERROR", JOptionPane.ERROR_MESSAGE);
- }
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException ex) {
- JOptionPane.showMessageDialog(jPanel1, "Error B3", "ERROR", JOptionPane.ERROR_MESSAGE);
- }
- Connection conexion = null;
- try {
- conexion = DriverManager.getConnection("jdbc:mysql://localhost/basculas", "root", "cay0703081");
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(jPanel1, "Error B4", "ERROR", JOptionPane.ERROR_MESSAGE);
- }
- int k = 0;
- while (k == 0) {
- try {
- mySC = new Scanner(mySP.getInputStream());
- } catch (IOException ex) {
- JOptionPane.showMessageDialog(jPanel1, "Error B5", "ERROR", JOptionPane.ERROR_MESSAGE);
- }
- if (mySC.nextLine() != null) {
- Statement st = null;
- try {
- st = conexion.createStatement();
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(jPanel1, "Error B6", "ERROR", JOptionPane.ERROR_MESSAGE);
- }
- try {
- st.executeUpdate("UPDATE peso_bascula SET peso='" + mySC.nextLine() + "' WHERE id='1'");
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(jPanel1, "Error B7", "ERROR", JOptionPane.ERROR_MESSAGE);
- }
- }
- //System.out.println (""+mySC.nextLine());
- // Thread.sleep(1000);
- }
- }
- // sleep(1000);
- } // Fin del while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement