Results 1 to 3 of 3
  1. #1
    schworak is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default JavaPOS, Star TSP100 and Linux

    Has anyone gotten this combination to work? I can't even get the sample code to work. It compiles but won't communicate.

    Error Message:
    Java Code:
    jpos.JposException: The device communications channel could not be opened, check the device and retry.
    	at com.starmicronics.starjavapos.POSPrinterStarBase.setDeviceEnabled(Unknown Source)
    	at jpos.BaseJposControl.setDeviceEnabled(Unknown Source)
    	at StarSlipTest.runTest(StarSlipTest.java:71)
    	at StarSlipTest.main(StarSlipTest.java:184)
    StarSlipTest finished.
    I have tried talking to the USB TSP100 via CUPS and it works fine although it looks ugly and lacks any real control so I have to go with JavaPOS to get true control and a good looking output. But I can't figure out how to get it to talk. And as I mentioned, this is Star's sample code. I haven't touched it except to fill in a couple sections that are unique to my printer (the name for example)

    Java source code:
    Java Code:
    // StarSlipTest.java
    // This file contains sample code illustrating how to use the POSPrinter class to
    // control your Star printer.  The basic printing and status querying mechanisms
    // are used here.  For more advanced usage of the POSPrinter class, see the
    // JavaPOS specification.
    
    // usage instructions - Windows
    // 1. compile from command line - javac -classpath jpos113-controls.jar;jcl.jar StarSlipTest.java
    // 2. execute from command line - java -classpath .;starjavapos.jar;stario.jar;jpos113-controls.jar;jcl.jar;xercesimpl.jar;xml-apis.jar StarSlipTest
    
    // usage instructions - Linux and Mac OS X
    // 1. compile from command line - javac -classpath jpos113-controls.jar:jcl.jar StarSlipTest.java
    // 2. execute from command line - java -classpath .:starjavapos.jar:stario.jar:jpos113-controls.jar:jcl.jar:xercesimpl.jar:xml-apis.jar StarSlipTest
    
    // NOTE: CHANGE THE PRINTER NAME IN THE printer.open STATEMENT BELOW TO MATCH YOUR CONFIGURED DEVICE NAME
    
    import jpos.JposConst;
    import jpos.JposException;
    import jpos.POSPrinter;
    import jpos.POSPrinterConst;
    
    import jpos.events.ErrorEvent;
    import jpos.events.ErrorListener;
    import jpos.util.JposPropertiesConst;
    
    public class StarSlipTest implements ErrorListener {
    	public void errorOccurred(ErrorEvent event) {
    		System.out.println("ErrorEvent received: time = " + System.currentTimeMillis()
    				+ " error code = " + event.getErrorCode()
    				+ " error code extended = " + event.getErrorCodeExtended());
    
    		try {
    			Thread.sleep(1000);
    		} catch (Exception e) {
    		}
    
    		event.setErrorResponse(JposConst.JPOS_ER_RETRY);
    	}
    
    	public void runTest(String[] args) {
    		/*
    		 * If you want to place the jpos.xml file elsewhere on your local file
    		 * system then uncomment the following line and specify the full path to
    		 * jpos.xml.
    		 * 
    		 * If you want to place the jpos.xml file on a web server for access over
    		 * the internet then uncomment the second System.setProperty line below
    		 * and specify the full URL to jpos.xml.
    		 */
    		System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "jpos.xml");
    		// System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_URL_PROP_NAME, "http://some-where-remote.com/jpos.xml");
    
    		// constants defined for convenience sake (could be inlined)
    		String ESC = ((char) 0x1b) + "";
    		String LF = ((char) 0x0a) + "";
    		String SPACES = "                                                                      ";
    
    		// instantiate a new jpos.POSPrinter object
    		POSPrinter printer = new POSPrinter();
    		try {
    			// register for asynchronous ErrorEvent notification
    			printer.addErrorListener(this);
    
    			// open the printer object according to the entry names defined in jpos.xml
    			printer.open("POSPrinter_linux_usb_printer_class");
    
    			// claim exclusive usage of the printer object
    			printer.claim(1);
    
    			// enable the device for input and output
    			printer.setDeviceEnabled(true);
    
    			// set map mode to metric - all dimensions specified in 1/100mm units
    			printer.setMapMode(POSPrinterConst.PTR_MM_METRIC); // unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units
    
    			do {
    				// register for asynchronous StatusUpdateEvent notification
    				// see the JavaPOS specification for details on this
    
    				// check if the cover is open
    				if (printer.getCoverOpen() == true) {
    					System.out.println("printer.getCoverOpen() == true");
    
    					// cover open so do not attempt printing
    					break;
    				}
    
    				// check if the printer is out of paper
    				if (printer.getSlpEmpty() == true) {
    					System.out.println("printer.getSlpEmpty() == true");
    
    					// the printer is out of paper so do not attempt printing
    					break;
    				}
    
    				// being a transaction
    				// transaction mode causes all output to be buffered
    				// once transaction mode is terminated, the buffered data is
    				// outputted to the printer in one shot - increased reliability
    				printer.transactionPrint(POSPrinterConst.PTR_S_SLIP, POSPrinterConst.PTR_TP_TRANSACTION);
    
    				if (printer.getCapSlpBitmap() == true) {
    					// print an image file
    					try {
    						printer.printBitmap(POSPrinterConst.PTR_S_SLIP, "star.gif", POSPrinterConst.PTR_BM_ASIS, POSPrinterConst.PTR_BM_CENTER);
    					} catch (JposException e) {
    						if (e.getErrorCode() != JposConst.JPOS_E_NOEXIST) {
    							// error other than file not exist - propogate it
    							throw e;
    						}
    
    						// image file not found - ignore this error & proceed
    					}
    				}
    
    				// call printNormal repeatedly to generate out receipt the following
    				// JavaPOS-POSPrinter control code sequences are used here
    				// ESC + "|cA" -> center alignment
    				// ESC + "|4C" -> double high double wide character printing
    				// ESC + "|bC" -> bold character printing
    				// ESC + "|uC" -> underline character printing
    				// ESC + "|rA" -> right alignment
    
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|cA" + ESC + "|4C" + ESC + "|bC" + "Star Grocer" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|cA" + ESC + "|bC" + "Shizuoka, Japan" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|cA" + ESC + "|bC" + "054-555-5555" + LF);
    
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|uC" + "Qnty Unit Tx Description"
    						+ SPACES.substring(0, printer.getSlpLineChars() - "Qnty Unit Tx Description".length()) + LF);
    
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, "   1  830    Soba Noodles" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, "   1  180    Daikon Radish" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, "   1  350    Shouyu Soy Sauce" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, "   1   80    Negi Green Onions" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, "   1  100    Wasabi Horse Radish" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, "   2  200 Tx Hashi Chop Sticks" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, LF);
    
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|rA" + "Subtotal:  2160" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|rA" + "Tax:         24" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|rA" + ESC + "|bC" + "Total:     2184" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|rA" + "Tender:    2200" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|rA" + ESC + "|bC" + "Change:      16" + LF);
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, LF);
    
    				if (printer.getCapSlpBarCode() == true) {
    					// print a Code 3 of 9 barcode with the data "123456789012" encoded
    					// the 10 * 100, 60 * 100 parameters below specify the barcode's
    					// height and width in the metric map mode (1cm tall, 6cm wide)
    					printer.printBarCode(POSPrinterConst.PTR_S_SLIP, "123456789012", POSPrinterConst.PTR_BCS_Code39,
    							10 * 100, 60 * 100, POSPrinterConst.PTR_BC_CENTER, POSPrinterConst.PTR_BC_TEXT_BELOW);
    				}
    
    				printer.printNormal(POSPrinterConst.PTR_S_SLIP, ESC + "|cA" + ESC + "|4C" + ESC + "|bC" + "Thank you" + LF);
    
    				// terminate the transaction causing all of the above buffered data to be sent to the printer
    				printer.transactionPrint(POSPrinterConst.PTR_S_SLIP, POSPrinterConst.PTR_TP_NORMAL);
    
    				// Paper feed
    				printer.beginRemoval(-1);
    
    				printer.endRemoval();
    
    				// exit our printing loop
    			} while (false);
    		} catch (JposException e) {
    			// display any errors that come up
    			e.printStackTrace();
    		} finally {
    			// close the printer object
    			try {
    				while (printer.getState() != JposConst.JPOS_S_IDLE) {
    					Thread.sleep(0);
    				}
    
    				printer.close();
    			} catch (Exception e) {
    			}
    		}
    		System.out.println("StarSlipTest finished.");
    	}
    
    	public static void main(String[] args) {
    		new StarSlipTest().runTest(args);
    	}
    }
    The jpos.xml file:
    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE JposEntries PUBLIC "-//JavaPOS//DTD//EN" "jpos/res/jcl.dtd">
    <JposEntries>
    
      <JposEntry logicalName="POSPrinter_linux_usb_printer_class">
        <creation factoryClass="com.starmicronics.starjavapos.ServiceInstanceFactory" serviceClass="com.starmicronics.starjavapos.POSPrinterService" />
        <vendor name="Star Micronics" url="www.star-m.jp/eng/index.htm" />
        <jpos category="POSPrinter" version="1.13" />
        <product description="Star receipt printer" name="Star Micronics POSPrinter controller" url="www.star-m.jp/eng/index.htm" />
        <prop name="model" type="String" value="TSP100" />
        <prop name="portName" type="String" value="usbprn:TSP100" />
        <prop name="portSettings" type="String" value="" />
        <prop name="ioTimeoutMillis" type="Integer" value="5000" />
        <prop name="doCheckedBlockPrinting" type="Boolean" value="True" />
      </JposEntry>
    
      <JposEntry logicalName="CashDrawer_linux_usb_printer_class">
        <creation factoryClass="com.starmicronics.starjavapos.ServiceInstanceFactory" serviceClass="com.starmicronics.starjavapos.CashDrawerService" />
        <vendor name="Star Micronics" url="www.star-m.jp/eng/index.htm" />
        <jpos category="CashDrawer" version="1.13" />
        <product description="Printer controlled cash drawer" name="Star Micronics cash drawer controller" url="www.star-m.jp/eng/index.htm" />
        <prop name="portName" type="String" value="usbprn:TSP100" />
        <prop name="portSettings" type="String" value="" />
        <prop name="ioTimeoutMillis" type="Integer" value="5000" />
        <prop name="controlPrimaryDrawer" type="Boolean" value="True" />
        <prop name="firePulseWidth" type="Long" value="200" />
        <prop name="sleepPulseWidth" type="Long" value="200" />
        <prop name="capStatus" type="Boolean" value="True" />
        <prop name="signalLevelHighWhenDrawerOpen" type="Boolean" value="True" />
      </JposEntry>
    
    </JposEntries>

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: JavaPOS, Star TSP100 and Linux

    The printer couldn't be found... it could be switched off, not connected or you could've mispelt its logical name. If you printed off the Jpos error you'd get JPOS_E_NOHARDWARE.

  3. #3
    schworak is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: JavaPOS, Star TSP100 and Linux

    This being my first attempt at any JavaPOS work (and still fairly new to Java in general), I am suspecting the printer name is the key here. But I am not quite sure to know how the device is seen by JavaPOS. Is there some way to display a list of all the devices as JavaPOS sees them?

    If I can get this sample code to run, then I am 99% the way to where I need to be. I really appreciate any assistance. I bet this would be helpful to others too.

    I know in Linux (where I am trying to run this code) that I can get a list of USB attached devices using this command:
    Java Code:
    lsusb -v
    I can see the printer, it is turned on and does function via CUPS (just ugly and limited control). So perhaps all I need is to get the printer's name correctly into the jpos.xml file.?.?.?.

Similar Threads

  1. Need help with JavaPOS/UnifiedPOS
    By ozzyman in forum Advanced Java
    Replies: 6
    Last Post: 06-04-2013, 12:21 PM
  2. JavaPOS Applet
    By leequarella in forum Java Applets
    Replies: 1
    Last Post: 02-19-2012, 05:11 PM
  3. Need Help with A star
    By 256mxr in forum New To Java
    Replies: 3
    Last Post: 10-11-2009, 02:50 PM
  4. Replies: 6
    Last Post: 04-08-2009, 04:05 AM
  5. How to use JavaPos
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •