Javax comm in windows




















Perhaps a little example will make this concept clear. Suppose we have a modem on COM1 and we want to dial a phone number. A Java dialer management application will query for the phone number and interrogate the modem. These commands are carried by javax. One of the most important tasks of dialer management and modem management is to deal with errors and timeouts.

GUI for serial port management. Normally, serial ports have a dialog box that configures the serial ports, allowing users to set parameters such as baud rate, parity, and so on. Too often, programmers dive right into a project and code interactively with an API on the screen without giving any thought to the problem they are trying to solve.

To avoid confusion and potential problems, gather the following information before you start a project. Remember, programming devices usually requires that you consult a manual. Get the manual for the device and read the section on the RS interface and RS protocol. Most devices have a protocol that must be followed. This protocol will be carried by the javax.

The device will decode the protocol, and you will have to pay close attention to sending data back and forth. Not getting the initial set-up correct can mean your application won't start, so take the time to test things out with a simple application. In other words, create an application that can simply write data onto the serial port and then read data from the serial port using the javax. Try to get some code samples from the manufacturer. Even if they are in another language, these examples can be quite useful.

Find and code the smallest example you can to verify that you can communicate with the device. In the case of serial devices, this can be very painful -- you send data to a device connected to the serial port and nothing happens.

This is often the result of incorrect conditioning of the line. The number one rule of device programming unless you are writing a device driver is to make sure you can communicate with the device.

Do this by finding the simplest thing you can do with your device and getting that to work. Using the javax. In other words, with the exception of the simplest devices, there is usually another layer required to format the data for the device. Of course the simplest protocol is "vanilla" -- meaning there is no protocol. You send and receive data with no interpretation. On top of this byte transport layer you could put your transport layer.

For example, your PPP stack could use the javax. The role of the javax. Give the javax. Before you use a device, the javax. Open the device and condition the line. You may have a device that requires a baud rate of kilobits with no parity. The latest version of the API does not require any ports to be initialized.

On start-up, the javax. You can initialize the serial ports your javax. For devices that do not follow the standard naming convention, you can add them explicitly using the code segment below. This next code sample demonstrates how to add, condition, and open a device. I downloaded the distribution from the Java Developer Connection and tried unsuccessfully to use it to talk to the Java Ring.

With the ring working, I basically forgot about the communications package. That is, until one weekend about a month ago, which is the starting point for this story. For many different reasons mostly having to do with highly interactive simulated environments -- for example, games , the primary computer in my "lab" runs Windows The PDP-8 was arguably the first true personal computer.

Designed in the late s and produced in relatively high quantities in the 70s, the PDP-8 could be lifted by a single individual, was powered by volt line current, and cost less than 0, The ASR teletype was a printing terminal that came with a paper-tape reader and punch. Yep, it was paper tape, 1"-wide paper with holes punched in it, that was the primary storage medium for programs on the PDP The PDP-8 was the first computer I ever programmed and therefore it has a special place in my heart.

Further, due to some fortuitous circumstances, I was in the right place at the right time and managed to save a PDP-8 that was going to be scrapped as junk. A photograph of my prize is shown below. On this special weekend not too long ago, I decided to bring the PDP-8 back to life, if only to relive those precious early memories and to show my daughter just how good she has it with her "measley old MHz Pentium.

To begin my revival effort, I had to get a program into the PDP On the PDP-8, this is achieved by following a three-step process:. Using the front-panel switches, the user "keys" a short program into the magnetic core memory.

After going through these three steps, the program you want to run is stored in core memory. All the user needs to do then is set the starting address and tell the machine to "go. In my effort to revive the machine, Step 1 was no problem, but Step 2 involved the use of the paper-tape reader in the Teletype -- and I didn't have a Teletype. Of course, I did have my desktop computer, so the logical step was to simulate a paper tape reader on my desktop.

From a logical and programming standpoint, simulating a paper-tape reader is trivial. You simply read a file that contains the data from the "tape," send it out to a serial port at baud yes, only 10 characters per second , until you have exhausted the file. I could write a program in C on my Solaris system or my FreeBSD system in about 10 minutes that could do this -- but, remember, I was on a Windows 95 system, not a Unix system. I knew I could easily write this program in C, so that was my language of choice.

Bad choice. I tried to set it into RAW mode the mode in Unix where the operating system doesn't try to interpret anything on the serial port as user input and then tried to compile it. Whoops, no ioctl function or tty functions -- nada, zip, zilch!

I looked at the examples and was appalled at how much code it would take to do such a simple thing as write bytes to the serial port at baud. All I wanted to do was open the darned serial port, set its baud rate, and stuff a few bytes down it -- not create a new class of serial communications-enhanced applications!

The folks at Dallas Semiconductor have figured out how to talk to a serial port on the PC. Let's see what they do. At this point in my weekend, I was thinking perhaps I'd drag one of my Unix machines to the lab in order to code the program on it instead of using what I already had. Then I remembered my experience with the Java Ring and the java. In an older versions of RXTX, yes.

You could use the javax. In newer versions of RXTX, you will need to change imported packages from "javax. Compare the two API's here: rxtx. EDIT By an astounding piece of research i. Stephen C Stephen C k 90 90 gold badges silver badges bronze badges. Thank you Stephen, i visited the link euclideanspace. I wanted a package for the windows however.

Lazar Lazar 21 2 2 bronze badges. PeterMmm PeterMmm 23k 12 12 gold badges 68 68 silver badges bronze badges. It is all explained here rxtx. I had this issue Gili Gili The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta.

New post summary designs on greatest hits now, everywhere else eventually. Linked 0. Related 4. Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.



0コメント

  • 1000 / 1000