Blame view

src/com/eztlib/COMPacket.java 2.63 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  package com.eztlib;
  
  public class COMPacket
  {
  	static
  	{
  		try {
  			System.loadLibrary("EZTLIB");
  		} catch (Exception e) {
  			e.printStackTrace();
  		} catch (Throwable e) {
  			e.printStackTrace();
  		}
  	}
  
  	public static native int HexStringToBytes(byte[] mbyte, int mlen, String Text);
  	public static native String BytesToHexString(byte[] mbyte, int mlen);
  
  	///bytes转换成十六进制字符串
  	///@byte[] b 数组
  	///@int len  数组长度
  	//String addstr 每个Byte值之间 添加指定分隔字符
  	public static String BytesToHexString(byte[] b,int len,String addstr)
  	{
  		StringBuilder sb = new StringBuilder("");
  		for (int n=0;n<len;n++)
  		{
  			String stmp = Integer.toHexString(b[n]&0xff);
  			sb.append((stmp.length()==1)? "0"+stmp : stmp);
  			sb.append(addstr);
  		}
  		return sb.toString();
  	}
  
  
  	/// <summary>
  	/// 端口打开
  	/// </summary>
  	/// <param name="mMode">端口模式 mMode=0 串口端口,mMode=1 USB HID端口</param>
  	/// <param name="ComNumber">mMode=0 串口端口号,mMode=1 USB HID端口 VID</param>
  	/// <param name="Baudrate">mMode=0 串口波特率,mMode=1 USB HID端口 PID</param>
  	/// <returns>返回true表示成功,返回false表示失败</returns>
  	public static native boolean COMOpen(String Port, int baudrate, int flags);
  
  	/// <summary>
  	/// 端口关闭
  	/// </summary>
  	/// <returns>返回true表示成功,返回false表示失败</returns>
  	public static native boolean COMClose();
  
  	/// <summary>
  	/// 端口状态判断,是打开还是关闭
  	/// </summary>
  	/// <returns>返回true表示打开,返回false表示关闭</returns>
  	public static native boolean COMIsopen();
  
  	/// <summary>
  	/// 端口发送数据
  	/// </summary>
  	/// <param name="pDataIn">要写入的数据</param>
  	/// <param name="Inlen">数据长度</param>
  	/// <returns>返回写入的数据长度</returns>
  	public static native int COMSendBytes(byte[] pDataIn, int Inlen);
  
  	/// <summary>
  	/// 端口读取数据
  	/// </summary>
  	/// <param name="pDataOut">返回数据</param>
  	/// <param name="Outlen">想要读取长度</param>
  	/// <returns>返回读取到的数据长</returns>
  	public static native int COMReadBytes(byte[] pDataOut, int len);
  
  	/// <summary>
  	/// 端口查询是否有数据可读取
  	/// </summary>
  	/// <returns>返回可读取长度</returns>
  	public static native int COMBytesToRead();
  
  	/// <summary>
  	/// 端口获取缓冲区大小
  	/// </summary>
  	/// <returns>返回缓冲区大小</returns>
  	public static native int COMBufMaxSize();
  
  	/// <summary>
  	/// 端口清空缓冲区
  	/// </summary>
  	/// <returns>返回true表示成功,返回false表示失败</returns>
  	public static native boolean COMCleanBuf();
  }