Port + Java Comm API

i want to send some bits to parallel or serial port. i am confused to use which port. after sending them, i want to use some LED to see wheather the bits are transmitted correctly. this i want to do it using Java, so can i use java comm api or any other api is available for this. Please help me, it's very urgent.
LVL 7
maheshexpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
You will need to use the comm api for this:

http://java.sun.com/products/javacomm/
0
TimYatesCommented:
ahhh...I see you know that...ignore me ;-)
0
jimmackCommented:
Yes, javacomm is what you need.

You may need a bit more, depending upon the OS that you are using.  For Linux, have a look here:

http://www.geeksville.com/~kevinh/linuxcomm.html

I don't know of any other APIs that deal with the interaction with serial/parallel ports from within Java.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

jimmackCommented:
Ah Tim.  I just took that extra minute to identify the space between "comm" and "api" ;-)
0
TimYatesCommented:
;-)
0
maheshexpAuthor Commented:
experts, please help me in my problem, it's very urgent. i am using WinXP and JDK 1.4 also Java COMM API.i need only to send a bit and recive a bit, when i send a bit then i use an LED, to check wheather it is recive properly or not, if recive properly then it should glow. please help me very urgent
0
jimmackCommented:
Are you referring to a H/W LED or a software indicator (displayed on the screen)?
0
maheshexpAuthor Commented:
no, it's not a software indicator which will display on the screen, it is pure hardware LED. i had placed 8 LED for 8 bits. when i send 0, no LED should glow, if i send 5, 1st and 3rd LED will glow ( 101 )...and so on, but i don't know how to send these bits and use which port to output it.... please help me.

0
jimmackCommented:
What code do you have so far?
0
maheshexpAuthor Commented:
i have never started anything, confused in the begining, as to choose which port. after choosing port only i can just start programming.....i can't judge is serial or parallel port will be useful
0
jimmackCommented:
Have you looked at the examples that come with the commapi?

Specifically, SimpleWrite.java shows how you identify the ports that can be seen by commapi.  The only confusing bit is that the line for Windows use has been commented out and one for Unix use has been left in:

            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                // if (portId.getName().equals("COM1")) {
                if (portId.getName().equals("/dev/term/a")) {

You can change this to:

            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                if (portId.getName().equals("COM1")) {

At this point, the code has iterated through the serial ports that it can see and if COM1 has been found, it sends data to that port.

Stick with serial ports for now.  If you are using a standard PC configuration, you will only be interested in either COM1 or COM2, depending upon which one has your hardware hanging off it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maheshexpAuthor Commented:
yeah i looked at them, but they send the string converted to bytes. i need only to send a single byte, but i didn't get any output and none of my LED glows. so where will be the problem. u say me to use serial port right!!!!
0
jimmackCommented:
Well, I'm suggesting the serial port because support for the parallel port is lagging behind for Linux (I think it's OK for Windows).

But, if you've already got the hardware, doesn't this tell you which port you should be using?

Yes, in the example, a string (converted to a byte array) is sent to the OutputStream that has been retrieved for the serial port.  If you want to write a byte to the port, just use the OutputStream method that writes a byte (encoded as an int) instead of a byte array.
0
maheshexpAuthor Commented:
but the serial port has only one pin for transmission, how to get all the 8 bits simultaneously, i am using only LED and not anyother storage components such as registers outside. i think parallel port will be suitable , as it has 8 data pins. but strugging how to configure and send data to it.
0
jimmackCommented:
Can you explain exactly what hardware you are trying to write to?

If you want to store the data that has been sent, then you're going to need to latch it somehow.  This is particularly good idea if you want an LED to remain on when the data has been received (otherwise you'll need to keep pumping a bit out to the LED in order for it to remain lit, data out of a port is transient).
0
maheshexpAuthor Commented:
i am not latching anything or using any latch circuit. just sending a bit in the port and reciving from the port, put an led to see wheather the bit is high or low, that's it!!!!
0
jimmackCommented:
You mean you're sticking an LED into the port on the back of your PC?

That sounds like a bad idea!  If I may, I'd like to suggest that you ask a question in one of the hardware TAs asking what kind of hardware you should build to achieve what you want to do.  I would hope that it shouldn't be too difficult and the components you'll need should also be quite cheap.

I think that it's probably more important to get the hardware sorted out first, then come back to this question when you have done that.
0
maheshexpAuthor Commented:
i don't want to know how to use an LED, i need only to know how to send a single bit to parallel port using java api. i tried to send data, but after sending data also all the ports are having bit 1 and before sending also the ports have bit 1 in all the eight pins. this is my problem jim!!!!
0
jpyeronCommented:
okay, since you are using windows I reccommend that you use lpt1

it is the easiest.

are you willing to do some testing without java first?

I can breakout my old port code, to use with java.


do you have the pinout specs for your ports?

also do you have a volt meter.

sometimes the ports use 12v sometimes 5v

the leds will burn out if they are on to long at high voltage w/o a resistor.

0
jpyeronCommented:
test output bytes...

1,2,4,8,16,32,64,128

to turn on all pins output 255(1+2+4+8...+128)

some lpt modes latch (leave in the last state) the output, ith that is the case then you will have to turn them back off.

example:

Start->Run:
 cmd.exe

echo  > lpt1:

rem that is E C H O [space] [Alt-255] > L P T 1 :

this should turn on all the lights for each of the 8 data pins.

since you are in xp there might be some "printer out of paper / printer not ready warnings" this can be avoided by correctly wiring the INPUT pins.


CHECKPOINT HERE.

now test the port features in java, hook up a printer to that port [not a usb printer].

echo Testing..... > lpt1:
echo ^L > lpt1:

rem that is E C H O [control-L] > L P T 1 :

does the paper feed?
did it print out the message?

MINI CHECKPOINT:

now do this in Java

char ctl_L='0x0c';

write this to the port.

did you get the same results?


CHECKPOINT:

now hook up your LED interface...

and wite the bytes of choice

does it still work?


if not then explain where/when the failure occured.

0
jpyeronCommented:
just a friendly suggestion, on problems this abstract you should offer much more than 250 points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.