Is there any way to send data through a USB connection with Processing?

Hello, good afternoon:

I have a problem with a thermal printer drivers, samsung BIXOLON SPR 350 II.

The main problem is that the printer is recognized as usb port. I would turn that USB port to COM to use the processing.serial library. But I've tried to change and is not possible.

Is there a way to send a string of data through the USB port using processing?

Other solutions I have tried without success and who may be possible: -Mandar From app to windows, a print order, a .txt document. Maybe send a sequence of commands with MS-2 file path.

Print document from java, I tried several stackoverflow codes but give me error.

thanks

Tagged:

Answers

  • Answer ✓

    Bueno, finalmente he conseguido hacer funcionar un código de java en processing y con unos retoques tengo funcionando la impresora, dejo el código retocado por si puede servirle a alguien:

    import javax.print.*;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    PrintWriter output;
    
     void setup(){
    for(int i = 0; i < 6; i++){ datos_imprimir(ENTER +Integer.toString(i)+"IMPRIMIENDO"+OK+"?"+ENTER+"VAMOS!"+ENTER);}
     }
    
    void datos_imprimir(String datos)
    {
      output = createWriter("C:/SIACER/D.txt");
      output.println(datos);
      output.flush();
       try{imprimir_documento("C:/SIACER/D.txt");}catch(Exception e){}
    }
    
    
    
    void imprimir_documento(String direccion) throws IOException {
    
            FileInputStream inputStream = null;
            try {
                inputStream = new FileInputStream(direccion);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            if (inputStream == null) {
                return;
            }
    
            DocFlavor docFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
            Doc document = new SimpleDoc(inputStream, docFormat, null);
    
            PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
    
            PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
    
    
            if (defaultPrintService != null) {
                DocPrintJob printJob = defaultPrintService.createPrintJob();
                try {
                    printJob.print(document, attributeSet);
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                System.err.println("No existen impresoras instaladas");
            }
    
            inputStream.close();
        }
    
  • _vk_vk
    edited April 2015 Answer ✓

    Thanks for sharing @anthony20 (Gracias por compartir)

    Free translation from above post:

    Well, finally I got a Java code, that, with some tweaks, is working to print trough Processing. Below the tweaked code in case someone needs it.

Sign In or Register to comment.