Serial port ReadTo timeout exception

Hello.
I am communicating with modem using serial port.
The fist time I open serial port and start sending AT commands everything works fine.
Then I wait for a couple of seconds and repeat procedure...
Second time it opens port and sends first command and waits port.ReadTo("\r\n") -> and here is operation timed out exception.
If I close the program and start again it works fine... its like serial port wasnt disposed properly?
Here is the program:
class Program
static void Main(string[] args)
SendATcommands();
Thread.Sleep(5000);
SendATcommands();
static void SendATcommands()
SerialPort port = new SerialPort();
port.RtsEnable = true;
port.BaudRate = 9600;
port.DataBits = 8;
port.Handshake = Handshake.None;
port.Parity = Parity.None;
port.PortName = "COM9";
port.StopBits = StopBits.One;
port.WriteTimeout = 20000;
port.ReadTimeout = 30000;
port.NewLine = "\r";
port.Open();
Thread.Sleep(1000);
port.WriteLine("+++");
Thread.Sleep(1000);
port.WriteLine("AT\r\n");
port.ReadTo("\r\n");
port.WriteLine("ATH\r\n");
port.ReadTo("OK\r\n");
port.WriteLine("AT\r\n");
port.ReadTo("OK\r\n");
port.WriteLine("AT&D2\r\n");
port.ReadTo("OK\r\n");
port.WriteLine("AT\r\n");
port.ReadTo("OK\r\n");
port.WriteLine("ATE0V1Q0\r\n");
port.ReadTo("OK\r\n");
port.WriteLine("AT\r\n");
port.ReadTo("OK\r\n");
port.WriteLine("ATDT040111222"); //phone number
port.ReadTo("CONNECT 9600/RLP\r\n");
port.WriteLine("ATH");
Thread.Sleep(1000);
port.WriteLine("+++");
Thread.Sleep(1000);
port.Close();
port.Dispose();

Closing the serial port makes normal no sense, when you want a contious communication. Also using sleep to time your commands is pretty useless as the modem may need longer to prepare for the next command. Thus you need to read the answer from your modem
and continue when sent an OK.

