摘要
Java Communication API是Java平台下用于串口通信程序开发的唯一官方解决方案,Java串口通信程序均可以由官方提供的开发包中的示例程序括展;但以示例程序为基础开发的Java串口通信程序一般都存在着在异步通信模式下无法完整接收长串数据的缺陷;为解决这一问题,根据通信前收发信双方可以约定通信的数据长度这一特点,提出一种对接收到的字节进行计数的方法,以接收的数据长度为指标判断通信是否结束;通过实际编程验证,该方法克服了上述缺陷,具有很好的可行性与实用性,可以广泛应用于各种使用Java Communication API进行开发的场合。
Java Communication API is the only official solution for serial communication. Java serial communication program can be developed based on the sample in the Java Communication API developer toolkit, but such program has the defect that it cannot receive long data string continuously in asynchronous mode. In order to solve this problem, according to the characteristic that transceiver both sides know the length of data to be transferred in asynchronous mode, proposed a method which is to count the number of bytes received, using the counted number as the criteria to judge whether the communication is ended. Verified by programming, the method overcomes the shortcoming above. It is proved that the method has good feasibility and practicality, and can be widely used in various programming using the Java Communication API.
出处
《计算机测量与控制》
北大核心
2014年第8期2644-2646,2649,共4页
Computer Measurement &Control
基金
航空科学基金项目(20100119004)
国家级大学生创新创业训练计划项目(201310610109)