2012-04-24 104 views
2

我正嘗試創建一個從Android設備打印到TSP100 Star打印機的收據。我到處搜索,無法找到打印光柵收據的簡單示例(因爲TSP100只接受光柵)。我通過電子郵件發送了Star,他們向我發送了以下代碼,但我不確定這是否正確,或者如何將其轉換爲格式化的位圖並打印出來。在Star TSP100打印機上創建光柵收據android

byte[] data; 
    ArrayList<Byte> list = new ArrayList<Byte>(); 

    Byte[] tempList; 
    list.addAll(Arrays.asList(new Byte[]{0x1b, 0x1d, 0x61, 0x01})); 

    data = "[If loaded.. Logo1 goes here]\r\n".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 

    list.addAll(Arrays.asList(new Byte[]{0x1b, 0x1c, 0x70, 0x01, 0x00, '\r', '\n'})); //Stored Logo Printing 

    data = "Company Name\r\n".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 

    data = "Street1\r\nCity, ST, ZIPCODE\r\n\r\n".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 

    list.addAll(Arrays.asList(new Byte[]{0x1b, 0x1d, 0x61, 0x00})); // Alignment 

    list.addAll(Arrays.asList(new Byte[]{0x1b, 0x44, 0x02, 0x10, 0x22, 0x00})); //Set horizontal tab 

    data = "Date: 2/22/2012".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 

    list.addAll(Arrays.asList(new Byte[]{' ', 0x09, ' '})); //Moving Horizontal Tab 

    data = "Time: 9:18 PM\r\n------------------------------------------------\r\n\r\n".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 

    list.addAll(Arrays.asList(new Byte[]{0x1b, 0x45})); // bold 

    data = "SALE \r\n".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 

    list.addAll(Arrays.asList(new Byte[]{0x1b, 0x46})); // bolf off 

    data = "SKU ".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 

    list.addAll(Arrays.asList(new Byte[]{0x09})); 

    // notice that we use a unicode representation because that is how Java expresses these bytes at double byte unicode 
    // This will TAB to the next horizontal position 
    data = " Description \u0009   Total\r\n".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 
data = "34353434 \u0009 SP500\u0009  100.99\r\n".getBytes(); 
    tempList = new Byte[data.length]; 
    CopyArray(data, tempList); 
    list.addAll(Arrays.asList(tempList)); 

等。

我們從ArrayList的列表中得到一個位圖到打印機。一個簡單的收據例子將有助於奇蹟。我從STAR請求過,但不知道他們需要多久才能回來。我認爲那裏的人一定是這樣做的。

謝謝。

回答

4

你從哪裏得到該代碼?這實際上是我剛剛創建的收據的一小部分。我是Kale Evans,我在Star Micronics工作。

本示例顯示如何將數據作爲原始文本發送到打印機。如果你想發送光柵數據到打印機,你必須把你的收據渲染成一個android位圖,然後把它作爲printImageAsBitmap函數中的一個參數傳遞給我(或者類似的名字,看一下rasterprinting活動)。

+0

嗨Kale Evans,我想知道ODP 160-G支持通過USB移動打印嗎? – 2012-12-03 06:26:55

+0

嗨羽衣甘藍,我不知道我能做些什麼,安卓通過USB檢測打印機明星TSP100 eco,我已經嘗試按照手冊,但沒有得到它檢測到打印機,我已經在平板電腦上安裝SDK應用程序(nexus 7和點燃火)http://www.starmicronics.com/Printer/PrinterDesc.aspx?PageId=1&PrinterId=110 – cesarggf 2013-04-05 04:14:56

+0

嗨Kale Evans.how打印標誌和restaturant名稱在行?在此先感謝 – 2013-10-18 05:45:24