Solved

Port + Java Comm API

Posted on 2003-11-14
21
872 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:maheshexp
  • 8
  • 7
  • 3
  • +1
21 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9748873
You will need to use the comm api for this:

http://java.sun.com/products/javacomm/
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9748876
ahhh...I see you know that...ignore me ;-)
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9748879
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9748887
Ah Tim.  I just took that extra minute to identify the space between "comm" and "api" ;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9748951
;-)
0
 
LVL 7

Author Comment

by:maheshexp
ID: 9752229
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9754496
Are you referring to a H/W LED or a software indicator (displayed on the screen)?
0
 
LVL 7

Author Comment

by:maheshexp
ID: 9757243
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9758046
What code do you have so far?
0
 
LVL 7

Author Comment

by:maheshexp
ID: 9758082
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 15

Accepted Solution

by:
jimmack earned 250 total points
ID: 9758223
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
 
LVL 7

Author Comment

by:maheshexp
ID: 9762689
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9767160
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
 
LVL 7

Author Comment

by:maheshexp
ID: 9768229
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9769980
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
 
LVL 7

Author Comment

by:maheshexp
ID: 9844101
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9845083
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
 
LVL 7

Author Comment

by:maheshexp
ID: 9847345
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
 
LVL 2

Expert Comment

by:jpyeron
ID: 9848436
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
 
LVL 2

Expert Comment

by:jpyeron
ID: 9848479
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
 
LVL 2

Expert Comment

by:jpyeron
ID: 9848485
just a friendly suggestion, on problems this abstract you should offer much more than 250 points.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now