1 2 Previous Next 25 Replies Latest reply: Oct 2, 2009 1:54 AM by PhHein Go to original post RSS
      • 15. Re: Java Serial Port Program
        843807
        This is kind of unrelated, but I was having a problem accessing the serial port, when I used the SerialRead example I kept getting a "PortInUseException" and it said it was being used by an Unknown Windows Application. This was despite the fact that when I queried the port it said it wasn't in use. Anyways, when I changed the way that it found the port from the way in the example, with the while statement and the enumeration, and changed it to just open up the port by default, like so: "portId = CommPortIdentifier.getPortIdentifier(defaultPort);" then it worked fine. Just thought I should post this somewhere so that if anyone else has the same problem as me, that's how I fixed it.
        • 16. Re: Java Serial Port Program
          843807
          For windows OS

          // if (portId.getName().equals("COM1")) {          //uncomment this line
          if (portId.getName().equals("/dev/term/a")) {      //comment this line

          a null modem connection is needed
          • 17. Re: Java Serial Port Program
            843807
            Write the program in .NET and use a .NET to Java converter.
            • 18. Re: Java Serial Port Program
              843807
              Hey I am using a weighting scale on the serial port but I cant get the weight

              the method I'm using is
              outputStream = serialPort1.getOutputStream();
              outputStream.write("W\r\n".getBytes());
              outputStream.flush();
              serialPort1.sendBreak(1000);
              int i = inputStream.read();
              but the programm stops on the inputStram.read()
              Any help ?
              • 19. Re: Java Serial Port Program
                843807
                Hi,

                We are working on the project to read data from Serial port - Glucometer device.

                I am new to this serial port project. It will be nice, if any one can send the sample Java code on how to connect and read data from the serial port.

                Appreciate you help.

                Thanks,
                Rajashekar
                • 20. Re: Java Serial Port Program
                  843807
                  I'll have to do some reading on this one. im new to java and i im hoping to learn little things like this.

                  val
                  http://www.classyselection.com
                  • 21. Re: Java Serial Port Program
                    843807
                    Hi,

                    I also have serial port issue in my application but it is different issue which I am facing..

                    I am working with Sun Solaris 9 Sparc,Sun-Blade-100.In my application,I need to monitor the UPS using Serial port(/dev/term/a or /dev/term/b).
                    When I am using JRE 1.4 bundle in my application,It is finding the serial port and able to monitor the but when I am upgrading the JRE version from 1.4 to JRE1.6. It is not detecting the Serial port So I am not
                    able to monitor the UPS.It is showing the message

                    Serial port "/dev/term/a" was not found.

                    when I check it in debug log.i am getting the following error message---

                    java.lang.NullPointerException
                    at com.liebert.dpg.device.LxDeviceCommsChannel.writeConfiguration(LxDeviceCommsChannel.java:1115)
                    at com.liebert.dpg.storedInfo.LxBaseStoredInfoTopic.setObject(LxBaseStoredInfoTopic.java:1433)

                    So I am putting the some code here from the file LxDeviceCommsChannel.java:

                    public void writeConfiguration (LxiStoredInfoWriter propFile) throws IOException
                    {
                    // Save internal settings in configuration data.
                    propFile.setValue
                    (LxDeviceInterfaceAgent.NAME_COUNT_PROPNAME, m_nameCount);

                    // Save the host comms portal in configuration data.
                    propFile.setValue //*line no.-1115*
                    (
                    LxDeviceProps.COMMS_PORTAL_CLASS_PROPNAME,
                    getHostCommsPortal().getClass ()
                    );
                    propFile.setValue
                    (
                    LxDeviceProps.COMMS_PORTAL_PROPNAME, getHostCommsPortal().getName ()
                    );

                    // Save the device protocol in configuration data.
                    propFile.setValue
                    (
                    LxDeviceProps.DEVICE_PROTOCOL_PROPNAME, m_driver
                    );

                    // Save managed device data scan rate in configuration.
                    propFile.setValue
                    (
                    LxDeviceProps.SCAN_INTERVAL_PROPNAME, getUpdateInterval ()
                    );

                    // Save the list of managed devices.
                    propFile.setValue (MANAGED_DEVICES_PROPNAME, getManagedDevices ());
                    }



                    So Please take a look and let me know the problem and how can i solve it.
                    Thanks in advance ...
                    • 22. Re: Java Serial Port Program
                      843807
                      hello this is ronit, regarding commport programing.

                      i have installed rxtxdll for serial programing so that i can easily build my code and run successfully. in my code i am using gnu.io.* package given by rxtxseriall.dll so it will run properly. but if try to use import javax.comm it gives me error. is dere any dll for this package please tell me.
                      now i am building my serial code without using public main here i am not pasting my code in only one java file now i have another main. so i am just invoking serial methods for running serial program but now it is giving exception on my this object , outputstream = serialport.getOutputStream(); why this occurs please tell me. now i am really frustrated :( plz guys help me
                      • 23. Re: Java Serial Port Program
                        843807
                        Thank you! Your solution solved my problem.

                        Petr
                        [My Site|http://www.higherlegal.com]
                        • 24. Re: Java Serial Port Program
                          843807
                          hi all
                          i am facing problem to read input from com port
                          i am using *javax.com package on a windows machine




                          the program is:




                          import java.io.*;
                          import javax.comm.*;
                          import java.util.*;

                          public class PortReader implements SerialPortEventListener {
                          static Enumeration ports;

                          static CommPortIdentifier pID;

                          InputStream inStream;

                          SerialPort serPort;

                          public PortReader() throws Exception{
                          serPort = (SerialPort) pID.open("PortReader", 2000);
                          inStream = serPort.getInputStream();

                          serPort.addEventListener(this);

                          serPort.notifyOnDataAvailable(true);

                          serPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                          SerialPort.PARITY_NONE);
                          }

                          public void serialEvent(SerialPortEvent event) {
                          switch (event.getEventType()) {
                          case SerialPortEvent.BI:
                          System.out.println("SerialPortEvent.BI occurred");
                          case SerialPortEvent.OE:
                          System.out.println("SerialPortEvent.OE occurred");
                          case SerialPortEvent.FE:
                          System.out.println("SerialPortEvent.FE occurred");
                          case SerialPortEvent.PE:
                          System.out.println("SerialPortEvent.PE occurred");
                          case SerialPortEvent.CD:
                          System.out.println("SerialPortEvent.CD occurred");
                          case SerialPortEvent.CTS:
                          System.out.println("SerialPortEvent.CTS occurred");
                          case SerialPortEvent.DSR:
                          System.out.println("SerialPortEvent.DSR occurred");
                          case SerialPortEvent.RI:
                          System.out.println("SerialPortEvent.RI occurred");
                          case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                          System.out.println("SerialPortEvent.OUTPUT_BUFFER_EMPTY occurred");
                          break;
                          case SerialPortEvent.DATA_AVAILABLE:
                          System.out.println("SerialPortEvent.DATA_AVAILABLE occurred");
                          byte[] readBuffer = new byte[20];

                          try {
                          while (inStream.available() > 0) {
                          int numBytes = inStream.read(readBuffer);
                          }
                          System.out.print(new String(readBuffer));
                          } catch (IOException ioe) {
                          System.out.println("Exception " + ioe);
                          }
                          break;
                          }
                          }

                          public static void main(String[] args) throws Exception{
                          ports = CommPortIdentifier.getPortIdentifiers();

                          while (ports.hasMoreElements()) {
                          pID = (CommPortIdentifier) ports.nextElement();
                          System.out.println("Port " + pID.getName());

                          if (pID.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                          if (pID.getName().equals("COM1")) {
                          PortReader pReader = new PortReader();
                          System.out.println("COM1 found");
                          }
                          }
                          }
                          }

                          }





                          when running this alone i get the response

                          Port com1
                          COM1 found
                          port com6
                          port com7
                          port com8
                          port LPT1
                          port LPT2

                          but when i use a gps simulator to output on the com1 port
                          while running the program simulator pops a message "com1 in use"

                          And when i run the gps simulator first the the program the the program gives
                          the exception:
                          Exception in thread "main" javax.comm.portInUseEXception:Port currently
                          owned by gps_simulator_com1

                          pls suggest a way how to read output from the simulator through com1 by the program
                          • 25. Re: Java Serial Port Program
                            PhHein
                            Welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.

                            I'm locking this thread now.
                            1 2 Previous Next