Talking directly to a parallel and serial port

Is it possible to interface directly to the parallel or serial ports of a computer with pure java? Or do i need to switch over to C/C++ for this?

I need fairly fine control, not just sending packets of information, but flipping on/off the voltages of the pins individually (trying to communicate to a GBA in UART mode ;D )

This might help:

http://java.sun.com/products/javacomm/

The Java Communications API lets you do this (http://java.sun.com/products/javacomm/). Sun has implementations for Windows and Solaris and there are open source implementations for Linux and other OS’s.

I’m not sure if it allows switching the pins on and off individually but I would recommend checking out the open source implementations since some of them seem to support more features than the ones from Sun. I used JCA in my last project to talk with my motion capture controller and explicitly had to set the DTR flag so it does allow some pin-level control.

The only really bad thing about the API is that it does not come with a nice installer, one has to copy the files manually into the right directories of the JRE. This wasn’t a problem for me since I had complete control over my platform, but it could be a problem for products that are meant to be mass-distributed.

Ooo, I hadn’t seen that package before - looks promising. :slight_smile: A quick glance over the API shows that you can write individual bytes, so I assume you can affect all the bits by constructing the bytes to send appropriatly (although my knowledge of these ports in general is very lacking, i need to hunt around for more info).

Not having a proper installer isn’t really too much of a worry - its mainly just a small side project, and i doubt many people will have the hardware to be able to use it and want to use it from Java. I will probably end up doing a C++ version as well, but i figured the Java one would be easier to start with…

Orangy, that package is pretty cool, and works well. I’ve used it for all sorts of things in live TV so it’s pretty reliable…

EXCEPT: the Win32 version is broken under Java 2’s security model - it throws an NPE and breaks immediately! Yes, you read right! Agh! And I don’t think they’ve bothered to fix it even now! But have no fear, the jar can be reverse engineered and hacked, or better still, you can swap the broken classes out with the Solaris implementation - which mysteriously has been fixed :-/

Cas :slight_smile:

Well I installed it, and the simple write demo compiled and everything seemed good - until I tried to actually run the damn thing. Kept giving me an empty list of avalible ports - but i stumbled across a post on the java.sun.com forums that explains that the install info is wrong >:( Apparently the .dll needs to sit in the \Program Files\jre\bin dir on an NT machine.

After that it seems to work ok, so they must have fixed whatever bug you bumped into Cas.

Unfortunatly i seem to have some problems with flow control. This is probably a problem with my GBA code though, information on the UART mode with the FIFO queue is minimal to say the least :’(