Serial communication : guidance wanted

I've just been handed a project which will be my first attempt to have Java communicate via a serial interface.
Some minimal research shows that there are several packages available that deal with this sort of thing. Is there one "official" package that they are all based on?
I have the specs for a proprietary protocol I need to use. Not sure if this makes a difference regarding what packages to use.
For this project, I also plan to use JUnit testing - my first attempt at that as well.
Packages I'm currently contemplating:
javax.comm (not sure if this is right, or where to find it)
http://www.rxtx.org/

"javax.comm" is the Java Communications API. It's the "reference implementation" which means it conforms to the specification (on a couple of platforms) but that's all. Here's the Sun page about it where you can download it. I have used it and it works fine for basic things (I just read input from a barcode scanner, no output). The RTXT product seems to be in active development and it runs on other platforms. I don't have any experience with it.
Your "protocol" is probably a higher-level protocol that says something like "Send these bytes, then wait for some other bytes to come back". Whereas the packages deal with the lower-level RS232 protocol which talks about voltages and pins. So it won't make a difference what implementation you choose, I don't think.

Similar Messages

  • How to send data using serial Communication

    I want to make serial communication using RXTXcomm.jar file.I was written the code.From this I got the list of serial ports avilable on pc but then after when I was tring to send command to machine which is attached to port it didn't gave any reply.
    Tell me that how to send command to port?

    This is how I do it:// open port, get ownership
    SerialPort serialPort= (SerialPort)portId.open(APPLICATIONNAME, timeout);
    // no framing and no threshold
    serialPort.disableReceiveFraming();
    serialPort.disableReceiveThreshold();
    // communication speed, parity, stopbits and databits
    serialPort.setSerialPortParams(BAUDRATE, SerialPort.DATABITS_8,
         SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    // no handshaking or other flow control
    serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    // timer on any read of the serial port
    serialPort.enableReceiveTimeout(TIMEOUT);
    // open streams for reading and writing
    InputStream is= serialPort.getInputStream();
    OutputStream os= serialPort.getOutputStream();... then you use the 'os' stream for writing and the 'is' stream for reading.
    kind regards,
    Jos

  • How do i open a new window? serial communication problem

    I am trying to make a serial communication interface, with changeable settings,
    but i wanted it to be that the settings to be openend in a new window, how am i able to do that.
    I tried to make a separate subvi, but unable to do that, here is my explanation in images and the vi files.
    -Just a student-
    Attachments:
    LVTerm.vi ‏50 KB

    Hello Nandha,
    SubVI's can be created by selecting the part that you want in the subVI and than select "create subVI" from the "Edit" menu.
    Or cut the selected part and open a new VI and paste in the code. Then you have to connect all the controls and indicators to your connector pane. To do this right click the icon in the upper right corner and "Show connector". Select a pattern that has enough connectors, my personal favorite is the 4x4x4. Select the wire tool and select a connector and then the control or indicator you want to connect. Try to keep controls to the left and indicator to the right.
    Now you have to figure out when you want to show the settings window. Is it necessary that the communication goes on during manipulation of the settings?
    Kind regards,
    André
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

  • Changing the name of serial communication example in lab windows. Urgent help required

    I am using the example of getting data from rs 232 in lab windows. I want to use this in my final year project that's why I want to change its name that appears as  "serial communication example" how can I change its name and how can I make its exe file that will run on any system even without lab windows.
    How can I modify this example to save the data. I am very new to lab windows, I was using hyper terminal previously.

    I am not informed about the file format that hyperterminal uses.  However, CVI allows wiring to files.  To get a list of functions that deal with file handling, press <Ctrl-Shift-p> to get the "Find Function Panel" dialog.  Type in "file" and press the "Find" button.  This will open a list of funtions that contain "file" in their name.

  • To read 512 bytes using serial communication

    I want to read 512 bytes of data using rs 232 with the timeout of 30ms. I am using "Serial read with timeout -Palm.vi". Is there a limitation of the number of bytes I can specify to this VI?
    Thanks!!
    Attachments:
    Serial_Read_with_Timeout--Palm.vi ‏63 KB

    Hi software enigineer,
    It is not possible to transfer 512 bytes per 30 ms here. To do this would require a baud rate of 136533 (512*8/.03) and the maximum possible baud rate is 115000. The recommend baud rate for a serial transfer is 9600, which would mean transferring at most 36 bytes if the timeout is kept at 30ms. Moreover, there is usually some overhead involved in serial communication, and I would recommend sending a little less than the maximum 36 bytes every time too.
    On another note, I noticed that in your block diagram, you are using the Bytes at Serial Port vi. Definitely use the output of this vi to determine how many bytes to read at a time and read the bytes as they become available in the serial buffer rather than reading in a large buffer
    all at once. Continuously read and append the output until there are no more bytes to be read or until the termination character is read. This will avoid any lost data transmission due to overflow.
    Good luck with your program!
    Kileen Cheng
    Applications Engineer
    National Instruments

  • User-specified DAQ interruptions, instrument control through serial communication

    I'm working on an instrument control program, and I've run into a structural problem that I cannot figure out.
    The instrument in question is effectively a thermostat.
    The program has two functions:
    1.)  Background sampling to record temperature in a log over time.
    2.)  Adjust temperature according to user input
    The issue is that the instrument uses EIA-232 serial communication to talk to the PC.
    This prohibits simultaneous execution.  Attempting to send a command while the program is taking a sample will result in serial blockage errors.
    So the program must interrupt background sampling until the specified command has been completed.
    I can't figure out how to do this.
    My best idea was to create a manual pause control.  If the user wants to adjust the temperature, he hits a switch to pause the sampling, sends the appropriate command, then hits the switch again to reinitiate sampling.  This method will suffice, but is not ideal.
    Beyond that, I really have no idea how to prevent the two functions from running into each other.
    Help structuring this program would be greatly appreciated,
    Thank you

    Look into Semaphores (icons with traffic light glyphs)
    Set up a Semaphore resource to the COM port that is wired to two parallel structures.
    One structure would do the background polling, the other would handle setting changes.
    Prior to background poll, lock the resource, then unlock it after the poll. Likewise for the setting change command.
    When a resource is locked, the other process cannot access it until it is unlocked. Be sure to dispose of the Semaphore when ending the program.
    -AK2DM
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    "It’s the questions that drive us.”
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
    Attachments:
    SempahoreExample.jpg ‏256 KB

  • How to make Serial Communication in windows

    Hello, I want to do serial communication using windows platform.Sun provides javax.comm package for solaris & unix but there is no any provision for windows platform.Can I use it in Windows Platform.?

    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=698876

  • Serial communication to read single character

    Hi! List,
    I want to read single character using serial communication(see the attached VI).
    The initialization of the serial port is taken care.
    TIA
    Attachments:
    Serial_comm[2_read_single_character].vi ‏42 KB

    I'm not sure I can understand you. If you want to read just one single character why can't you do so by just passing 1 to the Serial Read function as the number of bytes to read?
    The diagram of above VI doesn't make to much sense to me I have to admit.
    Rolf K
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Serial Communication In JAVA

    Hi.
    I just wanted to know if serial communication is possible using java. If yes, which are the classes used.
    Thank you.

    I have found javax.comm for Linux and Solaris but not for Windows can any body help me about it .
    How can I comunicate using rs232 two computers using Java in Windows.
    Tkns
    I

  • RE:Serial communication using java

    Hello,
    First of all, I want to make clear thatI did not double post it as previously I posted it in Networking section..But I was told that I have not posted it at appropirate place....thats wht I am posting here.
    I am a newbie in Java.I have started with Netbeans.I have designed a interface using Netbeans.It has 5 texboxes and two buttons named "Start" and "Stop".
    I want to receive data from the serial port and display the data in text boxes.I want when I press Start button, then it should start listening to the serial port .If adat is present on serial port, then it must receive it and displayin the text boxes.when I press Stop button, then it should stop receiving data as well close connection.
    can please anyone help me on this?
    I would be highly thankful for this.
    Regards,
    Jass

    Hello All,
    I am using the javax.comm for serial communication using serial to usb converter at port COM4(I check using device manager.).Beside that I have also added the option in the programming to look into other COMs also.I have placed "comm.jar " and "javax.properties" into jdk\lib\ext and "win32.dll" into jdk\bin.
    But I am getting the following output:
    Wed Dec 24 02:23:43 EST 2008: COM4 null
    Serial port List is  javax.comm.CommPortEnumerator@1a46e30
    Serial port ID  is null
    BUILD SUCCESSFUL (total time: 0 seconds)
    The code Is as follows:
    import java.io.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.comm.*;
    import java.util.*;
    public class serialport implements Runnable, SerialPortEventListener
        static CommPortIdentifier portId, portId1;
        public SerialPort serialPort;
        public OutputStream outputStream;
        public InputStream inputStream;
        Thread readThread;
        static Enumeration portList;
         static String TimeStamp;
        public static void main(String args[])     
        {try {
              portId1 = CommPortIdentifier.getPortIdentifier("COM4");
              }catch(Exception e) {
          TimeStamp = new java.util.Date().toString();
          System.out.println(TimeStamp + ": COM4 " + portId1);}
               portList = CommPortIdentifier.getPortIdentifiers();
               System.out.println("Serial port List is  "+portList+"\n");
               portId = (CommPortIdentifier) portList.nextElement();
              System.out.println("Serial port ID  is "+portId+"\n");
           while (portList.hasMoreElements()) {
              portId = (CommPortIdentifier) portList.nextElement();
              if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                if (portId.getName().equals("COM3")) {
                     System.out.println("Serial port COM3 is found\n");
                serialport Port = new serialport();
                else if (portId.getName().equals("COM4")) {
                     System.out.println("Serial port COM4 is found\n");
                serialport Port = new serialport();
                else if (portId.getName().equals("COM6")) {
                     System.out.println("Serial port COM6 is found\n");
                serialport Port = new serialport();
                else if (portId.getName().equals("COM7")) {
                     System.out.println("Serial port COM7 is found\n");
                serialport Port = new serialport();
                else if (portId.getName().equals("COM5")) {
                     System.out.println("Serial port COM8 is found\n");
                serialport Port = new serialport();
      public serialport()
        try {
          serialPort = (SerialPort) portId.open("MainClassApp", 2000);
        } catch (PortInUseException e) {
                  System.out.println("Port is owned by another application \nor port cannot be opened\n");
        try {
          inputStream = serialPort.getInputStream();
        } catch (IOException e) {
             System.out.println("IOstream for port is not available\n");}
        try {
          serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {
             System.out.println("Serial port is not properly configured\n");}
        try {
          serialPort.addEventListener(this);
        } catch (TooManyListenersException e) {
             e.printStackTrace();}
        serialPort.notifyOnDataAvailable(true);
        readThread = new Thread(this);
        readThread.start();
        public void run() {
           try {
             Thread.sleep(2000);
               } catch (InterruptedException e) {      e.printStackTrace();}
        public void serialEvent(SerialPortEvent event) {
             Runtime rt = Runtime.getRuntime() ;
             Process p;
        switch (event.getEventType()) {
        case SerialPortEvent.BI:
        case SerialPortEvent.OE:
        case SerialPortEvent.FE:
        case SerialPortEvent.PE:
        case SerialPortEvent.CD:
        case SerialPortEvent.CTS:
        case SerialPortEvent.DSR:
        case SerialPortEvent.RI:
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
          break;
        case SerialPortEvent.DATA_AVAILABLE:
          byte[] readBuffer = new byte[1];
          try {
            while (inputStream.available() > 0)
                   int numBytes = inputStream.read(readBuffer);
                   System.out.print(new String(readBuffer));
                    break;
            System.out.print(new String(readBuffer));
                } catch (Exception e) {
               e.printStackTrace();}
          break;}  }  }Kindly help........I really wanna to know where is the error???
    Thanks
    Edited by: jass11 on Dec 23, 2008 11:39 PM
    Edited by: jass11 on Dec 23, 2008 11:51 PM

  • Dsc modbus - Serial communication input/holding registers

    Hello,
    I am trying to create a labview application to act as a Modbus master and control multiple stepper motors. I have the DSC module in labview and am using a serial communication with an RS-485 converter. I have followed this guide: http://www.ni.com/white-paper/13911/en/  However, the driver I am using does not support coils, it only uses input and holding registers and I have not found a guide or tutorial that shows me how to create a labview application that can read and write to a specific address. For now all I want to do is turn the motor on and off using labview. I have used a modbus simulator to communicate with the driver and can do everything I want to do through the simulator. I can not get labview to do anything for me. I would be very happy if someone could direct me to a tutorial that can help me understand labview dsc module for reading and writing to addresses using modbus. 
    Meesh

    Ok, so this is really strange. I solved my problem in a round about sort of way. I'm using a modbus simulator (mdbus) to help me communicate with the driver/stepper motor so I know which address to use. But after I use the simulator I get a communication port error when I try to use Labview. It's like the port is locked in with the simulator and I can't end the connection and let Labview use the same communication port. I can't find anyway to fix the problem except going to this NI site: http://www.ni.com/download/labview-run-time-engine-6.1/746/en/  downloading this software and using the "repair" function. Then I can do a system restart and cycle the power on the driver/motor and then Labview with work again through the correct port. But if I need to use the simulator again then I have to go through this whole process again. Does anyone know what the heck is going on? Or if there is a better way to clear the communication port?? 

  • Java Serial Communication (Student)

    Hey there,
    Im new to this forum and currently a full time student (not in any type of computer programming). I am currently working on an assignment in Java Programming and I am having difficulty with having my program executing the scenario i want.
    If anyone is willing or available to help me, I will post the code I currently have and explain where I am encountering problems.
    The program is a basic serial communication applet, that has two buttons and a textfield. The first button is supposed to send the text in the textfield (writeButton) and the second button will be used to read the text (readButton).
    For now I am creating two separate applets, one to write and one to read, with only one button "performing" an action in each.
    Thanks

    Ok I got rid of the code that I don't think I need and added the actionListener.
    The program compiles with no errors, but will still not send the messageString.
    Do you see where the possible errors are?
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    import javax.swing.JApplet;
    import java.awt.event.*;
    import java.awt.Graphics;
    import java.applet.*;
    import java.awt.*;
    public class ProjectWrite_test_2 extends JApplet implements ActionListener
         static Enumeration portList;
         static CommPortIdentifier portId;
         static String messageString = "Hello, world!\n";
         static SerialPort serialPort;
         static OutputStream outputStream;
         //public static void main (String [ ] args) {
         String OutString;
         TextField textFieldWrite;
         Button writeButton;
         Button readButton;
              public void init()
                    writeButton = new Button ("Press to Write");
                    writeButton.addActionListener(this);
                    readButton = new Button ("Press to Read");
                   Container window = getContentPane();
                   window.setLayout(new FlowLayout());
                   window.add(writeButton);
                   window.add(readButton);
                    textFieldWrite = new TextField(50);
                   add(textFieldWrite);
                    String outString = textFieldWrite.getText();
                   public void paint (Graphics g)
                             String s = textFieldWrite.getText();
                   g.drawString(s, 40, 50);
              public void actionPerformed(ActionEvent c)
                        portList = CommPortIdentifier.getPortIdentifiers ( ) ;
                                  while (portList.hasMoreElements ( ) ) {
                                       portId = (CommPortIdentifier) portList.nextElement ( ) ;
                                       if (portId.getPortType ( ) == CommPortIdentifier.PORT_SERIAL) {
                                            if (portId.getName ( ) .equals ("COM1")) {
                                                      try {
                                                           serialPort = (SerialPort)
                                                           portId.open ("SimpleWrite", 2000);
                                                      } catch (PortInUseException e) { }
                                                      try {
                                                           outputStream = serialPort.getOutputStream ( ) ;
                                                      } catch (IOException e ) { }
                                                      try {
                                                           serialPort.setSerialPortParams (9600,
                                                                SerialPort.DATABITS_8,
                                                                SerialPort.STOPBITS_1,
                                                                SerialPort.PARITY_NONE) ;
                                                      } catch (UnsupportedCommOperationException e) { }
                                                      try {
                                                           outputStream.write(messageString.getBytes());
                                                      } catch (IOException e) { };
                             }

  • Serial communication

    I am a new user a Labview 6.1and I am trying to learn how to get information out of the serial port. I am check on ni.com for more information, but I am still really confused. I don't know if someone could help me just to get started. Thanks

    The example:
    (drive):\National Instruments\LabVIEW 6.1\examples\instr\smplserl.llb\Serial Communication.vi
    shows the basics using the VISA vi's. You'll want to use these unless you're working with field-point controllers, for those you'll have to use the field-point specific vi's since VISA isn't supported on field-point.
    Hope this helps!

  • Emulator support serial communication?

    Hi all
    I'm trying to implement some serial communication using mobile to write to usb. But I'm surprised that is it possible to do with using emulator?
    Here the problem is
    String ports = System.getProperty("microedition.commports");this thing always return null when run it on my mobile. I used k510i to test this and finally got to know that jp6 (k510i) does not support serial communication.
    But when this run on emulator it gives output string as COM1, COM2.
    So my question is can we use emulator to do this, hence emulator does not have usb cable and does any one has an idea to convert emulator to make enable this?
    If can please tell me how?

    Sorry to say you that you can not touch your PC hardware from the emulator. Because the emulator runs KVM
    as its runtime over the JVM. Thus if you want to touch the hardware of your PC then you have to request your
    JVM from the KVM to communicate with the hardware and return you the response. Which is not at all possible.
    But if you still want to use the COM1 and COM2 then run two different instances of the emulator and start a serial
    communication between two emulators like a chat application.
    Shan!!!

  • Handling multichannel serial communication on FPGA

    NI recently released cRIO modules for serial communication on RS232 and RS485/422.  We need multiple RS232 channels for our RIO systems and previously the solution would have been to use a serial port server and then communicate with that using raw TCP/IP. Having the serial communication handled by RIO modules seems a bit more elegant though so I'm looking into using the RS232 module NI9870 instead.
    NI has supplied an example on how to use the 9870 - a serial loopback on port 0. I've successfully modified this to be a general driver for a selectable port (added port selection and initialization), however I really need to code a solution that handles ALL the 4 channels in parallell. I'm not sure what would be the best way to do that though. DMA FIFOs seem to be the best option for host-target communication, however in this case there are 4 channels....and I may have multiple modules so at most it could be that I need to handle as much as 32 ports. The example uses interrupts for synchronization....which off course is also a limited resource. All in all I'll probably figure out a way to do this, however if anyone else have done something similar already it would be great to hear your views on this.
    Coming from the Windows-programming world (this is the first FPGA work I've done) I was also hoping to make this driver as general as possible, maybe even be able to write a wrapper containing both VISA based serial functions and the FPGA host code. That way it could be transparent how the port is accessed.
    This would require 1 code that would be able to handle a variety of module configurations (well, 1 to 8 NI9870 modules in the chassis), however that does not seem to be feasible(?). When you read or write to a port you cannot just refer loosely to it with a number e.g. - the read and writes are referenced to a specific port...this means that unlike in a Windows application where you can let the user just configure that he wants to use COM port num XX and the serial functions will accept that number regardless of whether the port exists or not (returning an error if it does not exist or is in use) - the FPGA code has to have all the items it will call pre-defined. If the chassis can have 16 ports on 4 9870 modules it does not seem possible to use the same FPGA code if the chassis currently only has 1 module...Is this the reality, or is it possible to create a more flexible solution?
    If it turns out that the FPGA has to be reprogrammed if another serial module is added (or one is removed) it would seem much better to drop the modules and use a port server and tcp/ip instead...that way using new ports will only be a question of configuration (IP and port), not reprogramming...That may not be possible always (if you need the compact size and roughness only a single RIO chassis would offer), but in our case it is - it' just not as elegant hardware-wise.
    MTO

    Well, the multichannel experiment only wrote data, it did not read...(see attached VIs) however the concept can be used in both directions: Add a header to the FIFO data where the header tells the recipient what port the data is going to or comes from...Then use e.g. a state machine to read the FIFO, split the header and data, and route the data to the loop handling the port.
    If you are going to read data you will get into one of the downsides to this namely that you will need to have a central communications manager that reads the incoming data and distributes it to the requesting VI. This way you can have more parallell access to both read and write, however the reads will have to be routed through this handler. How big a performance gain this would give is unknown though. You still only have one DMA FIFO for each direction so there is a limit to how parallell things can get, but logically this might get you closer than the NI example...
    MTO
    Attachments:
    9870 MultichannelIO Experiment.zip ‏1002 KB

Maybe you are looking for

  • Condtional formatting on Grand Total in OBIEE 11.1.1.6.7

    Hi, We have upgraded a report from 10g to 11g and the report has pivot table which has conditional formatting set on the Grand Total level and is resulting in the following error in OBIEE11g. "DXE compiler error. No table 'GTGT' found in DXE. Source

  • How to deal with addition of .jpg or .gif file

    how do i add a LARGE .jpg or .gif image to a JPanel? and is it possible to add JTextField or other features onto the .jpg or .gif file after the addition of the image? Thanks for the time and consideration.

  • How to use DLNA on BB Q5

    Hi Just having a look to see if I can use the DLNA feature to play stuff from my phone on my TV. The TV is DLNA certified, it is on the same network as the phone; it can see the phone on the network, but says there are no photos/music/videos it can a

  • NetRestore using OS X 10.8.4 Server

    Hello all, I created an image for NetRestore and am having a strange issue. I can netboot to the installer and it seems to go through the process fine, but when the process completes, it gives an error - "invalid argument," reporting that the restore

  • Can Time Machine reload an older system ?

    Yeah, like I have been using Mt.Lion (10.8.5) for a long time on my Late 2012 iMac (13,1) I want to try Yosemite so I can get a nice free Logic Pro X upgrade for my music. If I make the plunge and go for Yosemite and it does not work out-. Can I reve