Painel de líderes
Conteúdo popular
Showing content with the highest reputation on 12-07-2015 em todas as áreas
-
Boa Tarde Pessoal! Desenvolvi um componente de integração com o PagSeguro, 100% Delphi. O mesmo está compatível com: Delphi 2009, 2010, XE, XE2, XE3, X4, X5, X6, XE7 e XE8 Está compatível para VCL e também para o Framework UniGui https://www.dropbox.com/s/e45ualteppmoesb/Captura de tela 2015-06-04 19.37.02.png?dl=0 (UniGui) https://www.dropbox.com/s/8n0q9pgt0ve33xo/Captura de tela 2015-06-30 20.31.08.png?dl=0 (VCL) https://www.dropbox.com/s/80mqktq5zcf7xli/Captura de tela 2015-06-04 19.45.42.png?dl=0 Para aqueles que tiverem interesse entre em contato pelo e-mail: [email protected]1 ponto
-
Compare o XML enviado ao SAT, com o XML recebido do SAT... várias das informações são preenchidas pelo próprio SAT1 ponto
-
Vou testar quando tiver um tempo.... o Fortes4Lazarus está tão estável que até esqueço dele...1 ponto
-
Claro: //no Contrutor private IntByReference handleBalanca = new IntByReference(); private void configuraBalanca() { try { ACBrBALInterop.INSTANCE.BAL_Create(handleBalanca); ACBrBALInterop.INSTANCE.BAL_SetModelo(handleBalanca.getValue(), 2); //2 é toledo ACBrBALInterop.INSTANCE.BAL_SetPorta(handleBalanca.getValue(), "COM2"); ACBrBALInterop.INSTANCE.BAL_Ativar(handleBalanca.getValue()); System.out.println("Porta Balança configurada no banco: " + "COM2"); System.out.println(handleBalanca.getValue()); System.out.println(2); System.out.println(ACBrBALInterop.INSTANCE.BAL_GetModelo(handleBalanca.getValue())); System.out.println(handleBalanca.getValue()); } catch (NumberFormatException t) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "", t); JOptionPane.showMessageDialog(rootPane, "Problema com a balança", "Verificar:", JOptionPane.ERROR_MESSAGE); } } //Depois pegando valor da balança: public static Double lePeso(int handle) throws ACBrException { DoubleByReference peso = new DoubleByReference(0.0); ACBrBALInterop.INSTANCE.BAL_LePeso(handle, 1000, peso); return peso.getValue(); } // minha chamada BigDecimal quantidadeProdutoFormatada = BigDecimal.valueOf(Balanca.lePeso(handleBalanca.getValue())); Também desenvolvi um pequena lib bem tosca que usa a RXTXComm para ler de certos modelos de balança de checkout, tipo aquelas elgin é só incluir o jar RXTXcomm.jar no seu projeto e adicionar essa classe: public class Balanca { RXTXCommDriver rxtx = new RXTXCommDriver(); private InputStream in; private OutputStream out; private int timeout = 100; public Balanca() { super(); } public void connect(String portName) throws gnu.io.PortInUseException, UnsupportedCommOperationException, NoSuchPortException, IOException { Enumeration ports = CommPortIdentifier.getPortIdentifiers(); CommPortIdentifier portIdentifier = null; while (ports.hasMoreElements()) { portIdentifier = (CommPortIdentifier) ports.nextElement(); if (portIdentifier.getName().equalsIgnoreCase(portName)) { System.out.println(portIdentifier.getName()); break; } } // CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName); if (portIdentifier != null) { if (portIdentifier.isCurrentlyOwned()) { System.out.println("Erro: Porta já está em uso"); } else { CommPort commPort = portIdentifier.open(this.getClass().getName(), 2_000); if (commPort instanceof SerialPort) { SerialPort serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(9_600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); in = serialPort.getInputStream(); // out = serialPort.getOutputStream(); } else { System.out.println("Erro: Somente as portas seriais são tratadas."); } } } else { System.err.println("erro porta não encontrada."); throw new NoSuchPortException(); } } public String getPesoStr() throws IOException { return lerPeso().toString(); } public Double getPesoDb() throws IOException { return lerPeso().doubleValue(); } public BigDecimal getPesoBd() throws IOException { return lerPeso(); } public BigDecimal getPesoBd(int scale) throws IOException { return lerPeso(); } public BigDecimal getPesoBd(int scale, RoundingMode roundingMode) throws IOException { return lerPeso().setScale(scale, roundingMode); } public void atribuirPeso(javax.swing.text.JTextComponent tc) throws IOException { tc.setText(lerPeso().toString()); } public void atribuirPesoFmt(javax.swing.text.JTextComponent tc) throws IOException { tc.setText(String.format("%.2f", lerPeso())); } public BigDecimal getValorPeso(BigDecimal valorKg, int scale, RoundingMode roundingMode) throws IOException { return valorKg.multiply(getPesoBd()).setScale(scale, roundingMode); } public BigDecimal getValorPeso(String valorKg, int scale, RoundingMode roundingMode) throws IOException { return getValorPeso(new BigDecimal(valorKg), scale, roundingMode); } public BigDecimal getValorPeso(Double valorKg, int scale, RoundingMode roundingMode) throws IOException { return getValorPeso(new BigDecimal(String.valueOf(valorKg)), scale, roundingMode); } private BigDecimal lerPeso() throws IOException { int len = -1; BigDecimal valor = BigDecimal.ZERO; byte[] buffer = new byte[1_024]; if ((len = in.read(buffer)) > -1) { try { Thread.sleep(timeout); } catch (InterruptedException ex) { Logger.getLogger(Balanca.class.getName()).log(Level.SEVERE, null, ex); } String lido = (new String(buffer, 0, len)); valor = trataRetorno(lido); } return valor; } private BigDecimal trataRetorno(String r) { if (r == null) { return BigDecimal.ZERO; } r = r.split("\\r")[0].trim(); if (r.isEmpty()) { return BigDecimal.ZERO; } try { BigDecimal b = new BigDecimal(r); //if maior que 15, balanca elgin so permite 15 if (b.compareTo(new BigDecimal("15")) >= 0) { return BigDecimal.ZERO; } return b; } catch (NumberFormatException e) { System.err.println(e); return BigDecimal.ZERO; } } public void setTimeout(int timeout) { this.timeout = timeout; } } testando: try { Balanca b = new Balanca(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Digite a porta da balanca: "); String porta = br.readLine(); b.connect(porta); // b.setTimeout(500); while (true) { System.out.println("STR: " + b.getPesoStr()); // System.out.println("DB: " + b.getPesoDb()); // System.out.println("BD: " + b.getPesoBd()); // System.out.println("BDSc: " + b.getPesoBd(3)); // System.out.println("BDScRM: " + b.getPesoBd(3, RoundingMode.UP)); // System.out.println("-------------------------------------------"); // System.out.println("TOTAL: " + b.getValorPeso("10.100", 3, RoundingMode.UP)); // System.out.println("-------------------------------------------"); // System.in.read(); } } catch (gnu.io.PortInUseException | UnsupportedCommOperationException | NoSuchPortException | IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } Espero ter ajudado, abraços.1 ponto