Similar Messages

  • Buffersize, Outputstream to serial port

    Hello,
    I working with some infosigns and got the following problem.
    The java commapi use a OutputStream to send information to the serial port. The OutputStream seems to have a upper buffersize of 512 bytes, which means that I am sending my message ( of 7702 bytes ) in 'small packets'.
    My infosign make a timeout, because of the time it takes to send the message... I only reache about 2 Kb when it answer.
    this is my code which send the data ....
    private OutputStream os;
    public int[] Transmit(ByteArrayOutputStream b) {
    BufferedOutputStream bos = new BufferedOutputStream(os,8192);
    writeable = true;
    Consumer c = new Consumer(this);
    c.start();
    try {
    bos.write(b.toByteArray());
    bos.flush();
         } catch (IOException e) {
         System.err.println("OutputStream write error: " + e);
    while (c.isAlive()) {
    try{
    this.wait(10);
    }catch(Exception e){}
    return respondTavle;
    I use a thread class to make timeout if the infosign is not responding.
    I�ve got no problem with data of small size, lets say below 2 kb.
    My cuestion is ... Is it possible to raise the buffersize ?
    In another application (windows ) the portmonitor see this :
    send 7702: 55 AA 02 1E 0E 40 93 66 0C 31 2E 53 45 4B ......
    response : 55 AA 02 00 00 A1 00 00 5E !!! Yes data recieved....
    when I launch the java application it seems like this :
    send 512: 55 AA 03 1E 0E....
    send 512: 00 00 00 00 00 00....
    send 512: 00 00 00 00 00 00 ....
    response : 55 AA 02 00 00 A1 00 00 5E !!! AARRRGGG I�m not finished.
    send 512: 00 00 00 00 00 00...
    send 512: 00 00 00 00 00 00....
    as you see it is divided in packets of 512 bytes....

    And why are you using a Buffered stream?

  • Serial port prob

    Hi,
    I'm testing some application using javax.comm.* serial communication package.
    Problem some data is missing after some time connection, any one have any clue?
    Below is the code snippet.
    ====================
    Open Connection
    =============
    public void openConnection() throws SerialConnectionException {
              // Obtain a CommPortIdentifier object for the port you want to open.
              try {
                   portId = CommPortIdentifier.getPortIdentifier(parameters
                             .getPortName());
              } catch (NoSuchPortException e) {
                   throw new SerialConnectionException(e.getMessage());
              // Open the port represented by the CommPortIdentifier object. Give
              // the open call a relatively long timeout of 30 seconds to allow
              // a different application to reliquish the port if the user
              // wants to.
              try {
                   sPort = (SerialPort) portId.open("SerialDemo", 30000);
              } catch (PortInUseException e) {
                   throw new SerialConnectionException(e.getMessage());
              // Set the parameters of the connection. If they won't set, close the
              // port before throwing an exception.
              try {
                   setConnectionParameters();
              } catch (SerialConnectionException e) {
                   sPort.close();
                   throw e;
              // Open the input and output streams for the connection. If they won't
              // open, close the port before throwing an exception.
              try {
                   sPort.setInputBufferSize(999999999);
                   os = sPort.getOutputStream();
                   is = sPort.getInputStream();
                   dis = new DataInputStream(is);
              } catch (IOException e) {
                   sPort.close();
                   throw new SerialConnectionException("Error opening i/o streams");
              // Create a new KeyHandler to respond to key strokes in the
              // messageAreaOut. Add the KeyHandler as a keyListener to the
              // messageAreaOut.
              keyHandler = new KeyHandler(os);
              messageAreaOut.addKeyListener(keyHandler);
              // Add this object as an event listener for the serial port.
              try {
                   sPort.addEventListener(this);
              } catch (TooManyListenersException e) {
                   sPort.close();
                   throw new SerialConnectionException("too many listeners added");
              // Set notifyOnDataAvailable to true to allow event driven input.
              sPort.notifyOnDataAvailable(true);
              // Set notifyOnBreakInterrup to allow event driven break handling.
              sPort.notifyOnBreakInterrupt(true);
              // Set receive timeout to allow breaking out of polling loop during
              // input handling.
              try {
              sPort.enableReceiveTimeout(30);
              } catch (UnsupportedCommOperationException e) {
              // Add ownership listener to allow ownership event handling.
              portId.addPortOwnershipListener(this);

    Placing a delay is not the solution.
    Have a look at the code snippet that I posted here:
    http://forums.ni.com/t5/LabVIEW/Reading-time-interval-of-serial-port/m-p/1529140#M568806
    The modified code is also attached in that post. 
    The solution is to place the serial read inside a loop which continues to read until there is no more data in the buffer. 

  • How to detect serial port

    CommPortIdentifier portId;
              Enumeration en = CommPortIdentifier.getPortIdentifiers();
              Vector v=new Vector();
              while (en.hasMoreElements())
                   portId = (CommPortIdentifier) en.nextElement();
                   if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
                             v.addElement(portId.getName());
              }

    refer this URL
    http://www.java2s.com/Code/Java/Development-Class/ReadfromaSerialportnotifyingwhendataarrives.htm
         * Project                     :
         * Class                     : GUIFrame.java
         * Purpose                    :
         * Date_Created               :
         * @ Version 1.0
    import javax.swing.JFrame;
    // import javax.swing.JPanel;
    import javax.swing.JMenuItem;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import java.awt.event.*;
    import javax.comm.*;
    import java.awt.*;
    import javax.swing.*;
    // import javax.swing.border.TitledBorder;     
    public class GUIFrame extends JFrame implements ActionListener
         JButton connectPort;
         JComboBox combo;     
         //JButton baudRate;
         //JComboBox baudRateCombo;     
         public JTextArea textArea;     
         JButton sendData;
         public SerialConnection serialConnection;
         public GUIFrame()
              setLayout(null);
              setTitle("First Frame");
              serialConnection = new SerialConnection();                    
              setJMenuBar(createMenuBar());
              combo = new JComboBox();
              combo.setBounds(50, 50, 80, 25);
              listPort();
              combo.addActionListener(this);
              connectPort = new JButton("Connect");
              connectPort.setBounds(150, 50, 100, 25);
              connectPort.addActionListener(this);
              sendData = new JButton("Send Data");
              sendData.setBounds(150, 150, 100, 25);
              sendData.addActionListener(this);
              textArea = new JTextArea();
              textArea.setBounds(300, 300, 400, 300);
              textArea.setFont(new Font("sansserif",0,18));
              add(connectPort);
              add(combo);
              add(sendData);
              add(textArea);;
              setSize(400, 300);
              setVisible(true);
              addWindowListener(new MainWindowAdapter());
         public static void main(String arg[])
              System.out.println("Hi");
              new GUIFrame();
         public JMenuBar createMenuBar()
              JMenuBar menuBar = new JMenuBar();
              JMenu fileMenu = new JMenu("File");
              JMenuItem connectMenuItem = new JMenuItem("Connect");
              connectMenuItem.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent ae){
                        try{
                             if(serialConnection.portName == null){
                                  serialConnection.portName = combo.getSelectedItem().toString();
                             serialConnection.openConnection();
                        catch(Exception ex)
              JMenuItem disconnectMenuItem = new JMenuItem("Disconnect");
              disconnectMenuItem.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent ae){
                        try{
                             serialConnection.closeConnection();
                        catch(Exception ex)
              fileMenu.add(connectMenuItem);
              fileMenu.add(disconnectMenuItem);
              menuBar.add(fileMenu);
              return menuBar;
         public void listPort()
              CommPortIdentifier portId;          
              java.util.Enumeration enumeration = CommPortIdentifier.getPortIdentifiers();
              while(enumeration.hasMoreElements())
                   portId = (CommPortIdentifier)enumeration.nextElement();
                   if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
                        if(!portId.isCurrentlyOwned())
                             combo.addItem(portId.getName());
         public void actionPerformed(ActionEvent ae)
              if(ae.getSource() == connectPort)
                   System.out.println("Connect is clicked");     
                   try
                        if(serialConnection.portName == null)
                             serialConnection.portName = combo.getSelectedItem().toString();
                        serialConnection.openConnection();
                   catch(Exception ex)
              if(ae.getSource() == combo)
                   System.out.print("Port Name = " + combo.getSelectedItem().toString());
                   serialConnection.portName = combo.getSelectedItem().toString();
              if(ae.getSource() == sendData)
                   byte b[] = new byte[5];
                   b[0] = (byte)0xaa;
                   b[1] = (byte)0xbb;
                   b[2] = (byte)0xcc;
                   b[3] = (byte)0xdd;
                   b[4] = (byte)0xee;     
                   try
                        serialConnection.getOutputStream().write(b);
                        display(b);
                   catch(Exception ex)
         public class MainWindowAdapter extends WindowAdapter
              public void windowClosing(WindowEvent win)
                   dispose();
                   System.exit(0);
         public void display(byte[] b)
              for(int i=0; i< b.length; i++)
                   textArea.append(Integer.toHexString (b[i] & 0xff) + " ");
              textArea.append("\n");
         * Project                     :
         * Class                     : SerialConnection.java
         * Purpose                    :
         * Date_Created               :
         * @ Version 1.0
    import javax.comm.*;
    import java.io.*;
    public class SerialConnection
         private OutputStream os;
         private InputStream is;
         private CommPortIdentifier portId;
         public SerialPort sPort;
         private boolean open;
         public String portName;
         SerialConnection serialConnection;
         public SerialConnection()
              serialConnection=this;
              PortHandler portHandler = new PortHandler(serialConnection);
              portHandler.init(serialConnection);
         public void setOutputStream(OutputStream os)
              this.os=os;
         public OutputStream getOutputStream()
              return os;
         public void setInputStream(InputStream is)
              this.is=is;
         public InputStream getInputStream()
              return is;
         * A Method to open the SerialConnection
    public void openConnection() throws Exception
              try
                   portId = CommPortIdentifier.getPortIdentifier(portName);
              catch (javax.comm.NoSuchPortException e)
                   System.out.println("noPort : "+e);
              try
                   sPort = (SerialPort)portId.open("port", 3000);               
                   open = true;
              catch (javax.comm.PortInUseException e)
                   throw new Exception();
              try
                   setOutputStream(sPort.getOutputStream());
                   setInputStream(sPort.getInputStream());               
                   System.out.println("IO stream is opened");
              catch (java.io.IOException e)
                   sPort.close();                    
         *A Method to Close the port and clean up associated elements.
         public void closeConnection()
              // If port is already closed just return.
              if (!open)
                   return;
              if (sPort != null)
                   try
                        this.os.close();
                        this.is.close();
                        System.out.println("IO stream is opened - CloseConnection");
                   catch (java.io.IOException e)
                        System.err.println(e);
                   sPort.close();
                   System.out.println("Port is closed");
              System.out.println("Flag Open - 1 : " + open );
              open = false;
              System.out.println("Flag Open - 2 : " + open);
         * Send a one second break signal.
         public void sendBreak()
              sPort.sendBreak(1000);
         * Reports the open status of the port.
         * @return true if port is open, false if port is closed.
         public boolean isOpen()
              return open;
         * A Method to add the event listener to the SerialPort
         public void addEventListener(java.util.EventListener listener)throws Exception
              System.out.println("Is not in opened state");
              if(isOpen())
                   System.out.println("Is in opened state");
                   try
                        sPort.addEventListener((javax.comm.SerialPortEventListener)listener);
                   catch (java.util.TooManyListenersException e)
                        sPort.close();               
                   // Set notifyOnDataAvailable to true to allow event driven input.
                   sPort.notifyOnDataAvailable(true);
                   // Set notifyOnBreakInterrup to allow event driven break handling.
                   sPort.notifyOnBreakInterrupt(true);
                   // Set receive timeout to allow breaking out of polling loop during
                   // input handling.
                   try
                   sPort.enableReceiveTimeout(50);
                   //sPort.enableReceiveTimeout(-1);
                   catch (javax.comm.UnsupportedCommOperationException e)
                        e.printStackTrace();
                   // Add ownership listener to allow ownership event handling.
                   portId.addPortOwnershipListener((javax.comm.CommPortOwnershipListener)listener);
         import javax.comm.*;
         public class PortHandler implements SerialPortEventListener,CommPortOwnershipListener{
              public SerialConnection serialConnection;
              public PortHandler(SerialConnection serialConnection)
                   this.serialConnection=serialConnection;
                   try{
                        serialConnection.addEventListener((SerialPortEventListener)this);
                        System.out.println("New Port Handler is called");
                   catch(Exception e)
                        System.out.println("Exception PortHandler(); " +e);
                        e.printStackTrace();
                   // Add this object as an event listener for the serial port.
                   System.out.println("PortHandler is initialised...");
              public SerialConnection getConnection(){
                   return serialConnection;
              public void setSerialConnection(SerialConnection serialConnection){
                   this.serialConnection = serialConnection;
              public void init(SerialConnection serialConnection){
                   setSerialConnection(serialConnection);
              public void serialEvent(SerialPortEvent e){
                   System.out.println("Event Initialised");
                   //Determine type of event.
                   switch (e.getEventType())
                        case SerialPortEvent.DATA_AVAILABLE:
                             try{
                                  readData();                              
                             catch(java.io.IOException e1)
                                  System.out.println("IO Excep "+e1.getMessage());
                                  e1.printStackTrace();
                             catch(Exception e1)
                                  System.out.println("Exception from Serial Event "+e1.getMessage());
                                  e1.printStackTrace();
                        break;
                        case SerialPortEvent.BI:
                        break;
              public void readData() throws java.io.IOException
                   byte b[]=new byte[8500];
                   int i=0,selectOption=0;
                   int newData=0;
                   int doubleLength=0;
                   int length=0;
                   // String mid="",strLen="";
                   while (newData != -1)
                        try     
                             System.out.println("getInputStream().available() : " + serialConnection.getInputStream().available());
                             newData = serialConnection.getInputStream().read();
                             System.out.println("newData\t"+newData);
                             if (newData == -1)
                                  System.out.println("\n End of the File\n");
                                  break;
                             if(i==0){
                                  b=(byte)newData;
                                  System.out.print("\n MSg ID \t= " + Integer.toString(newData&0xff,16)+"\n----------------------------");
                                  if(b[0] == (byte)0x00)
                                       i=-1;
                                       i++;
                                       continue;
                                  i++;
                                  //System.out.println("Method is called - selectOption : " + selectOption);
                                  continue;
                             if(i==1)
                                  b[i]=(byte)newData;
                                  System.out.print("\n Length =\t"+Integer.toString(newData&0xff,16)+"\n----------------------------");
                                  length=newData;
                                  if(length == 0)
                                       i=0;
                                       continue;
                                  i++;
                                  continue;
                             b[i]=(byte)newData;
                             if((b[0] == (byte)0x07) && (i == 2) || (b[0] == (byte)0xaf) && (i == 2) || (b[0] == (byte)0xec) && (i == 2)
                                  || (b[0] == (byte)0x5c) && (i == 2) || (b[0] == (byte)0xbe) && (i == 2) )
                                  String string = String.valueOf((byte)b[0]);
                                  String strLen = Integer.toString(b[2]&0xff,16) + Integer.toString(b[1]&0xff,16);
                                  System.out.println("\n\nLength String = " + strLen + "\n\n");
                                  java.math.BigInteger bi=new java.math.BigInteger(strLen,16);
                                  strLen = bi.toString();
                                  doubleLength = Integer.parseInt(strLen);
                                  System.out.println("\nLength int = " + doubleLength + "\n");
                                  //System.out.println("Method is called");
                             i++;
                             // Added by Siva on Jan 06
                             switch(selectOption)
                                  case 0:
                                       if(i>length+1)
                                            try
                                                 b[i]=(byte)newData;     
                                                 System.out.print("\nThe Last Byte =\t"+Integer.toString(newData&0xff,16)+"\n----------------------------");
                                                 System.out.print("\n"+i+" i Value =\t"+Integer.toString(newData&0xff,16));
                                                 System.out.println("\n----------------------- FINISHED------------------------------");
                                                 // service(b);     
                                                 System.out.println("\n----------------------- After Service------------------------------");
                                                 i=-1;
                                                 i++;               
                                                 continue;
                                            }catch (Exception e)
                                                 System.out.println("Exception in calling service 0:"+e.getMessage());
                                                 e.printStackTrace();
                                                 b[i]=(byte)newData;
                                       System.out.print("\nMSg ID \t= "+Integer.toString(newData&0xff,16)+"\n----------------------------");
                                       break;
                   }catch (java.io.IOException ex)     {
                        System.err.println("Abstarct Port handler Exception\t"+ex);
                   catch(Exception e1)
                        System.out.println("Exception from Read Data "+e1.getMessage());
                        e1.printStackTrace();
                   System.out.println("-----------------------------");
              public void ownershipChange(int type){
                   if (type == CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED){
              public void destroy()     
                   try{
                        serialConnection.closeConnection();     
                   }catch(Exception e){
                        System.out.println("Exception 2:"+e);     
                        e.printStackTrace();
              public void finalize(){
                   destroy();

  • Java Serial Port Question !

    Hello,
    I am writing characters such as "open\r", "close\r" to the serial port of a PC from the Java program. This PC is connected to robot controller through the serial port.
    Suppose, I am writing open\r to the serial port. After writing open\r, the controller immediately echos "open" back to the serial port, which my Java program can read & print. Then, approximately after 1 second, when the robot actually executes the open (Open Gripper) command, the controller sends "Done.>" this response. I want to monitor & read this response "Done.>" because I want to check controller's response ("Done.>") before sending next command.
    1. Is it MUST to listen & read data at port at the time the data comes? Does the data gets lost if we don't read the data at the time it comes? For example, if data comes at 10000 millisecs, then is it MUST to start reading at 10000 or 10001? Would that data get lost if we start reading after say 3 seconds i.e. at 13000?
    2. If some data ("Done") comes at the serial port from controller and the Java program does not read that and if suppose more data (".>")comes at the serial port after 1/2 second, then does the previous data("Done") gets erased?
    3. My problem is --> the java program that I have written, can sometimes read & print controller's response --> "Done.>" and other times it does not find "Done.>"....That means the data --> "Done.>" is getting lost somewhere or Java program is not able to read it..The controller always sends "Done.>" when it excecutes "open" command.
    Thank You !
    Mayur
    Below is the code I am using...
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class WriteReadEdit implements SerialPortEventListener {
    CommPortIdentifier portId;
    Enumeration portList;
    OutputStream outputStream;
    InputStream inputStream;
    SerialPort serialPort;
    public static void main(String[] args) {
              String command1 = "open\r";
              String command2 = "close\r";                    
              boolean EndCharacterQMark = false;
              WriteReadEdit readObject = new WriteReadEdit();
                   readObject.Write(command1);
                   try {
                        EndCharacterQMark = readObject.waitUntilDataComes();
                        System.out.println("EndCharacterQMark is: " + EndCharacterQMark);
                   }     catch (IOException e) {}
                        if(EndCharacterQMark) {
                             EndCharacterQMark = false;
                             readObject.Write(command2);
                             try {
                                  EndCharacterQMark = readObject.waitUntilDataComes();
                                  System.out.println("EndCharacterQMark is: " + EndCharacterQMark);
                             }     catch (IOException e) {}
                        readObject.closePort();
    synchronized boolean waitUntilDataComes() throws IOException {
         String total="";
         boolean EndCharQMark = false;
         StringBuffer inputBuffer = new StringBuffer();
         int newData = 0;
         while(true) {
                        if(!dataAvailable()) {
                             try {                              
                                  wait();                              
                             }catch (InterruptedException e) {}
                   try {
                        while (newData != -1) {                         
                             newData = inputStream.read();
                             inputBuffer.append((char)newData);
                   }          catch (IOException ex) {
                             System.err.println(ex);
                        String dataAtPort = inputBuffer.toString();
                        for(int i = 0; i < dataAtPort.length(); i++) {                         
                                  if(dataAtPort.indexOf("?")>1 || dataAtPort.indexOf(">")>1 ) {
                                  EndCharQMark = true;
                                  return EndCharQMark;
    boolean dataAvailable() throws IOException {          
         return inputStream.available() > 0;
              void Write(String commandToSend) {
              String command = commandToSend;
              try {
                        outputStream.write(command.getBytes());                              
                        System.out.println("\nSuccessfully Written: " + command);
              } catch (IOException e) {System.out.println("IO Exception Occured: " + e);
    void closePort() {
         serialPort.close();
         System.out.println("Port closed successfully.");
    // Constructor()
    public WriteReadEdit() {
              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("writereadobjectApp", 2000);
                   System.out.println("Opened the port for writing: " + portId.getName());
              } catch (PortInUseException e) {
              try {
                   serialPort.setSerialPortParams(9600,
              SerialPort.DATABITS_8,
              SerialPort.STOPBITS_1,
              SerialPort.PARITY_NONE);
              } catch (UnsupportedCommOperationException e) {
                                            System.out.println("UnsupportedCommOperationException, Could not set the port: " + e);
                                       try {                                        
                                            outputStream = serialPort.getOutputStream();
                                            inputStream = serialPort.getInputStream();
                                       } catch (IOException e) {
                                       try {
                                            serialPort.addEventListener(this);
                                       } catch (TooManyListenersException e) {}
                                       serialPort.notifyOnDataAvailable(true);
    synchronized public void serialEvent(SerialPortEvent event) {
         switch(event.getEventType()) {
         case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
         case SerialPortEvent.DATA_AVAILABLE:
         notifyAll();          
         break;

    1. Usually there are buffers in the serial port controller. Apart from that, as long as the port is open, any data recieved will be added at the end of the InputStream of the comport so nothing will be lost.
    2. Nope, see above. But there might just be some kind of limit there.
    3. Download portmon http://www.sysinternals.com/ntw2k/freeware/portmon.shtml or any other prog that is able to monitor what's happening on you're serial port. This allows you to see if the response is really send by the robot.
    You're code seem to me to be more complex then it needs to be. Check out javax.comm.CommPort.enableRecieveTimeout(int). Setting a timeout will cause the the read function to return when the timeout is passed or data is recieved. A timeout of of say 4sec whould make sure that when a reply is send, it is recieved and it's stops reading when it gets no reply.
    In that case you could do with a sendMsg function wich dus not return until the correct response is recieved, or the timeout passed.
    You migth consider putting all the communicatoin with the com port in a different Thread so the rest of the program runs on when that thread is listening to the port...
    Hope this helps you a bit...

  • Occasional freeze when reading serial port

    I've a labview application which is a gui for a remote device via RS422.  The host computer is a quad core running XP SP3.  Initially I was developing with labview 7.1.1.  At random intervals (anywhere between 10 minutes and 5 hours observed), labview will freeze.  Using a port monitor during this freeze, I'm able to observe repeating calls for IOCTL_SERIAL_GET_COMM_STATUS followed by IRP_MJ_READ.  VISA is configured for 0.5s timeout.  The serial card is a MOXA, CP-114EL (4port RS422).  During the freeze, Labview cannot be closed.  Sometimes it will try by displaying the "Resetting..." text but it never completes.  A hard reset is then required.  After the freeze, processor usage is 25% (on average, 1 processor working full time for labview, but bouncing between cores).  Before the freeze, its less than 2%.
    At first I investigated the serial card driver via emails with MOXA.  After running a terminal emulation program and a loopback connector they gave me for several days without their program freezing, they're confident the problem isn't with their card or driver.  During discussions with them, I installed the evaluation of LabVIEW 2009.  The program still freezes except now I have less access to the VI (I used to be able to switch to the block diagram and via the highlighter tool observe it stuck in the read operation.  In either version though, the above mentioned port monitor output is the same.
    My instinct is that the source of the problem is in the multi-core application, some kind of timeout race condition.  My VI is fairly simple in summary, write a command (read temps, read status, write new params, etc) and wait for reply timing out if there's a problem.  Repeat.  Serial port is configured for 115kbps and transfers are in binary.  Before the freeze, the communication works well.
    I appreciate any suggestions.  I've looked around the net and this forum and didn't find anything similar.  Long time reader, first time poster.  I've a lot of experience in labview but can't solve this - the random interval doesn't help.  I think I'll start logging all serial transfers and see if anything always occurs before the freezing.

    This morning I updated the labview drivers to the most recent online (I hadn't done that yet when I installed LV2009, download was large).  It was something I planned to try if the LV2009 change alone did not resolve things.  The update also did not solve the serial freezing problem.
    I've attached two captures from NI Spy, one during normal operation and one of the last capture (up to the arrow).  I did a brief probing of a different VI that isn't a part of this afterward.  You can see the Read request of Com 2 for 266 bytes.  In the before image, red lines are timeouts.  So this read request is hung up waiting for bytes and never timing out.  That's at least my interpretation.
    I appreciate your and tbob's suggestions.  I've a new serial card (Brainboxes PX-310 card) to try coming soon, not that I don't want to solve this, I just can't spend too much time on it.  If it still gets hung up on the new card, I'll look into the motherboard PCIe port, maybe a failing transaction.  I would've went with the NI card but I need electrical isolation and 8 ports is excessive.
    Attachments:
    NI Spy - before freeze.JPG ‏104 KB
    NI Spy - after freeze.JPG ‏108 KB

  • How to detect if my external device is connected to the Serial port

    Hi,
    If I remove the cable from the serial port in my pc or either remove the serial cable from my external device, then when I send a request to open the serial port from my program, it basically does nothing, it just sits there.
    I want to be able to show some sort of message or any other way of indicating to the user that they should check the cable.
    below is the bit of code to open and set serial port params:
         public void openPort() {
              // Initialise the drivers
              System.setSecurityManager(null);
              String driverName = "com.sun.comm.Win32Driver";
              try {
                   CommDriver commdriver = (CommDriver) Class.forName(driverName)
                             .newInstance();
                   commdriver.initialize();
              } catch (Exception e2) {
                   e2.printStackTrace();
              // port will be set in Store Operations.
              String wantedPortName = Configuration
                        .getParameter(ConfigSetting.EFT_COM_PORT);
              //System.out.println("wantedPortname : " + wantedPortName);
              Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
              CommPortIdentifier portId = null; // will be set if port found
              while (portIdentifiers.hasMoreElements()) {
                   System.out.println("counter");
                   CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers
                             .nextElement();
                   System.out.println(pid.getName());
                   if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL
                             && pid.getName().equals(wantedPortName)) {
                        portId = pid;
                        System.out.println("found a macth");
                        break;
              } // end of while
              if (portId == null) {
                   System.err.println("Could not find serial port " + wantedPortName);
                   //System.exit(1);
              try {
                   port = (SerialPort) portId.open("EFTDriver", // Name of the
                                                                               // application
                                                                               // asking for the
                                                                               // port
                             10000 // Wait max. 10 sec. to acquire port
              } catch (PortInUseException e) {
                   e.printStackTrace();
                   System.err.println("Port already in use: " + e);
                   //System.exit(1);
              // Now we are granted exclusive access to the particular serial
              // port. We can configure it and obtain input and output streams.
              try {
                        port.setSerialPortParams(9600, SerialPort.DATABITS_8,
                             SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
              } catch (UnsupportedCommOperationException usc) {
                   System.err.println("Unsupported operation" + usc);
              }Please advise what method can I use for this purpose.
    Thanks
    Abhi

    You mean it hangs in the open() method despite the timeout?

  • I have problem with delay in serial port

    I have problem with serial port. I have connected two computers by serial port and I need to create program in Labview for transfer strings using start bits and stop bits. My problem is that my program is working quite well ...when I press start bit it starts to concatenate strings and if i press stop bits it stops...this is the purpose of this program...but problem is that it working only with delay...and need that this program dont need delay, because it can only concatenating data depends on delay from start bit....I wana solved problem with delay...I dont want using delay process in my program, but allways when I try to delete this delay it stop works correct
    here is my program

    Ok this should be simple - if I understand you correctly.
    You have the VISA session initialized with read termination character enabled.  So reading the number of bytes at port is NOT the correct way to read from the port.  Set the read number of bytes to something large (say 4096) and the read will return as soon as a termination character is received (or timeout).
    You'll need to make sure the sending device is configured to send termination character on writes (you can set that with a VISA property node)  and that you are sending the correct termination character.  The default is 0x0A (newline).
    Jeff

  • 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

  • Java ME 8 Permission check failed when opening a serial port

    I have a larger Jave ME8.1 application that was going well until I tried to add one last piece, reading and writing data from a serial port. This was left to last because it is trivial, at least in most programming languages. The is IDE NetBeans 8.0.2 running on a Windows 7 PC. The platform is a Raspberry Pi B or B+ (I have tried both) with the most current Raspbian (12/24/2014 I believe). To simplify the process I created a new app with just the open and close code and this generates the same error I am experiencing in the larger application. The program is as follows:
    package javamecomapp;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.microedition.io.CommConnection;
    import javax.microedition.io.Connector;
    import javax.microedition.midlet.MIDlet;
    * @author ****
    public class JavaMEcomApp extends MIDlet {
        static int BAUD_RATE = 38400;
        static String SERIAL_DEVICE = "ttyAMA0";
        static CommConnection commConnection = null;
        static OutputStream os = null;
        static InputStream is = null;
        static String connectorString;
        private int rtnValue = -1;
        @Override
        public void startApp() {
            java.lang.System.out.println("Opening comm port.");
            try {
                rtnValue = JavaMEcomApp.openComm();
            } catch (IOException ex) {
                Logger.getLogger(JavaMEcomApp.class.getName()).log(Level.SEVERE, null, ex);
        @Override
        public void destroyApp(boolean unconditional) {
            java.lang.System.out.println("Closing comm port.");
            try {
                rtnValue = JavaMEcomApp.closeComm();
            } catch (IOException ex) {
                Logger.getLogger(JavaMEcomApp.class.getName()).log(Level.SEVERE, null, ex);
            private static int openComm()throws IOException {
                java.lang.System.out.println("Opening comm port.");
                connectorString = "comm:" + SERIAL_DEVICE + ";baudrate=" + BAUD_RATE;
                commConnection = (CommConnection)Connector.open(connectorString);
                is  = commConnection.openInputStream();
                os = commConnection.openOutputStream();
            return 0;
        private static int closeComm()throws IOException {
            java.lang.System.out.println("Closing comm port.");
                is.close();
                os.close();
                commConnection.close();
            return 0;
    If I comment out the JavaMEcomApp.openComm and closeComm lines it runs fine. When they are included, the following error is dumped to the Raspberry Pi terminal:
    Opening comm port.
    Opening comm port.
    [CRITICAL] [SECURITY] iso=2:Permission check failed: javax.microedition.io.CommProtocolPermission "comm:ttyAMA0;baudrate=38400" ""
    TRACE: <at java.security.AccessControlException: >, startApp threw an Exception
    java.security.AccessControlException:
    - com/oracle/meep/security/AccessControllerInternal.checkPermission(), bci=118
    - java/security/AccessController.checkPermission(), bci=1
    - com/sun/midp/io/j2me/comm/Protocol.checkForPermission(), bci=16
    - com/sun/midp/io/j2me/comm/Protocol.openPrim(), bci=31
    - javax/microedition/io/Connector.open(), bci=77
    - javax/microedition/io/Connector.open(), bci=6
    - javax/microedition/io/Connector.open(), bci=3
    - javamecomapp/JavaMEcomApp.openComm(), bci=46
    - javamecomapp/JavaMEcomApp.startApp(), bci=9
    - javax/microedition/midlet/MIDletTunnelImpl.callStartApp(), bci=1
    - com/sun/midp/midlet/MIDletPeer.startApp(), bci=5
    - com/sun/midp/midlet/MIDletStateHandler.startSuite(), bci=246
    - com/sun/midp/main/AbstractMIDletSuiteLoader.startSuite(), bci=38
    - com/sun/midp/main/CldcMIDletSuiteLoader.startSuite(), bci=5
    - com/sun/midp/main/AbstractMIDletSuiteLoader.runMIDletSuite(), bci=130
    - com/sun/midp/main/AppIsolateMIDletSuiteLoader.main(), bci=26
    java.security.AccessControlException:
    - com/oracle/meep/security/AccessControllerInternal.checkPermission(), bci=118
    - java/security/AccessController.checkPermission(), bci=1
    - com/sun/midp/io/j2me/comm/Protocol.checkForPermission(), bci=16
    - com/sun/midp/io/j2me/comm/Protocol.openPrim(), bci=31
    - javax/microedition/io/Connector.open(), bci=77
    - javax/microedition/io/Connector.open(), bci=6
    - javax/microedition/io/Connector.open(), bci=3
    - javamecomapp/JavaMEcomApp.openComm(), bci=46
    - javamecomapp/JavaMEcomApp.startApp(), bci=9
    - javax/microedition/midlet/MIDletTunnelImpl.callStartApp(), bci=1
    - com/sun/midp/midlet/MIDletPeer.startApp(), bci=5
    - com/sun/midp/midlet/MIDletStateHandler.startSuite(), bci=246
    - com/sun/midp/main/AbstractMIDletSuiteLoader.startSuite(), bci=38
    - com/sun/midp/main/CldcMIDletSuiteLoader.startSuite(), bci=5
    - com/sun/midp/main/AbstractMIDletSuiteLoader.runMIDletSuite(), bci=130
    - com/sun/midp/main/AppIsolateMIDletSuiteLoader.main(), bci=26
    Closing comm port.
    Closing comm port.
    TRACE: <at java.lang.NullPointerException>, destroyApp threw an Exception
    java.lang.NullPointerException
    - javamecomapp/JavaMEcomApp.closeComm(), bci=11
    - javamecomapp/JavaMEcomApp.destroyApp(), bci=9
    - javax/microedition/midlet/MIDletTunnelImpl.callDestroyApp(), bci=2
    - com/sun/midp/midlet/MIDletPeer.destroyApp(), bci=6
    - com/sun/midp/midlet/MIDletStateHandler.startSuite(), bci=376
    - com/sun/midp/main/AbstractMIDletSuiteLoader.startSuite(), bci=38
    - com/sun/midp/main/CldcMIDletSuiteLoader.startSuite(), bci=5
    - com/sun/midp/main/AbstractMIDletSuiteLoader.runMIDletSuite(), bci=130
    - com/sun/midp/main/AppIsolateMIDletSuiteLoader.main(), bci=26
    java.lang.NullPointerException
    - javamecomapp/JavaMEcomApp.closeComm(), bci=11
    - javamecomapp/JavaMEcomApp.destroyApp(), bci=9
    - javax/microedition/midlet/MIDletTunnelImpl.callDestroyApp(), bci=2
    - com/sun/midp/midlet/MIDletPeer.destroyApp(), bci=6
    - com/sun/midp/midlet/MIDletStateHandler.startSuite(), bci=376
    - com/sun/midp/main/AbstractMIDletSuiteLoader.startSuite(), bci=38
    - com/sun/midp/main/CldcMIDletSuiteLoader.startSuite(), bci=5
    - com/sun/midp/main/AbstractMIDletSuiteLoader.runMIDletSuite(), bci=130
    com/sun/midp/main/AppIsolateMIDletSuiteLoader.main(), bci=26
    I have tried this with three different serial ports, /dev/ttyAMA0 (yes I did disable the OS from using it), an arduino board /dev/ttyACM0, and a USB to RS485 adaptor /dev/ttyUSB0. All of these ports could be connected and use normally with both a C program and terminal program in the Pi. The API Permissions were set in the project properties / Application Descriptor / API Permissions to jdk.dio.DeviceMgmtPermission "/dev/ttyAMA0". This of course was changed as I tested different devices.
    I found a reference suggesting adding the line "authentication.provider = com.oracle.meep.security.NullAuthenticationProvider" to the end of the jwc_properties.ini file. This had no effect. I found references that during development in eclipse and NetBeans, the app is already elevated to the top level so this should not be an issue until deployment. This does not appear to be the case.
    I am out of time and need a solution quickly. Any suggestions are welcome.

    Terrence,
       Thank you for responding and confirming the issues I'm having with static addressing.  As far as the example above, I do have the standard LEDs working correctly, however, the example I'm referring to above is from the JavaME samples using the GPIO Port for the LEDS, according to the Device I/O Preconfigured List you referenced:
    GPIO Ports
    The following GPIO ports are preconfigured.
    Devicel ID
    Device Name
    Mapped
    Configuration
    8
    LEDS
    PTB22
    PTE26
    PTB21
    direction = 1 (Output only)
    initValue = 0
    GPIOPins:
    controllerNumber = 1
    pinNumber = 22
    mode = 4 (Push-pull mode)
    controllerNumber = 4
    pinNumber = 26
    mode = 4 (Push-pull mode)
    controllerNumber = 1
    pinNumber = 21
    mode = 4 (Push-pull mode)
    So is the assumption that using GPIOPort for accessing the GPIO port for Device ID 8 as listed in the Device I/O Preconfigured list not supported?

  • Write to serial port asyncronously

    I am trying to write a commands to a serial port but my problem is that the operation is tedious so it is freezing up my UI. What makes it more complicated is that I must call this procedure when the form loads I want to ask if anyone can provide an alternative
    way to get the same or better result I was thinking of running it asynchronously but I don't know how to?
    This is the code I am calling on load
    If lblConnected.Text = "" Then
    MsgBox("Please connect to port.", MsgBoxStyle.OkOnly, "Validation")
    Exit Sub
    End If
    RichTextBox1.Text = ""
    Try
    With SerialPort1
    rcvdata = ""
    .Write("AT" & vbCrLf)
    Threading.Thread.Sleep(1)
    .Write("AT+CMGF=1" & vbCrLf)
    Threading.Thread.Sleep(1)
    .Write("AT+CPMS=""SM""" & vbCrLf)
    Threading.Thread.Sleep(1)
    .Write("AT+CMGL=""ALL""" & vbCrLf)
    Threading.Thread.Sleep(1)
    .Write("AT+CNUM" & vbCrLf)
    Threading.Thread.Sleep(2000)
    Dim lineoftext As String
    Dim arytextfile() As String
    Dim myString As String
    lineoftext = rcvdata.ToString
    arytextfile = Split(lineoftext, "Your number is", CompareMethod.Text)
    myString = "Your number is"
    lineoftext = lineoftext.Substring(lineoftext.IndexOf("Your number is"), 40)
    lineoftext = lineoftext.Replace("Your number is", "")
    lineoftext = lineoftext.Substring(0, 13)
    txtDonglePhoneNumber.Text = LTrim(lineoftext)
    End With
    Catch ex As Exception
    MsgBox(ex.Message)
    End Try
    I am trying to extract the phone number from this whole routine  and it works but its freezing up my UI. How can I run from another thread.
    If you think it you can achieve it

    Imports System.IO.Ports
    Imports System.Threading
    Public Class Form1
    Private comport As SerialPort
    Private sending As Boolean
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    sending = False
    End Sub
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    comport = CreateComport(comport)
    If sending = False AndAlso OpenComport(comport) = True Then
    Dim t As Threading.Thread = New Threading.Thread(AddressOf SendData)
    t.IsBackground = True
    t.Start(comport)
    End If
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    CloseComport(comport)
    End Sub
    Private Function CreateComport(ByVal port As SerialPort) As SerialPort
    If port Is Nothing Then
    port = New SerialPort("COM4", 9600, Parity.None, 8, StopBits.One)
    End If
    Return port
    End Function
    Private Function OpenComport(ByVal port As SerialPort) As Boolean
    Try
    If (Not port Is Nothing) AndAlso (port.IsOpen = False) Then
    port.Open()
    End If
    Return True
    Catch ex As Exception
    MessageBox.Show(String.Format("Exception :{0}", ex.ToString()))
    Return False
    End Try
    End Function
    Private Sub CloseComport(ByVal port As SerialPort)
    Try
    If (sending = False) AndAlso (Not port Is Nothing) AndAlso (port.IsOpen) Then
    port.Close()
    MessageBox.Show("Port closed")
    End If
    Catch ex As Exception
    MessageBox.Show(String.Format("Exception :{0}", ex.ToString()))
    End Try
    End Sub
    Private Sub SendData(ByVal port As Object)
    Dim buffer(1023) As Byte
    For i As Int32 = 0 To buffer.Length - 1
    buffer(i) = i Mod 256
    Next
    sending = True
    Try
    DirectCast(port, SerialPort).Write(buffer, 0, buffer.Length)
    Catch ex As Exception
    CloseComport(DirectCast(port, SerialPort))
    MessageBox.Show(String.Format("Exception :{0}", ex.ToString()))
    Finally
    sending = False
    End Try
    End Sub
    End Class
    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

  • Writing to serial port

    I currently send ASCII characters to a serial port. I have not errors reported back. Everything appears to be error free, except that the device that I am trying to control does nothing. The device being controlled does not send anything back to the pc. The connection is strictly a one way connection. Do you have to send a carriage return or something to get the ASCII characters to "push" out of the buffer? - Sorry I don't have access to my code at the moment.

    A portion of my code is below. What does the 'flush'
    do? I thought it just emptied out the buffer.
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier)
    tIdentifier) portList.nextElement();
    if (portId.getPortType() ==
    ortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM1"))
    .equals("COM1")) {
    try {
    serialPort = (SerialPort)
    portId.open("SimpleWriteApp",
    d.open("SimpleWriteApp", 2000);
    } catch (PortInUseException e)
    ortInUseException e) {}People get life for this crime!
    try {
    outputStream =
    outputStream =
    tStream = serialPort.getOutputStream();
    } catch (IOException e) {}So you now have two life sentences to serve.
    try {
    serialPort.setSerialPortParams(9600,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch
    } catch
    } catch (UnsupportedCommOperationException e) {}Sorry, three life sentences to serve.
    try {
    outputStream.write(rightString.getBytes());
    } catch (IOException e) {}You get the prize! Four life sentences from a short bit of code.
    }P.S. You should really use the COMM api for writing to serial ports.

  • How to access the serial port in Java?

    How can I initialise and access the serial port for writing and reading data from it? Are there any code examples available?

    I tried that and I tried compiling and executing one of its examples, the one below:
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class SimpleWrite {
    static Enumeration portList;
    static CommPortIdentifier portId;
    static String messageString = "Hello, world!\n";
    static SerialPort serialPort;
    static OutputStream outputStream;
    public static void main(String[] args) {
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier) portList.nextElement();
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    if (portId.getName().equals("COM1")) {
    //if (portId.getName().equals("/dev/term/a")) {
    try {
    serialPort = (SerialPort)
    portId.open("SimpleWriteApp", 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) {}
    But when I execute this I get the error:
    Exception in thread "main" java.lang.NoClassDefFoundError: SimpleWrite
    What is wrong with this example??

  • 0 bytes at serial port after Visa Write

    Hi,
    I'm having problems communicating with a Pollux box controlling a stepper motor (both from Micos). The Pollux box has an RS232/485 connection to the computer. 
    I have tried adaptations of LV's Basic Serial Read and Write example. Even for the basic example there has never been any bytes at the serial port after the write.
    I have attached some sample code for LV 10.0.1(64bit) and the OS is Windows Server Enterprise 2008.
    The Visa drivers have just been installed.
    After some research I have added a 'Set I/O buffer size' as advised by http://digital.ni.com/public.nsf/allkb/60DDFED7EFEFE7188625705700750821?OpenDocument
    The time-out is set to 10s, I have a wait of 1s before read and 0.5s between each write (the characters are written individually incase that was the problem).
    The write command getaxisno_ should reply with the default axis no which is 1. However, there is never any reply.
    The termination character for Venus2 is a space for transmitting commands and ASCII CR LF at the end of received data.
    I'm not sure what else could be wrong. According to MAX the device is working properly. Although, when I try to open a Visa test panel in MAX the program crashes. I'm not sure if this is a related problem.
    I'd be really grateful for any advice, have been trying to fix this for a few days now.
    Thanks in advance!
    Ciara
    Attachments:
    Getaxisno test.vi ‏18 KB

    Thanks, I'll search those now.
    When I click the test panel button, the Max window disappears and the program is closed. Next time I open it an Unexpected Error box opens with a message saying there was an unexpected error and I should search Info Code MAXKnownException.
    'The exception occurred in the NIMax process in the function (Unknown).'
    I have searched this and the info advised me to send a report with log files etc to NI which I have done. Just waiting on the reply.
    I copied the Visa resource name from MAX and the termination character is the same as what a previous owner of the equipment used in Visual Basic. 

  • Serial port vi taking too much time to communicate?

    i am using visa vis for serial communication the read vi takes too much time to give me the bytes at serial port.what should i do to decrease the delay?

    You wouldn't happen to be specifying a byte count to read or setting read termination when a specific character is read would you? If you are, if you don't have the right number of bytes in the serial buffer or if the termination character is not seen, then VISA read will wait for the time specifed by the VISA timeout value. To fix the first problem, use the VISA Bytes at Serial Port function to determine how many bytes to read. In the second case, use a VISA property node to set Message Based Settings:Termination Character Enable to false and Serial Settingserial End Mode for Reads to none.

Maybe you are looking for

  • How do you add a card to passbook

    how do you add a card to passbook

  • HT2494 Lightning to SD Card Camera Reader.

    I attached the reader to the Mac Air and can find it in the finder location.  But when I go to open it there is nothing there. The SD card is in the reader.  My software is Mac OS X Lion 10.7.5(11G63). One thing i read is that my software needs to be

  • F-05 Function?

    Dear Experts, I need to post foreign currency valuation (F-05) with document currency amount = 0 but local currency amount > 0. I've tried function BAPI_ACC_DOCUMENT_POST, it does not allow amount 0 in line item, so I cannot post it correctly. I also

  • All of my address book information is gone!  Any fixes?

    This seems to happen once in a while whenever I download an Apple update. I opened Mail to send an email and all of my addresses are gone. Any assistance would be greatly appreciated.

  • Remembering the column selection on the iPod song pane...

    Is there a way I can force iTunes to remember the particular columns I select on my iPod's song pane? It seems that every time I connect the iPod (nano 4gb) it resets the song pane colums to some default setting. This problem does not seem to happen