public static String toHexLine(byte[] in, int pos, int size, int address, ByteOrder order)
	{
		byte cksum = 0;
		cksum += size;
		cksum += (address & 0xFF);
		cksum += ((address>>8) & 0xFF);
		String res = String.format(":%02X%04X00", size, address & 0xFFFF);
		while(size>0)
		{
			switch(order)
			{
			case LE: {
				cksum += in[pos];
				res += String.format("%02X",in[pos]);
				pos++;
				size--;
			} break;
			case BE16: {
				cksum += in[pos];
				cksum += in[pos+1];
				res += String.format("%02X%02X",in[pos+1],in[pos]);
				pos+=2;
				size -=2;
			} break;
			case BE32: {
				cksum += in[pos];
				cksum += in[pos+1];
				cksum += in[pos+2];
				cksum += in[pos+3];
				res += String.format("%02X%02X%02X%02X",in[pos+3],in[pos+2],in[pos+1],in[pos]);
				pos+=4;
				size -=4;
			} break;
			case BE64: {
				cksum += in[pos];
				cksum += in[pos+1];
				cksum += in[pos+2];
				cksum += in[pos+3];
				cksum += in[pos+4];
				cksum += in[pos+5];
				cksum += in[pos+6];
				cksum += in[pos+7];
				res += String.format("%02X%02X%02X%02X",in[pos+7],in[pos+6],in[pos+5],in[pos+4]);
				res += String.format("%02X%02X%02X%02X",in[pos+3],in[pos+2],in[pos+1],in[pos]);
				pos+=8;
				size -=8;
			} break;
			}
		}
		res += String.format("%02X\n", (-cksum) & 0xFF);
		return res;
	}