Problem communicating via serial port in Linux

Hello,
I am trying to transfer data via serial port, in Linux.
But it is impossible till now!
I get Runtime exception.
Here is my code:
public class Main {
    public Main() {
    int num=5;
    int[] array = new int[5];
    public static void main(String args[])  {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                array[0]=1;
                array[1]=2;
                array[2]=3;
                array[3]=4;
                array[4]=5;
                new ParallelCommunication(num,array);
import java.io.*;
import java.util.*;
import javax.comm.*; // for SUN's serial/parallel port libraries
//import gnu.io.*; // for rxtxSerial library
public class ParallelCommunication implements Runnable, SerialPortEventListener {
   static CommPortIdentifier portId;
   static CommPortIdentifier saveportId;
   static Enumeration portList;
   InputStream inputStream;
   SerialPort serialPort;
   Thread readThread;
   static OutputStream outputStream;
   static boolean outputBufferEmptyFlag = false;
   int num;
   int[] array;
   public ParallelCommunication(int this_num,int[] this_array) {
      boolean portFound = false;
      String defaultPort;
      num = this_num;
     array=new int[this_array.length];     
      array = this_array;     
      // determine the name of the serial port on several operating systems
      String osname = System.getProperty("os.name","").toLowerCase();
      if ( osname.startsWith("windows") ) {
         // windows
         defaultPort = "COM1";
      } else if (osname.startsWith("linux")) {
         // linux
        defaultPort = "/dev/ttyS0";
      } else {
         System.out.println("Sorry, your operating system is not supported");
         return;
//      if (args.length > 0) {
//         defaultPort = args[0];
      System.out.println("Set default port to "+defaultPort);
      // parse ports and if the default port is found, initialized the reader
      portList = CommPortIdentifier.getPortIdentifiers();
      while (portList.hasMoreElements()) {
         portId = (CommPortIdentifier) portList.nextElement();
         if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            if (portId.getName().equals(defaultPort)) {
               System.out.println("Found port: "+defaultPort);
               portFound = true;
               // init reader thread              
               initialize();
               break;
      if (!portFound) {
         System.out.println("port " + defaultPort + " not found.");
   public void initwritetoport() {
      // initwritetoport() assumes that the port has already been opened and
      //    initialized by "public void initialize()"
      try {
         // get the outputstream
         outputStream = serialPort.getOutputStream();
      } catch (IOException e) {}
      try {
         // activate the OUTPUT_BUFFER_EMPTY notifier
         serialPort.notifyOnOutputEmpty(true);
      } catch (Exception e) {
         System.out.println("Error setting event notification");
         System.out.println(e.toString());
         System.exit(-1);
   public void writetoport(int counter) {
      try {
         // write string to serial port
         outputStream.write(String.valueOf(array[counter]).getBytes());
      } catch (IOException e) {}
   public void initialize() {
      // initalize serial port
      try {
         serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
      } catch (PortInUseException e) {System.out.println("Port In Use.");}  //******Here is the Exception******
      try {
         inputStream = serialPort.getInputStream();
      } catch (IOException e) {}
      try {
         serialPort.addEventListener(this);
      } catch (TooManyListenersException e) {}
      // activate the DATA_AVAILABLE notifier
      serialPort.notifyOnDataAvailable(true);
      try {
         // set port parameters
         serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
                     SerialPort.STOPBITS_1,
                     SerialPort.PARITY_NONE);
      } catch (UnsupportedCommOperationException e) {}
      // start the read thread
      readThread = new Thread(this);
      readThread.start();
   public void run() {
      // first thing in the thread, we initialize the write operation
     initwritetoport();     
     for(int i=0; i<=num_of_inputs; i++) {
        // write string to port, the serialEvent will read it
        writetoport(i);
     serialPort.close();     
   public void serialEvent(SerialPortEvent event) {
      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:
         // we get here if data has been received
         byte[] readBuffer = new byte[20];
         try {
            // read data
            while (inputStream.available() > 0) {
               int numBytes = inputStream.read(readBuffer);
            // print data
            String result  = new String(readBuffer);
            System.out.println("Read: "+result);
         } catch (IOException e) {}
         break;
}...and the outcome is :
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException:
Error opening "/dev/ttyS0"
tcgetattr(): Input/output error
at com.sun.comm.LinuxDriver.getCommPort(LinuxDriver.java:66)
at javax.comm.CommPortIdentifier.open(CommPortIdentifier.java:369)
at ParallelCommunication.initialize(ParallelCommunication.java:128)
I have searched a lot and I couldn't find a solution.
Thank you.

I'm having the same problem this helped somewhat debug the problem
http://bloggerdigest.blogspot.com/2006/11/linux-serial-com-port-diagnostic-test.html
I'm running Suse 10.3 and apparently it does not recognize my serial ports. So before
you can test your Java code you have to figure out how to make linux see the ports.
If I find a solution I'll let you know but if you find one first let me know. Thanks.

Similar Messages

  • How can i browse FP 2000 via serial port same use Ethernet port(RJ 45)?

    I am a new user for  labview.I develope my program with FP 2000 but I have some problem
      1 How can i browse FP 2000 via serial port same use Ethernet port(RJ 45)? if it can Tell me please.
      2 If  I use GSM/GPRS modem via FP 2000 rs 232 port (I under stand how to send AT command) and leave it stand alone
         Can I dial modem and browse file in FP 2000 same as use Ethernetport?
    Someone please help me.Thank you very much.

    Hi!
        First, I can say that your project involves many things, I cannot describe all features in the forum, and I'm not used with GPRS modems (my modems are base band serial modems...).
        Anyway, I would say that in your project you should proceed like this:
          1) Configure your FP 2000 module via MAX and ethernet connection;
          2) Download an embedded application to your module (build in LabView Real-Time)
          3) In your application, you should build a kind of serial port manager, and by the means of serial port you send/receive commands from PC.
        The commands from PC can include "Tell me the about the FP 2000 file system ", or "switch on line X", or anything you need.
       I think it would be difficult to use Internet exp, because you use IE with TCP/IP, and TCP/IP is over ethernet.
       I know that for Windows you can find some wrappers that make you "see" the serial port as an ethernet, but these wrapper do not exist under filed Point, and you shoul build one yourself!!!(and that's not easy).
        For example, to browse your files, you should build a VI that searches through your file system, and reports, via serial, the files present in a directory (it's an example....).
        About communication between GPRS modems and FP2000, I know nothing.  I suppose that these modems accept serial inputs, so you'll have to configure your serial port on FP 2000 with the correct baud rate, parity, and so on..... and you send your data to the modem.  The modem will transfer data in its way, no matter on how it does.
        To send data to your modem you shoud take a look to some Serial communication examples.  What I suggest you, first, is to connect the serial port of FP2000 to a PC, and test communication between PC and FP2000, without modems. Just direct cable connection!  If you're able to do this, insertion of modems is the next step, and should be quite easy.  If you're not able to make the PC receive strings of data from FP2000, over  RS232, adding modems is a further complication, and you won't come out of this mess!
       So, what I say, is just build, for now, a simple embedded application for FP2000, that, using RS232, sends data to a PC (you should see data sent with use of Hyper terminal).
        To build this application, use Instrument I/O --> VISA commands (VISA open, VISA write, and Property node should be enough, for now).
       Please, let me know if this helps......
        Have a nice (programming) day!
    graziano

  • Files via serial port

    I need to send a jpg file via serial port. Have anyone an idea how to get it. I am using LabView 6.0.

    Hi Francesc,
    In order to solve this you will need:
    - a null modem cable (the difference is that pin 2in goes to pin 3out and pin 3in goes to pin 2out)
    - a normal serial communication VI (you can use the one in lv\examples)
    - to pass the data you have to transform your array of bytes (your file) in string at sender and reverse this operation at receiver. THE ONLY PROBLEM is with ASCII character 11 (even if the receiver has all your bytes in buffer it seems that will return to you just those before ASCII 11). Thus, you will have to avoid the transmission of this character. An idea will be to split each byte from file in other two for transmission - for example its hex code (so, 11 will be transmitted as 0B ). Of course, this method doubles the number of transmit
    ted bytes. If somebody found a better solution, please let me know.
    good luck

  • How to transfer file from PC to PC via serial port using labview

    I need to transfer files(.txt, .doc, .xls) from PC to PC via serial port using LabVIEW. Is it possible to transfer files, if so how to transfer?
    Solved!
    Go to Solution.

    Yes, it is possible to transfer files with the serial port using LabVIEW.  Files are just collections of bytes and the serial port is pretty good at shipping bytes from one PC to another.  You need to connect the serial ports together with a null modem cable.
    First, take a look at the example for serial communication.   In LabVIEW, go to the Help menu and select "Find Examples...".  From there you can search for "serial" or navigate to Hardware Input and Output >> Serial.  Select the "Basic Serial Write and Read.vi".  Experiment with that example to gain confidence on the serial communication methods.
    Next, it's time to learn about how to read and write files.  For that, the examples could be somewhat confusing since they all deal with files that are presumed to have data of a specific type in them.  I would recommend just getting familiar with the functions on the File I/O palette.  Specifically, get to know the following functions.
    Open/Create/Replace File - On your destination side, you'll need to create the copy of the file that you are trying to transfer
    Close File - When you are finished reading from or writing to a file, you should close it.  It cleans up the memory being used and finalizes any write operations that are still floating in the write buffer.
    Read From Binary File - The best way to read from a file when you do not really care what type of file it is.  In your case, you just want to get those bytes read and sent out so they can be written down at the destination.
    Write to Binary File - At the destination side, this is what will store those bytes to the file you created with number 1.
    Get File Size (under the Advanced File Functions sub-palette) - You need to know how big the file is so you know when you are finished.
    OK, so once you are able to create files, write bytes to them, and read bytes from existing files you can move on to transferring.
    The basic method I would suggest is to have the user specify a source file on the source PC and a destination folder on the destination PC.  Then, find out the size of the source file using number 5.  Divide that size number by the number of bytes you feel like transferring at once.  The serial buffers are usually around 32k (if I remember correctly) so do not exceed that.  Now begin sending data by reading some number of bytes and wiring that string output to the VISA Write function.  On the destination side, you'll want to be monitoring the serial port for bytes and reading them when they arrive.  Wire that string to the Write to Binary File function to add them to your destination file.
    That is the basic outline of how to do it.  You have to be careful not to overload the write and read buffers on the serial ports.  Initially you can use delays on the sending side to make sure the reading side has enough time to digest.  To get things moving faster, you can bring in some flow control.
    If all that sounds a bit intimidating, there are Alliance Member companies out there (such as PrimeTest Automation) who can write such code for you and even provide a turnkey solution for you.
    Happy wiring,
    Dan Press
    Certified LabVIEW Architect
    PrimeTest Automation

  • Problem: Instrument via serial connection

    Hello Forum,
    I am trying to connect my instrument to my laptop via USB through Serial port. I used NIVISAIC and found the Resource name as ASRL3::INSTR. When I was working with Laview I found the following error
    Error 1073807246 occured at property node (arg1) in VISA configure serial port (Instr.). Reason: The resource is valid, but VISA cannot currently access it.
    Using the interactive control one of the attribut is in red (Is Port connected: VI_ATTR_ASRL_CONNECTED: Invalid property value
    Also when I send Identification query using NIVISAIC, it returns the same command.
    I did not understand much of it. However there is a software for the instrument, using which I could connect to the instrument the first time I switch on the system. When I disconnect it and tried once again, it was not connecting.
    I had earlier connected Keithley 2400 via GPIB KUSB 488. Is there any problem in connecting two devices. Or is the driver of the software and NIVISA are conflicting with each other.
    Please find the screen shots.
    Please help.
    Thank you.
    Attachments:
    2.JPG ‏57 KB
    3.JPG ‏80 KB
    4.JPG ‏93 KB

    Hello Dennis,
    It did not help much.
    7: Write Operation (*IDN?)
    Return Count: 5 bytes
    8: Read Operation
    Return Count: 5 bytes
    *IDN?
    I tried to query with \n and \r\n; but did no good. There is only one instrument connected to the PC via Serial port.
    I would like to know if the identification command is same for all instrument or does it change with manufacturers.
    Why does it return the same command that was given to the instrument.
    If I am to ignore this, please find the block diagram and manual of the instrument in the attachment. It was said that the commands should be sent as single characters and not as string.
    In the block diagram I have used VISA Configure Serial Port, VISA Write, VISA Read and VISA Close vi's. Please tell me whether this is correct. The Commands where given in separate lines or should I use separate VISA Write vi for each characters.
    Thank you.
    Attachments:
    interface.JPG ‏130 KB
    block diagram.JPG ‏14 KB
    PR-655 - 670 Manual.pdf ‏4053 KB

  • Connection Siemens TC65 to PC via serial port

    I don't connect Siemens TC65 via serial port . How can I do this? How can I upload java code in tc65..
    Is there anyone to solve this problem?

    tajava
    Welcome to the forum. Please refrain from posting in old threads that are long dead. When you have a question, please start a topic of your own. Feel free to provide a link to an old thread if relevant.
    I also suggest you go through these links before posting again:
    [How to ask questions the smart way|http://catb.org/~esr/faqs/smart-questions.html]
    [How To Get Good Answers To Your Questions|http://www.tek-tips.com/viewthread.cfm?qid=473997]
    I'm locking this thread now.
    db

  • Export CDR via serial port

    The hardware platform is Cisco UCSC-C220-M3SBE, the Call Manager version is 8.6.2.22900-9.
    We manage to export the CDR to a sftp server. However, the bill system vendor requests us to export the CDR via serial port. 
    Is it possible to do it onto our platform in this case?

    On CUCM no, but with CME it can be done (by collecting syslog output). Otherwise you may exploit the CDRs on the voice gateway.
    It's not everytime that CUCM offers the required feature!

  • RMI via serial port.

    I would like to use RMI via serial port.
    How can I do that?

    Thanks for the reply
    I can get it sending bytes of info from one machine to
    another but not to sure how I still send an object
    Wy do you think I should'nt be sending an object using
    rmiOK, if you have a setup working that involves writing bytes to an OutputStream at one end, and reading bytes from an InputStream at the other, then all you need to do is create an ObjectOutputStream at one end, and write the object to it.
        ObjectOutputStream oos = new ObjectOutputStream(myOutputStream);
        oos.writeObject(myObjectToSend);
        oos.close();and at the other end an ObjectInputStream:
        ObjectInputStream ois = new ObjectInputStream(myInputStream);
        MyObjectType myObjectToReceive = (MyObjectType) ois.readObject();
        ois.close();That should pretty much do it.
    The reason you should not be using RMI for this is that it relies on the existence of a netork layer that connects the two machines. PPP would have provided that, but there just doesn't seem a justification for that level of complexity here.
    Sylvia.

  • Communication cldc serial port with problems?

    I have a problem using CLDC serial communications:
    I need a connection using Stopbit 2, databits 7, parity even and baudrate 4800.
    I use the line code:
    serialport.open("0;baudrate=4800;bitsperchar=7;stopbits=2;parity=even",1,true);
    or the sintax :
    soc_ = (StreamConnection)Connector.open("comm:0;baudrate=4800;bitsperchar=7;stopbits=2;parity=even");
    but the data arrive in palm of strange way. I send the bit 67 and receive in palm the bits 4, 12, 20 for example.
    helpme
    thank you

    [superfudido],
    The MIDP for Palm OS implementation currently does not
    support the comm protocol. Although CLDC supports the
    use of the serial comm protocol, what type of
    connections is determined by the profile, in the case
    of the Palm device, currently the only available
    profile is MIDP for Palm. The MIDP specification
    states that all MIDP compliant implementations must
    provide HTTP connections, all other connection types
    are optional.
    See this URL for the frequently asked questions for
    the MIDP for Palm technology:
    http://java.sun.com/products/midp4palm/faq.html#Q5
    HTH.
    Allen Lai
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/
    However is possible to create conection for serial using databits 8, parity none, stopbit 1 without problems. Then exist comm protocol in CLDC, but no run with databits 7, parity even, stopbit 2. This is a Bug?

  • Problem communicating via SMTP

    Hi
    I have an E52 and a 5800, both configured to connect to my work email system via IMAP and SMTP.
    On both deviices I am able to connect to secure IMAP (993) to view my inbox.  However when sending mail, via secure SMTP on port 587, the server is complaining that the device is sending the password in the wrong format.
    I am unable to find any setting that will allow me to adjust the SMTP settings on either device.
    I need to tell the devices to send a 'normal password'.
    For comparison, I am able to make this adjustment with Thunderbird on this PC.
    Any ideas, please?
    Echo

    I'm having the same problem this helped somewhat debug the problem
    http://bloggerdigest.blogspot.com/2006/11/linux-serial-com-port-diagnostic-test.html
    I'm running Suse 10.3 and apparently it does not recognize my serial ports. So before
    you can test your Java code you have to figure out how to make linux see the ports.
    If I find a solution I'll let you know but if you find one first let me know. Thanks.

  • Problem in using serial port.

    I am using serial port to get data from a fusion splicer. The number of bytes at the port is 4096 but the read buffer of VISA read is empty. I am reading the same number of bytes. Can any one tell me what is the maximum size of VISA Read buffer? I am trying to put the contents of the buffer in a file. I am using labVIEW 6.1 on linux.I am also attaching the VI.
    I also noticed this problem...If I read the number of bytes in the serial buffer many times, sometimes it reads it as 0 and I have to keep trying until it reads this 4096 bytes.
    Thanx for any help.
    S.Vijayalakshmi
    Attachments:
    serail_comm.vi ‏52 KB

    Hey Viji,
    In your application it looks like you are just checking to see how many bytes are at the serial port. Is it possible that your application is check for the serial data at the port before the data actually gets there. If you are looping this code as a subVI or just running it over and over it is possible that one of the iterations could occur faster than your device can write the information to the bus. In this instance you are checking the number of bytes at the port and there might not be any there yet. In this case the port reads 0 as you have designed it.
    If you want the read function to wait and always read 4096 then don't wire the bytes at port to the read function. Just wire a constant/control equal to 4096 to the read function instead o
    f the bytes at port. In this case, if there are not any bytes at the port the read function will wait for the bytes to show up or until the timeout period is reached.
    I would also, suggest lowering your time to something more reasonable, because if your instrument quits transmitting your application is going to wait for 33 minutes. That is a long time for a program to hang.
    I hope this helps out.
    JoshuaP
    National Instruments

  • Motion Control via Serial Port

    I have previously developed an automated video microscope application in Labview. It worked great. My setup was: NI PXI system with 1409 image board, 7344 motion controller, 7764 breakout box, stepper motors, motor drivers, and tables. Now, a customer is requiring that we use a specific brand of drivers that encompass a motion controller and are daisy-chained together. Communication will take place from a serial port, thereby bypassing the 7344. My question is: will I have to can my entire previous Labview motion/data acquisition program b/c I won't be using the 7344 controller? Or, will it be easy to specify in the program to commmunicate via the serial port rather than the card? Would this setup take place in MAX, or in the LabView applicatio
    n itself? Any nuances that I should know about? Any info would be appreciated. THANX-ROB

    Rob,
    in this case you won't be able to use any of your motion related code. The motion VIs in LabVIEW call the NI-Motion driver dll and thus they are not hardware independant. By the way, this is not a specific disadvantage of the NI-Motion driver. In fact there is not such a thing available like a standardized interface and hardware independant motion control language.
    In general you will have to use low level serial communication (VISA). That means you have to read the drive/controller manual, identify the serial command strings you need and send them to the device.
    For configuration the drive vendor should provide a utility to set the necessary parameters.
    On the other hand you could be lucky in the case that the vendor of the drive/controller provides h
    igh level LabVIEW vis. You should check with this vendor if a LabVIEW driver is available. Still you will have to rewrite your motion related part of the code.
    I'm sorry that there are no better news.
    Best regards,
    Jochen
    NI-Germany

  • Installing v240 via serial port of another v240

    Hello!
    We have two SunFire v240 running. Both were installed by connecting a Linux client via the "NET MGT" port.
    Now I want to reinstall one of the mashines. My question: Is it possible to use the serial port of the other server to do this using tip?
    Planned steps: Connecting a RJ-45 cable to the "NET MGT" port of the mashine which should be reinstalled. Then plugging that cable to the serial port of the other mashine using the shipped adapter. "tip hardwire" would use /dev/term/b
    TIA
    Stephan

    Yeah. This is the steps you would take:
    1. Brew a can of coffee. (Or tea, if you prefer that.)
    2. Power up your computer.
    3. Sit down in front of your computer
    4. Code.
    5. Drink coffee (or tea.) Repeat 1 when the pot runs empty.
    6. Code some more
    7. Code even more.
    But no, I can't tell you how the code should be. It's not something I know much about. And I wouldn't have done it anyway, you say you are a final year programming student, it's about time you start doing your own programming.

  • Transfer files via serial port

    Hello there
    I am final year programming student
    and I have to analyse transferring data from one pc to
    another via the serial port.
    I guess I would have to use the communications api.Does anyone know if there is an example of this already developed.
    Please reply
    Thanks

    Yeah. This is the steps you would take:
    1. Brew a can of coffee. (Or tea, if you prefer that.)
    2. Power up your computer.
    3. Sit down in front of your computer
    4. Code.
    5. Drink coffee (or tea.) Repeat 1 when the pot runs empty.
    6. Code some more
    7. Code even more.
    But no, I can't tell you how the code should be. It's not something I know much about. And I wouldn't have done it anyway, you say you are a final year programming student, it's about time you start doing your own programming.

  • Problems reading the serial port with labview 5.1.

    I open the example serial.vi , I select write to serial port, run the programm, I don`t have any problem. But when I select read serial port, I get the error code 16392and hex code error x4008. I need to know what can I do? Thanks a lot

    Any time you get an error in LV you can right click on the error cluster indicator and do a "Explain Error".
    If you do this for the error code you reported, the explanation says that it was a framing error.
    In serial communications, a framing error indicates that the hardware was not able to detect a start bit, data then the stop bits that comprise a frame.
    This prompts me to suggest that you check you port setting on the serial port. You want to make sure you are setting the port for the correct;
    Number of start/stop bits,
    Baud rate
    data bits
    parity (just for good measure)
    and hardware handshaking.
    I hope this helps,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for

  • Bonjour printer "You do not have sufficient access to...

    Bonjour for Windows: Printer wizard says "you do not have sufficient access" If you get this problem go into your Airport utility and change your printer name to something shorter than "40 Character." (Errrr PC!) Then go back into your Bonjour and fi

  • Creating Floor Plan Manager Application.

    Hello, I am creating a Webdynpro ABAP Application using standard FPM interface and component FPM_GAF_COMPONENT. First I create the Application Configuration ,But when I try to create the Component Configuration for the same I get the following error:

  • IWeb 08: Static horizontal menu with background image

    Hi I want to make a static horizonal menu bar. I want to have a 800px x 40px black bar that has a background image from the same size. The reason of a background image is because I want a logo to be in that menu. I have searched in google for samples

  • Error using Disco Viewer 10.1.2 through vpn

    We have upgraded Discoverer from release 9.0.4 to 10.1.2. When using Discoverer Viewer 9.0.4 through a VPN connection (Oracle Application Server is on the other side of the VPN) the browser waits for pages for a while then it displays them correctly.

  • Importing & Naming Help

    HI Folks I'm a fan of the Adam Carolla Radio Show. I subscribe to his podcast. I 've downloaded some of his earlier shows from a sharing service and they arrive as an mp3 (not a podcast) label eg. 20060103. I download about 6 of his old shows everyda