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

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

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

Postposted on 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-2600k (4.1Ghz), 16GB DDR3-1600, 6970 2GB, GA-Z68X-UD3H-B3, Recon3D Audio (PCI-E), WD 1TB Black (os/programs), WD 2TB Green (games), WD 3TB Green (movies/music), Win 8.1 Pro x64
Check out my site for trance mixes and other goodies! linserv.biz.tm
ClickClick5
Gerbil XP
Gold subscriber
 
 
Posts: 452
Joined: Fri Aug 15, 2008 8:28 pm
Location: Somewhere in a land the doctor says does not exist...

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

Postposted on 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.....
UberGerbil
Gerbil Khan
 
Posts: 9971
Joined: Thu Jun 19, 2003 3:11 pm

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

Postposted on 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-2600k (4.1Ghz), 16GB DDR3-1600, 6970 2GB, GA-Z68X-UD3H-B3, Recon3D Audio (PCI-E), WD 1TB Black (os/programs), WD 2TB Green (games), WD 3TB Green (movies/music), Win 8.1 Pro x64
Check out my site for trance mixes and other goodies! linserv.biz.tm
ClickClick5
Gerbil XP
Gold subscriber
 
 
Posts: 452
Joined: Fri Aug 15, 2008 8:28 pm
Location: Somewhere in a land the doctor says does not exist...

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

Postposted on Mon Jan 23, 2012 2:17 pm

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

Sledghammer on tack...
liquidsquid
Minister of Gerbil Affairs
 
Posts: 2447
Joined: Wed May 29, 2002 10:49 am
Location: New York

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

Postposted on 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-2600k (4.1Ghz), 16GB DDR3-1600, 6970 2GB, GA-Z68X-UD3H-B3, Recon3D Audio (PCI-E), WD 1TB Black (os/programs), WD 2TB Green (games), WD 3TB Green (movies/music), Win 8.1 Pro x64
Check out my site for trance mixes and other goodies! linserv.biz.tm
ClickClick5
Gerbil XP
Gold subscriber
 
 
Posts: 452
Joined: Fri Aug 15, 2008 8:28 pm
Location: Somewhere in a land the doctor says does not exist...

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

Postposted on 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-2600k (4.1Ghz), 16GB DDR3-1600, 6970 2GB, GA-Z68X-UD3H-B3, Recon3D Audio (PCI-E), WD 1TB Black (os/programs), WD 2TB Green (games), WD 3TB Green (movies/music), Win 8.1 Pro x64
Check out my site for trance mixes and other goodies! linserv.biz.tm
ClickClick5
Gerbil XP
Gold subscriber
 
 
Posts: 452
Joined: Fri Aug 15, 2008 8:28 pm
Location: Somewhere in a land the doctor says does not exist...

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

Postposted on 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/
thegleek
Darth Gerbil
Gold subscriber
 
 
Posts: 7359
Joined: Tue Jun 10, 2003 11:06 am
Location: Detroit, MI


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 1 guest