Page 1 of 1

Use Java to read a serial port and save to .txt

Posted: Mon Jan 23, 2012 1:58 pm
by ClickClick5
I was tasked with creating a program to read data coming from a serial port and save the information into a text file. The program would be written in java. Now I know how to do the saving of the txt files and so, but I do not have much experience with serial port I/O especially in Java. Does anyone know how to go about this? Or at least point me in a helpful direction? The program would need to constantly scan the port for any data that comes through.

~CC5

Re: Use Java to read a serial port and save to .txt

Posted: Mon Jan 23, 2012 2:07 pm
by UberGerbil
Might help:
http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java
Serial ports are bog simple if you have access to the hardware; unfortunately, Java's entire philosophy is to abstract the hardware. So.....

Re: Use Java to read a serial port and save to .txt

Posted: Mon Jan 23, 2012 2:13 pm
by ClickClick5
UberGerbil wrote:
Might help:
http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java
Serial ports are bog simple if you have access to the hardware; unfortunately, Java's entire philosophy is to abstract the hardware. So.....


Right. Thats the part that is getting me. The data arrives at port > Java sees data > prints data to test file as seen.
Hum....

Thanks Uber!

EDIT: If anyone has anything else to add, throw it here! I have eight tabs open as of now.

Re: Use Java to read a serial port and save to .txt

Posted: Mon Jan 23, 2012 2:17 pm
by liquidsquid
Can you execute shell inside of Java?
"copy COM6 output_com6.txt"

Sledghammer on tack...

Re: Use Java to read a serial port and save to .txt

Posted: Mon Jan 23, 2012 2:29 pm
by ClickClick5
liquidsquid wrote:
Can you execute shell inside of Java?
"copy COM6 output_com6.txt"

Sledghammer on tack...



...ill try when I get back. On lunch now. :)

Re: Use Java to read a serial port and save to .txt

Posted: Mon Jan 23, 2012 3:46 pm
by ClickClick5
Well scrap the Java idea. It appears that Java wont let you talk to the serial ports on a 64bit system.

C# it is then.

Re: Use Java to read a serial port and save to .txt

Posted: Mon Jan 23, 2012 10:00 pm
by thegleek
ClickClick5 wrote:
Well scrap the Java idea. It appears that Java wont let you talk to the serial ports on a 64bit system.

There's also the RXTX project: http://rxtx.qbang.org/wiki/index.php/Main_Page

What is RXTX? RXTX is a Java library, using a native implementation (via JNI), providing serial and parallel communication for the Java Development Toolkit (JDK). All deliverables are under the GNU LGPL license. It is based on the specification for Sun's Java Communications API, though while many of the class descriptions are the same the package used it not, since gnu.io is used instead. A certain amount of compatibility is intended with API, though this project should be considered as a fork and therefore compatible in spirit, but not in implementation.

ClickClick5 wrote:
C# it is then.

Awesome! Check out this post, may do ya some good? http://stackoverflow.com/questions/9159 ... are-in-use

Example C# code: http://sourceforge.net/projects/com0com ... m/1.0.0.0/

Example projects requiring no code: http://www.serialsniffer.com/en/index.php || http://www.serial-port-monitor.com/