关键词搜索

源码搜索 ×
×

WindowsCE摩托罗拉MC3100 PDA扫描开启和HEX解码

发布2015-08-26浏览6052次

详情内容

1.开启设备扫描功能

1.1定位扫描应用开启的位置

打开控制面板

点击“DataWedge”图标

双击图标打开;

1.2设置扫描格式并开启回车功能

点击“Status:”,条码扫描开启

点“Basic format...“

点”Send data Enabled“

点”7. Send ENTER key“,条码扫描后自动加回车键(根据需要也可选TAB键)

2.扫描二维码后获取到的HEX串解码

如上界面通过扫描输入来查询,若不解码显示出来的是类似“53534e303031313530383234303031”HEX码输入条件,此种情况自然就查不出相关的记录了;

2.1解码工具类

  1. package com.wlyd.wms.util.api;
  2. /**
  3. *
  4. * @packge com.wlyd.wms.util.api.PDAHexDecoder
  5. * @date 2015年8月26日 上午10:47:23
  6. * @author wlyd
  7. * @comment PDA扫描二维码HEX解码工具
  8. * @update
  9. */
  10. public class PDAHexDecoder {
  11. /**
  12. *
  13. * @MethodName: hexStringToBytes
  14. * @Description: hexString ->Bytes
  15. * @param hexString
  16. * @return
  17. * @throws
  18. */
  19. public static byte[] hexStringToBytes(String hexString) {
  20. if (hexString == null || hexString.equals("")) {
  21. return null;
  22. }
  23. hexString = hexString.toUpperCase();
  24. int length = hexString.length() / 2;
  25. char[] hexChars = hexString.toCharArray();
  26. byte[] d = new byte[length];
  27. for (int i = 0; i < length; i++) {
  28. int pos = i * 2;
  29. d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
  30. }
  31. return d;
  32. }
  33. /**
  34. *
  35. * @MethodName: charToByte
  36. * @Description: char ->Byte
  37. * @param c
  38. * @return
  39. * @throws
  40. */
  41. private static byte charToByte(char c) {
  42. return (byte) "0123456789ABCDEF".indexOf(c);
  43. }
  44. /**
  45. *
  46. * @MethodName: bytesToHexString
  47. * @Description: byte——>String
  48. * @param src
  49. * @return
  50. * @throws
  51. */
  52. public static String bytesToHexString(byte[] src) {
  53. StringBuilder stringBuilder = new StringBuilder("");
  54. if (src == null || src.length <= 0) {
  55. return null;
  56. }
  57. for (int i = 0; i < src.length; i++) {
  58. int v = src[i] & 0xFF;
  59. String hv = Integer.toHexString(v);
  60. if (hv.length() < 2) {
  61. stringBuilder.append(0);
  62. }
  63. stringBuilder.append(hv);
  64. }
  65. return stringBuilder.toString();
  66. }
  67. /**
  68. *
  69. * @MethodName: printHexString
  70. * @Description: byte——>hexString
  71. * @param b
  72. * @return
  73. * @throws
  74. */
  75. public String printHexString(byte[] b) {
  76. String a = "";
  77. for (int i = 0; i < b.length; i++) {
  78. String hex = Integer.toHexString(b[i] & 0xFF);
  79. if (hex.length() == 1) {
  80. hex = '0' + hex;
  81. }
  82. a = a + hex;
  83. }
  84. return a;
  85. }
  86. }

2.2解码测试用例

  1. public class StringTest extends TestCase {
  2. @Test
  3. public void testHex() throws UnsupportedEncodingException{
  4. String hexString="53534e303031313530383234303031";
  5. byte[] bytes=PDAHexDecoder.hexStringToBytes(hexString);
  6. String result=new String(bytes, "UTF-8");
  7. System.out.println(result);
  8. }
  9. @Test
  10. public void testStringToHex(){
  11. String str="SSN001150824001";
  12. String hexString=PDAHexDecoder.bytesToHexString(str.getBytes());
  13. System.out.println(hexString);
  14. }
  15. }

2.3JavaScript处理解码

  1. // 扫描二维码HEX解码
  2. function decode()
  3. {
  4. var batchNo = $.trim($("#batchNo").val());
  5. if (!batchNo || batchNo == "") {
  6. return;
  7. }
  8. var param={"hexCode":batchNo};
  9. $.ajax({
  10. type : 'post',
  11. async : false,
  12. url : "${pageContext.request.contextPath}/pda/hex/decode.html?" + "&res=" + Math.random(),
  13. contentType : "application/json; charset=utf-8",
  14. dataType : 'json',
  15. timeout:5000,
  16. data : JSON.stringify(param),
  17. success : function(result) {
  18. if (result.statusCode == 101) {
  19. $("#batchNo").val(result.data);
  20. }else{
  21. alert(result.reason + "!");
  22. }
  23. },
  24. error : function() {
  25. alert("解码提示:网络访问异常!");
  26. }
  27. });
  28. }

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载