Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
ClickClick5
Gerbil Elite
Topic Author
Posts: 581
Joined: Fri Aug 15, 2008 8:28 pm
Location: Alaska
Contact:

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

Mon Jan 23, 2012 1:58 pm

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
i7-5930k (4.1GHz), 32GB DDR4-2400, 2080Ti, GA-X99-UD3, Samsung 860 Pro 256GB (os/programs), Toshiba 5TB (games), WD VelociRaptor 500GB (games/scratch disk), Win 10 Pro x64
Check out my site for trance sets and other goodies! clickclick5.com!
 
UberGerbil
Grand Admiral Gerbil
Posts: 10368
Joined: Thu Jun 19, 2003 3:11 pm

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

Mon Jan 23, 2012 2:07 pm

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.....
 
ClickClick5
Gerbil Elite
Topic Author
Posts: 581
Joined: Fri Aug 15, 2008 8:28 pm
Location: Alaska
Contact:

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

Mon Jan 23, 2012 2:13 pm

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.
i7-5930k (4.1GHz), 32GB DDR4-2400, 2080Ti, GA-X99-UD3, Samsung 860 Pro 256GB (os/programs), Toshiba 5TB (games), WD VelociRaptor 500GB (games/scratch disk), Win 10 Pro x64
Check out my site for trance sets and other goodies! clickclick5.com!
 
liquidsquid
Minister of Gerbil Affairs
Posts: 2661
Joined: Wed May 29, 2002 10:49 am
Location: New York
Contact:

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

Mon Jan 23, 2012 2:17 pm

Can you execute shell inside of Java?
"copy COM6 output_com6.txt"

Sledghammer on tack...
 
ClickClick5
Gerbil Elite
Topic Author
Posts: 581
Joined: Fri Aug 15, 2008 8:28 pm
Location: Alaska
Contact:

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

Mon Jan 23, 2012 2:29 pm

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. :)
i7-5930k (4.1GHz), 32GB DDR4-2400, 2080Ti, GA-X99-UD3, Samsung 860 Pro 256GB (os/programs), Toshiba 5TB (games), WD VelociRaptor 500GB (games/scratch disk), Win 10 Pro x64
Check out my site for trance sets and other goodies! clickclick5.com!
 
ClickClick5
Gerbil Elite
Topic Author
Posts: 581
Joined: Fri Aug 15, 2008 8:28 pm
Location: Alaska
Contact:

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

Mon Jan 23, 2012 3:46 pm

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.
i7-5930k (4.1GHz), 32GB DDR4-2400, 2080Ti, GA-X99-UD3, Samsung 860 Pro 256GB (os/programs), Toshiba 5TB (games), WD VelociRaptor 500GB (games/scratch disk), Win 10 Pro x64
Check out my site for trance sets and other goodies! clickclick5.com!
 
thegleek
Darth Gerbil
Posts: 7460
Joined: Tue Jun 10, 2003 11:06 am
Location: Detroit, MI
Contact:

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

Mon Jan 23, 2012 10:00 pm

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/

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On