How to generate non-blocking commands to a serial device

I have a serial device which accepts non-blocking commands. This is, if you send a command that takes 1 minute, while this happens, you can send more commands and they will be executed. Once a command is done, it sends back a code that relates to that command, so you know it is finished.
I have a VI which tries to communicate with this serial device (see attachment). It does work, but it blocks the execution until a command is finished. So I can send commands one by one, but not in parallel, or in a delayed non-block way. The problem is the while loop which waits until the device outputs something.
I need to do something similar, but non blocking. The VI should be able to send several commands while others are executed.
This subVI is controlled from a main VI, which is just a State Machine with a few states, where each state is some action which is sent to this subVI, and then to the serial device.
Attachments:
blocking_vi.png ‏27 KB

Use another loop that does nothing but read from the serial port.  Report the data to whoever needs it with a Queue.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines

Similar Messages

  • How to close non blocking sockets

    Hello!
    I need your help with this. I'm writing a little server(ServerSocketChannel), versy simple, receives data, maskes some fast analisis, and stores it. However, the client make little transmissions and the close the connections. How can I detect a clsoe event with the select keys?. And how can I close the server?

    You will get an OP_READ, and when you do the read it will return -1, whereupon you close the channel.

  • How to generate variables whose name are in serial?

    I want to dynamically generate a serial of varials, like var1, var2, var3... How can I do this?

    an array perhaps.... You want want to pick up a book on the basics.

  • Non blocking sockets

    Hi All,
    Anybody have some idea about how to implement non blocking sockets using two threads/Can u help me with some sites where i can get more information in this topic.
    Regards
    Priya

    hi,
    you could have a look at the nonblocking io (nio) api's present in jdk1.4, that should do the trick. this link ought to get u started i suppose..
    http://developer.java.sun.com/developer/technicalArticles/releases/nio/
    hope this helps.
    cheerz
    ynkrish

  • Non-blocking SocketChannels

    I'm trying to learn how to use non-blocking socket channles, but I haven't found much info (nor luck) so far.
    To learn, I'm building a server and a client. The server accepts input from the clients and process it in only one thread. The clients should send Objects to the server, and the server process them and return the result also as an Object. For this, I'm trying to use ObjectOutputStream and ObjectInputStream.
    The problem I don't know how to solve is that the SocketChannel is in non-bolcking mode, so I can't use their input/output streams (I get a IllegalBlockingModeException). In the server process loop I can reconfigure the SocketChannel to blocking mode to be able to read the Object, but I can't configure it to non-blocking mode again because I get a CancelledKeyException.
    Does anyone know how to work with InputStreams and non-blocking channels? Or where to find more info about it?
    Here are the relevant part of the server code:
    Set ready = selector.selectedKeys();
    Iterator i = ready.iterator();
    while (i.hasNext()) {
       try {
          SelectionKey sk = i.next();
          i.remove();
          if (sk.isAcceptable()) {
             ServerSocketChannel ssc = (ServerSocketChannel)sk.channel();
             SocketChannel sc = ssc.accept();
             sc.configureBlocking(false);
             sc.register(selector, SelectionKey.OP_READ);
          } else if (sk.isReadable()) {
             SocketChannel sc = (SocketChannel)sk.channel();
             // PROBLEM: If the channel is in non-blocking mode
             // I cannot use InputStreams
             sk.cancel();
             sc.configureBlocking(true);
             // Read the object sent by the client
             ObjectInputStream in = new ObjectInputStream(Channels.newInputStream(sc));
             Object o = in.readObject();
             // PROBLEM: Can't put the channel back to non-blocking mode
             sc.configureBlocking(false);
             sc.register(selector, SelectionKey.OP_READ); // CancelledKeyException
       } catch (...){
    }

    In my client, this is working fine:
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    for (int i = 0; i < 30000; i++) {
       oos = new ObjectOutputStream(sc.socket().getOutputStream());
       oos.writeObject(object);
       oos.flush();
       ois = new ObjectInputStream(sc.socket().getInputStream());
       Object o = ois.readObject();
    }But trying to do it like this throws a StreamCorruptedException at the server side.
    ObjectOutputStream oos = new ObjectOutputStream(sc.socket().getOutputStream());
    ObjectInputStream ois = new ObjectInputStream(sc.socket().getInputStream());
    for (int i = 0; i < 30000; i++) {
       oos.writeObject(object);
       oos.flush();
       Object o = ois.readObject();
    }Do you know why?

  • Easy way to non-blocked sockets

    Use JSSE and NIO for a quick way to implement non-blocking communications
    October 22, 2003
    Although SSL blocking operations -- in which the socket is blocked from access while data is being read from or written to -- provide better I/O-error notification than the non-blocking counterpart, non-blocking operations allow the calling thread to continue. In this article, the author will cover both the client and server side as he describes how to create non-blocking secure connections using the Java Secure Socket Extensions (JSSE) and the Java NIO (new I/O) library, and he will explain the traditional approach to creating a non-blocking socket, as well as an alternative (and necessary) method if you want to use JSSE with NIO.
    http://www-106.ibm.com/developerworks/java/library/j-sslnb.html?ca=dgr-jw03j-sslnb

    MORE IBM SPAM Previous discussion
    I find it interesting spam, but thats a matter of taste. If the OP was truly interested in "trying to get new information out there" he would answer the mulitple questions about NIO and especially NIO mixed with traditional Sockets and NIO vs Secure Sockets. These are all on ALT, NIO is of no interest to New to Java folk.
    Given their budget I think IBM could do a better job of publishing their research.

  • How Do You Send the END KEY via Serial?

    Hello All,
    I'm trying to do something that would seem simple, but is not because almost no information about the END KEY on keyboards is posted online.  Essentially, I'm trying to activate a device that comes out of sleep when someone presses the END KEY through hyperterminal or some ascii based command window.  I'm trying to send that END KEY automatically using Labview, but I'm stuck. So here are my questions.
    Does the END KEY have a specific ASCII number?  I'm getting 2 different answers in my search for this one.
    If it doesn't, how do I send that command over the serial communications line?
    If it does, then what's the best way to convert it to something that labview understands as the END KEY, and not some combo of characters?
    Thanks a bunch.
    Matt

    You would have to find out the character that is mapped to the END key and simply send that out the serial port. You may want to try sending 0x4f". At least this is what I found for the mapping of the END key.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How to run non-customised report from command prompt to gen trace file?

    Hi
    how to run non-customised report from command prompt to gen trace file?
    EBS R12 RUP6.
    RHEL5
    rgrds

    Hi,
    See (Note: 285497.1 - Rwrun.sh Does Not Generate Trace Output Using TRACEOPTS in Command Line) and/or (Note: 737445.1 - R12 Concurrent Requests Run Forever; rwrun Errors REP-50125) for the command you need to use.
    Thanks,
    Hussein

  • How to generate load commands from cap (ijc)

    I don't understand how to generate load command from cap (in my case ijc)-file.
    This is the example from GPShell, first command of three:
    Command --> 1. 80E80000EFC48203DE01001ADECAFFED01020400011048656C6C6F576F726C64303030305F5002001F001A001F00140031006E00180147004E0036000000F1000A0005003503010004003103000107A0000000620101060210A0000000090003FFFFFFFF8910710002000110A0000000090005FFFFFFFF8913000000030014011048656C6C6F576F726C64303030305F410031060018438003020001070200000041004480020081010108810000070147000A40188C0002188D00058700181100FFAD007B0003037B00039210210303038B0004538901AD00058B0006188B00077A05308F0008181D1E1100FF538C00097A0020
    questions:
    1. Why the length of each command is equal to EF (239 bytes)? Maybe 239 bytes + Mac len + cla, ins, p1,p2, cmdLen. I mean, will the length always be EF?
    2. C48203DE - what is it. In the GP221 i found:
    'C4' 1-n Load File Data Block Mandatory. So if it is right, is the 8203DE - Load File Data Block? Because real data from my ijc-file starts after DE - 01001...
    3. Is all data from the file used for load? (i notised that the last command does'nt used all the rest bytes)

    So, I will help myself
    CAP is zip, but with other filename extension. Inside there are following files:
    Applet.cap
    Class.cap
    ConstantPool.cap
    Debug.cap
    Descriptor.cap
    Directory.cap
    Header.cap
    Import.cap
    Method.cap
    RefLocation.cap
    StaticField.cap
    Order of reading these files for loading by commands 80E8 the following:
    loading Header.cap (51 byte)
    loading Directory.cap (36 byte)
    loading Import.cap (55 byte)
    loading Applet.cap (19 byte)
    loading Class.cap (19 byte)
    loading Method.cap (6779 byte)
    loading StaticField.cap (13 byte)
    loading ConstantPool.cap (397 byte)
    loading RefLocation.cap (663 byte)
    loading Descriptor.cap (1005 byte)
    loading Debug.cap (12115 byte)
    But ijc the file is not cap (zip) and while I didn't understand how to load ijc

  • How to handle write errors in non blocking sockets

    Hi,
    I'm using sockets registered with a Selector for read operations. I've seen code examples that put the SocketChannel in non blocking mode before registering it with the selector, and in fact not doing so would cause an IllegalBlockingModeException to be thrown.
    My problem is that I can't handle write errors. The call to write() returns inmediately without throwing any exception. Even worse, when the network timeout expires the selector wakes up and I get an exception on read(). So I can't tell the difference between a real read error and a write error.
    What can I do? Is there a magic method I haven't heard about?
    Thanks

    ejp wrote:
    OK, so what happens is this: you write from your ByteBuffer; if there is room in the socket send buffer, the data is transferred and the transfer count is returned. (If there isn''t, the write returns zero and nothing has happened.) Your application code then continues. Meanwhile TCP is trying to send the data in the send buffer and get an ACK from the peer. If the peer is down as per your test, eventually those write attempts will time out. You will then get a connection reset exception on the next read or write.
    Even worse, when the network timeout expires the selector wakes upCorrect, to tell you there is an error condition pending. This is good, not bad.You're right. This way my program can know that something happened.
    But I still don't understand what the difference between a failed write() and a failed read() is. I mean, the error condition may appear during a send attempt, or it may appear after sending. In both cases I get an error when trying to read. How can my program know if data have been received by the other end?
    Do I have to implement ACK messages in the application level protocol??? It'd be nice if TCP could do this for me...

  • How to generate a new rhread for every request

    Hello,
    I'm trying to write a server side program that does the following, recieves a Single connection from a client, client sends a request to the server side program, the server side program sends to a third party(back end) and waits for a reply.
    The problem i am facing is the following, I want to for each message(request) recieved from the Client to generate a new thread and establish a new connection with the third party, I have tried creating a new thread for the communication with the third party, in this case if the response from backend takes time I will still be able to recieve other requests from the client. But I dont know how to return the message that his been to the Father thread. The reason why I am doing this is that I dont want the same thread that recieves the request from client to wait until the reply for the previous thread is sent.
    Here's the code which I have been trying to implement.
    ClientCommunicator {
    Socket soc= new Socket(IPAddress,port);
    Thread backEndComm= new Thread (new BackEndCommunicator
    (soc,"Message To Back End"));
    backEndComm.setPriority(8);
    backEndComm.start();
    public class BackEndCommunicator implements Runnable
    Socket socket;
    String messageToBeSentToBE= "";
    public BackEndCommunicator(Socket socket, String messageTOBE)
    this.socket= socket;
    messageToBeSentToBE= messageTOBE;
    public void run()
    PrintWriter outtBackEnd= null;
    BufferedReader innBackEnd= null;
    String replyFromBE= "";
    try
    outtBackEnd= new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
    outtBackEnd.println(messageToBeSentToBE);
    outtBackEnd.flush();
    innBackEnd= new BufferedReader(new InputStreamReader(socket.getInputStream()));
    replyFromBE= innBackEnd.readLine();
    How can I return the String "replyFromBE" to the ClientCommunicator class so it can be sent to the client as soon as recieved from the back end.
    regards,
    [email protected]

    I assume the problem you are having is that your ClientCommunicator thread is blocking in a read and has no way of receiving notification from the other thread. Seems like you have a couple options at least.
    1. Use non-blocking IO and a selector to do service both the client socket and the backend socket. Usually, NIO is more of a pain than it is worth unless you need to service hundreds of connections at once, but I think that in this case where you know that there are only two connections it might be easy enough to use.
    2. A second option would be to avoid blocking on the read by using the available method on the input stream to first determine if you can actually read anything. This would allow you to wait with a small timeout on a monitor that the backend communicator could notify when it receives a response. This is not the ideal solution because you are limiting how fast you respond to the client and could be using more cpu time than necessary. However, it might be a lot easier to implement and could be adequate for what you need.
    First solution is more elegant but potentially not worth the trouble. Second solution is less elegant, but may be good enough.

  • How to open the block diagram of the NI ELVISmx

    How to view the program block diagram of the virtual instrument of the function generator, oscilloscope and so on in the NI ELVISmx,, I have seen before, but now I forgotten how to open the block diagram, who know?
    1110340036    jyh

    iOS apps can be added to an iTunes library and thereafter transferred to an iOS device. They cannot be opened directly on a PC.
    epub files can be added to an iTunes library, and thereafter transferred to an iOS device where they can be read with the iBooks application. Files protected with Apple's DRM cannot be opened directly on a PC, though there are programs such as Kindle and Calibre that will open non-protected epub files.
    tt2

  • Non-blocking serialization

    Dear all,
    Does anybody know whether PI/XI supports the non-blocking serialization function?
    And in which version?
    If not, is there any work-around?
    Thanks a lot.
    best regards
    Jing

    HI
    Serialization plays an important role in distributing interdependent objects, especially when master data is being distributed.
    IDocs can be created, sent and posted in a specified order by distributing message types serially.
    Errors can then be avoided when processing inbound IDocs.
    Interdependent messages can be serially distributed in the following ways:
    Serialization by Object Type
    Serialization by Message Type
    Serialization at IDoc Level
    (not for IDocs from generated BAPI-ALE interfaces)
    Serialization at IDoc Level
    Use
    Delays in transferring IDocs may result in an IDoc containing data belonging to a specific object arriving at its destination before an "older" IDoc that contains different data belonging to the same object. Applications can use the ALE Serialization API to specify the order IDocs of the same message type are processed in and to prevent old IDocs from being posted if processing is repeated.
    ALE provides two function modules to serialize IDocs which the posting function module has to invoke:
    u2022 IDOC_SERIALIZATION_CHECK
    checks the time stamps in the serialization field of the IDoc header.
    u2022 IDOC_SERIAL_POST
    updates the serialization table.
    Check the following link:
    http://help.sap.com/saphelp_nw04s/helpdata/en/0b/2a66d6507d11d18ee90000e8366fc2/frameset.htm
    http://help.sap.com/saphelp_nw04s/helpdata/en/78/2175a751ce11d189570000e829fbbd/frameset.htm
    How to serialize IDoc XML messages fed into XI
    cheers

  • Non-Blocking call to read the Keyboard

    does anyone know how to make a JAVA program make a non-blocking call to read the keyboard? eg. write a program which generates prime number until a keyboard key is pressed.

    if you use a gui you can use keyListener
    Would work only if your gui elements have focus right now.

  • Sockets in non-blocking mode

    Hello Techies,
    How to set sockets in the non-blocking mode and what is the main use of setting sockets in non-blocking mode.
    regards,
    Ramu.

    Hello Techies,
    Thanks for u r replies,
    Finally i had understood how to use nio. But the problem is it is going into infinite loop. Here is my code.
    package networking;
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.CharBuffer;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.nio.charset.Charset;
    import java.nio.charset.CharsetDecoder;
    import java.util.Iterator;
    public class testSocketChannel {
          * @param args
         public static ByteBuffer buf ;
         public static SocketChannel clientChannel;
         public static void main(String[] args) {
              // TODO Auto-generated method stub
                        try
                             Selector selector = Selector.open();
                         clientChannel = SocketChannel.open();
                      clientChannel.configureBlocking(false);
                      // Send a connection request to the server; this method is non-blocking
                      clientChannel.connect(new InetSocketAddress("localhost",90));
                      clientChannel.register(selector,clientChannel.validOps());
    //                Wait for events
                      while (true)
                          try {
                              // Wait for an event
                              selector.select();
                          } catch (IOException e) {
                              // Handle error with selector
                              //break;
                          // Get list of selection keys with pending events
                          Iterator it = selector.selectedKeys().iterator();
                          // Process each key at a time
                          //while (it.hasNext())
                               for(int i = 0;i<selector.selectedKeys().size();i++)
                              // Get the selection key
                              SelectionKey selKey = (SelectionKey)it.next();
                              // Remove it from the list to indicate that it is being processed
                              it.remove();
                              try
                          //  processSelectionKey(selKey);
                                    if (selKey.isValid() && selKey.isConnectable()) {
                                       // Get channel with connection request
                                       SocketChannel sChannel = (SocketChannel)selKey.channel();
                                       boolean success = sChannel.finishConnect();
                                       if (!success) {
                                           // An error occurred; handle it
                                           // Unregister the channel with this selector
                                           selKey.cancel();
                                   if (selKey.isValid() && selKey.isReadable()) {
                                       // Get channel with bytes to read
                                        clientChannel = (SocketChannel)selKey.channel();
                                       System.out.println("INSIDE reading");
                                       // See e174 Reading from a SocketChannel
                                       // Clear the buffer and read bytes from socket
    //                                 Clear the buffer and read bytes from socket
                                      // ByteBuffer byteBuffer = ByteBuffer.allocate( BUFSIZE );
                                       buf = ByteBuffer.allocateDirect(1024);
                                       int nbytes = clientChannel.read( buf );
                                       buf.flip();
                                       Charset charset = Charset.forName( "us-ascii" );
                                       CharsetDecoder decoder = charset.newDecoder();
                                       CharBuffer charBuffer = decoder.decode( buf );
                                       String result = charBuffer.toString();
                                   if (selKey.isValid() && selKey.isWritable()) {
                                       // Get channel that's ready for more bytes
                                       //SocketChannel sChannel = (SocketChannel)selKey.channel();
                                       System.out.println("INSIDE writting");
                                       // See e175 Writing to a SocketChannel
                                     String message = "hi"; 
                                      buf = ByteBuffer.wrap( message.getBytes()  );
                                       int nbytes = clientChannel.write( buf );
                                       System.out.println( "Wrote " + nbytes + " to channel." );
                              catch (IOException e) {
                                       // TODO: handle exception
                                   System.out.println("IOException"+e.getMessage());
                        catch (IOException ioe) {
                             // TODO: handle exception
                             System.out.println("IOException"+ioe.getMessage());
    }How to stop this infinite loop.
    Need quick replies.
    Ramu

Maybe you are looking for

  • Adobe Flash CS5 - Blur effect & tween not working

    When I try to create a tween for the blur, so it will blur into focus, the tween just wont work. I go to frame 130, keyframe, add blur filter, create clasic tween. But when i go to frame 131 it instantly pops into focus instead of going along the twe

  • Windows 7 Download error - CDBOOT: Couldn't Find BOOTMGR

    I'm downloading Windows 7 Professional from a disc. I downloaded the support software to a USB flash drive using bootcamp, and that all went fine. Then I chose the partition size, put in my Windows 7 disc, it partitioned & rebooted, and I thought it

  • Duplicate Item code

    Hi All, My query goes like this SELECT DISTINCT(T0.[ItemCode]), T0.[ItemName], T1.[OnHand] as STOCK_IN_METER, T2.[Price] as BASE_PRICE, T0.[U_Length_In_Meter],T1.[OnHand]/T0.[U_Length_In_Meter] as STOCK_IN_PIECE, T0.[U_Weight_kgm], T1.[OnHand]* T0.[U

  • Enter password many times

    when i download app updates on Mac osx 10.8.3 with itunes 11.0.3 64 bit. the application askes me to enter my itunes users ID and password repeater

  • Exporting to flash with embedded video HELP

    I am working on a presentation that includes a video I shot and edited on FCP. I used compressor to resize and reformat to a mpeg4, which I thought would be a very universal format. However, while it does play nicely in my Keynote presentation, it re