Android Bluetoothプリンタの例
3900 ワード
, ( 4.0) 。
/**
*
*/
public static final byte[] stateBype = new byte[] { 0x10, 0x04, 0x04 };
/**
*
*/
// public static final byte[] stateBype2 = new byte[] { 0x1B, 0x76 };
/**
*
*/
public static final Byte[] toLeft = new Byte[] { 0x1B, 0x61, 0x00 };
/**
*
*/
public static final Byte[] toCenter = new Byte[] { 0x1B, 0x61, 0x01 };
/**
* 2
*/
public static final Byte[] toLarge = new Byte[] { 0x1D, 0x21, 0x11 };
/**
*
*/
public static final Byte[] cancleLarge = new Byte[] { 0x1D, 0x21, 0x00 };
/**
*
*/
public static final Byte[] toLarge2 = new Byte[] { 0x1B, 0x45, 0x01 };
/**
*
*/
public static final Byte[] cancleLarge2 = new Byte[] { 0x1B, 0x45, 0x00 };
/**
*
*/
public static final Byte[] cut = new Byte[] { 0x1D, 0x56, 0x42, 0x00 };//
/**
*
*/
public static final Byte[] setCodeModel = new Byte[] { 0x1D, 0x28, 0x6B, 0x04, 0x00, 0x31, 0x41, 0x32, 0x00 };
/**
*
*/
public static final Byte[] setCodeSize = new Byte[] { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x43, 0x09 };
/**
*
*/
public static final Byte[] setCodeLevel = new Byte[] { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x45, 0x30 };
/**
*
*/
public static Byte[] setCode = new Byte[8];
/**
*
*/
public static final Byte[] printCode = new Byte[] { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x51, 0x30 };
/**
*
* @param code
*/
public static void doSetCode(String code) {
Common.showDeBug((byte) code.length());
setCode[0] = 0x1D;
setCode[1] = 0x28;
setCode[2] = 0x6B;
setCode[3] = (byte) (code.length()+3);
setCode[4] = 0x00;
setCode[5] = 0x31;
setCode[6] = 0x50;
setCode[7] = 0x30;
}
/**
* byte
*
* @param byte_1
* @param byte_2
* @return
*/
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) {
byte[] byte_3 = new byte[byte_1.length+byte_2.length];
System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
return byte_3;
}
/**
* int[] byte[]
* @param arg
* @return
*/
public static byte[] intTobyte(int arg[]) {
byte[] byteTmp = new byte[arg.length];
for (int i = 0; i < arg.length; i++) {
byteTmp[i] = (byte)arg[i];
}
return byteTmp;
}
/**
* byte Byte
*
* @param srcArray
* @param cpyArray
*/
public static void CopyArray(byte[] srcArray, Byte[] cpyArray) {
for (int index = 0; index < cpyArray.length; index++) {
cpyArray[index] = srcArray[index];
}
}
/**
* List byte[]
* @param ByteArray
* @return
*/
public static byte[] convertFromListByteArrayTobyteArray(
List ByteArray) {
byte[] byteArray = new byte[ByteArray.size()];
for (int index = 0; index < byteArray.length; index++) {
byteArray[index] = ByteArray.get(index);
}
return byteArray;
}
/**
*
* @param li
* @return
*/
public static List removeDuplicateWithOrder(List li) {
List list = new ArrayList();
for(int i=0; i
プリンタ用紙のステータスを確認します.
/**
* , :
* 18 , ; 114( ) 114( ) ,
*/
public int doCheckJiaboPaperState() {
/**1: ,0: ,-1: */
int flag = 0;
try {
InputStream bis = bluetoothSocket.getInputStream();
outputStream.write(BlueThPrintInfo.stateBype);
outputStream.flush();
int tmp = bis.read();
if (tmp == 18) {
flag = 1;
} else {
flag = 0;
}
} catch (Exception e) {
flag = -1;
e.printStackTrace();
}
return flag;
}
残りの手順は、前のAndroidネットワークプリンタと同じです.ここでは一つ一つ説明しません.