专注于 JAVA WEB开发

Java 串口曲线程序

Java 串口曲线程序

设计需求
1. 能够接受下位机数据。
2. 保存接受的数据。
3. 把接收到合法的数据形成曲线。
4. 能够发送数据。
5. 程序能够设置常用串口参数。
6. 程序可以探测数据点的数据。

截图
serialPort

功能实现基于
Java串口通信RXTX

JfreeChart实现数据的实时动态曲线显示

串口模拟程序VSPD使用 http://www.bzhou.com/shuma/200812/20-9476.html
下载VSPD http://d.download.csdn.net/down/2605714/tangjunchf

附件是所有的源码程序,未整理,具体实现逻辑有删改
下载源码http://d.download.csdn.net/down/2605710/tangjunchf

Java串口通信RXTX

Java串口通信RXTX

RXTX是个提供串口和并口通信的开源java类库,由该项目发布的文档均遵循LGPL协议。该项目的主页位于 http://users.frii.com/jarvi/rxtx/index.html
  RXTX项目提供了Windows,Linux,Mac os X,Solaris操作系统下的兼容javax.comm串口通讯包API的实现,为其他研发人员在此类系统下研发串口应用提供了相当的方便。

这里是他的WIKI主页
http://rxtx.qbang.org/wiki/index.php/Main_Page

下载
http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip

在WINDOWS上安装
http://rxtx.qbang.org/wiki/index.php/Installation_on_MS-Windows

使用RXTX

Examples
* Two way communcation with the serial port
* Event based two way Communication
* Parallel Communications
* Discovering comm ports
* Discovering available comm ports
* Writing “Hello World” to a USB to serial converter

在eclipse里如何使用RXTX呢?

This is how I add and use RXTX in Eclipse for Win32 Projects, there are probably other ways but it works for me. [1]

1. Copy RXTXcomm.jar, rxtxSerial.dll and rxtxParallel.dll files to the lib directory of your project
复制RXTXcomm.jar, rxtxSerial.dll 和 rxtxParallel.dll文件到项目lib文件夹
2. Under Project | Properties | Java Build Path | Libraries
3. click Add JARs… Button
在工程属性下将lib包加入项目编译路径
4. Select the RXTXComm.jar from lib directory
5. Jar should now be in the Build Path
6. expand the RXTXComm.jar entry in the list and select “Native Library Location”
添加后,单击RXTXComm.jar展开,选择Native Library Location,选中rxtxSerial.dll 和 rxtxParallel.dll所在的目录,然后应用修改,OK。
7. Select the project lib directory and apply

附件里有WIKI上所有的源码,另外com.hitangjun.rxtx.util.demo包下有一个基于RXTX应用的实例,使用的是观察者模式

不是很明白RXTX是如何和串口通信的,串口的设置参数是如何应用,以及是如何处理收发数据的。

JfreeChart实现数据的实时动态曲线显示

目标:
通过JfreeChart实现数据的实时动态曲线显示

需要解决的问题
JfreeChart如何生成折线图?
JfreeChart如何生成动态图?
如何改变JfreeChart的动态图的X轴?

JfreeChart如何生成折线图?
JfreeChart提供了一个MemoryUsage的demo,

配置开发环境
下载Jfreechart的lib包 http://sourceforge.net/projects/jfreechart/files/
创建eclipse工程,引入jcommon-*.jar,jfreechart-*.jar
MemoryUsage的源码可以在下面的打包文件里找到
将这个demo运行起来你就可以看到一个JVM 内存消耗的实时数据显示

分析源码后可以发现生成这样的图表主要用到了
org.jfree.data.time.TimeSeriesCollection
org.jfree.data.time.TimeSeries
这个主要的功能是实时的收集数据,API文档是这样描述的
A collection of time series objects.
This class implements the XYDataset interface,
as well as the extended IntervalXYDataset interface.
This makes it a convenient dataset for use with the XYPlot class.

org.jfree.chart.plot.XYPlot
是一个曲线图,通过指定XY的坐标来表示数据点,任何实现了XYDataset接口的类都可以通过它来显示,
它通过XYItemRenderer来设置点数据的显示样式,从而生成各种不同的图表。
A general class for plotting data in the form of (x, y) pairs.
This plot can use data from any class that implements the XYDataset interface.
XYPlot makes use of an XYItemRenderer to draw each point on the plot.
By using different renderers, various chart types can be produced.

问题
现在X轴是以时间线来显示的,可以设置以刻度或次序(1,2,3,4…)的格式显示吗?
可以,

org.jfree.data.time.TimeSeries
org.jfree.data.time.TimeSeriesCollection
换成
org.jfree.data.xy.XYSeries
org.jfree.data.xy.XYSeriesCollection
就可以了。

那他们还是动态的图吗?
是的。

那是为什么呢?
因为XYSeriesCollection 和 TimeSeriesCollection都实现了这样一个接口
org.jfree.data.general.SeriesChangeListener
它继承自EventListener
SeriesChangeListener extends java.util.EventListener
它有定义了数据更改时发出通知的方法

Methods for receiving notification of changes to a data series.

void seriesChanged(SeriesChangeEvent event)
Called when an observed series changes in some way.

实现了这个接口的SeriesCollection都可以实时的更新数据
添加数据可以使用
series.add(X,Y);
更新可以使用
series.update(X,Y);
还有清空之前的所有数据可以使用
series.clear();

如何实时的显示特定点的数据呢?
当然JfreeChart有一个tip的功能,当鼠标移上去的时候显示数据点的数据
但是如何让它按照我们想要的格式显示呢?

这里你就需要使用
org.jfree.chart.annotations.XYTextAnnotation

A text annotation that can be placed at a particular (x, y) location on an XYPlot.

这里有一小段的代码(更多的jfreechart的demo代码可以在附件里找到,相信看过之后,基本上都能满足你的要求了)

XYTextAnnotation textpointer = new XYTextAnnotation(X+”,”+Y, X+15, Y-15);
textpointer.setBackgroundPaint(Color.YELLOW);
textpointer.setPaint(Color.CYAN);
dynamicJfreeChart.getXYPlot().addAnnotation(textpointer);

下面的代码未整理,收集来源于网络

http://d.download.csdn.net/down/2605527/tangjunchf

2010-07-19IT技术

没有评论
140 views

SVN auto property

通过svn的auto property keyword这一特性可以自动设置常用的文档信息,比如作者,时间,版本号等

修改配置文件
C:\Documents and Settings\Administrator\Application Data\Subversion\config
去掉注释开启auto propery特性
enable-auto-props = yes
添加
*.java = svn:mime-type=text/plain;svn:eol-style=native;svn:keywords=Date Revision Id Author

这样就可以在你提交JAVA文件到SVN时自动为其设置相应信息

/**
*
* @author $Author: $
* @version $Revision: $
* @since $Date: $
*/

配合TortoiseSVN 来配置会更好。

最新youtube视频下载方法

一直在看google的python Class,突发奇想,想收藏下来,可是在youtube上,苦于不知道如何下载,还是请教google,但是提供的方法都太老了,都是很就以前的了,要不就是需要付费的,经过不断的研究,终于找到了一个方法,废话少说,开始干吧

1 首先保证你能看到youtube,这个不好说,从这里你能找到很多途径;

2 使用firefox,下载并安装

3 安装插件Greasemonkey,打开link,点击Install

4 可能需要重启firefox,安装脚本Download YouTube Videos as MP4,install就可以了

5 打开youtube的视频 ,如google python 教程的地址,你会发现在视频的下方多了一个Download的button,点击下载吧,可以选择下载的视频清晰度,有360P和480P两种

本方法于2010年5月4号晚上测试有效!

稍后我会在QQ中转站或者网盘里share这个python的视频.

返回顶部