Serial port control -- what's this code snippet?

Hi, all.
I've just become active working with LabView, version 6.0i. And this because of a program which "suddenly" stopped working, with no changes made by anyone that I can see (yeah, likely story, right?).
In short, the screenshot which I'll include with this post is of one tiny code snippet buried deeply in the .vi which runs an X-Z positioning system. I'd like to know what people thing this code snippet does. I have my suspicions, but I can't believe that whoever wrote this code actually used it for this purpose!
The X- and Z-positioners which I'm using are controlled by separate power sources, and separate ports on the computer. The X-positioner is ultra-fine-resolution, and has an optical encoder. It's controlled by the RS-232 port on the computer, and it's meant to be moved only a little at a time. The Z-positioner is a bit more coarse, and usually moves quite a bit at a time. It's serial-port controlled.
The screenshot is of the portion of the code called "XMove" -- that portion of the code which controls the x-positioning stepper motor. Often, the Z-positioner is still running during this part of the code (the "ZMove" subroutine is called before the "XMove"), and then, after both parts of the positioner have stopped, the code should shut down the power to them, and update the position of the translation stage.
However, once the code gets to this portion (screenshot), that while loop just keeps running.
Here's what I think is happening (please correct me if I'm wrong!): The Z-positioner is run by the serial port, which, as far as I know, can be controlled by only one device at a time. Thus, this While loop does the following:
1) attempts to write the characters "1R" followed by a linefeed to port 0 (the applicable serial port on this computer);
2) reads how many characters are stored in the serial buffer;
3) reads all the characters in the serial buffer;
4) takes the first two characters from the string read;
5) compares these two characters to *R;
6) if the two characters are R, then the loop terminates and the code finishes.
As far as I can tell (I've probed many parts of this structure), the code fails when the "N" portion passes the number of characters in the serial buffer to the "R" portion -- it's always zero. It appears to me that the "W" portion writes to the buffer AFTER the number of characters is read (I wouldn't have suspected this unless I'd run it many times and monitored which steps were done in which order). This ain't right!
I found a similar question answered in the KnowledgeBase forum, but the answer to that one was that the serial port may have an "echo" mode. That doesn't change the fact that data is being from to the port before it's written, does it?
Is there a way to make sure that the "read" statement happens AFTER the "write" statement? Am I way off base with what this code snippet should do? And, most importantly, *** is this a good way to tell if the Z-positioner is done with its job? ***. Is this a standard trick to tell if a program is done with the serial port?
Thanks, all. I know the quandary of trying to debug with so few details, and not having the program in front of you. Any help is appreciated!
Curtis Osterhoudt
VI_diagram.jpg ‏17 KB

I suspect someone did change it, but they just don't realize they did.
THe code snippet is an example of some very bad LV code! What you suspect is happeneing is indeed true. LV uses a data dependacy paradigm that says code execution order is dependent on data availablility. Data availability is determined by ythe rule that the output of a node or sub-VI is not available until the object completes.
In you snipet, the only node that has to complete before the read bytes at port and the write to port VI is the the constant port number constant. That means that LV can execute either the write or the check bytes at port VI's first. This is determined at LV compile time. If for some reason LV decideds to compile in the write before the check bytes at port, the
n the I/O may work as intended, BUT NOT POROGRAMMED!
For a quick fix, put the contant port number and the write VI in a single frame sequence structure. This way the read from the constant and wire operation must comlplete before the seq completes, therby forcing the read stuff to wait.
I hope this help,
Ben Rayner
Certified LabVIEW Developer
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction

Similar Messages

  • I have just tried to sync my iphone. Error message saying it cannot be synced has popped up quoting error code (-50). I have just removed old iphone backups from itunes but was very careful to not delete the current one. What does this code mean?

    Hi there,
    I have just tried to sync my iphone.
    Worryingly an error message saying it cannot be synced has popped up quoting error code (-50)
    I have just removed old iphone backups from itunes but was very careful to not delete the current one
    What does this code mean?

  • What does " this code must be redeemed in the Australian storefront " mean? And how can I fix it?

    What does " this code must be redeemed in the Australian storefront " mean? And can I fix it?

    All iTunes gifts and gift cards are country-specific, they can only be redeemed and used in their country of issue. Are you in Australia with an Australian billing address on your account ? If you are then try going to the bottom of the Featured tab in the App Store app on your iPad and tap on your account id, tap on 'View Apple ID' on the popup and log into your account, and then select the Country/Region section and select Australia.
    If you are not in Australia then you won't be able to use it.

  • Please explain what does this code does exactly

    Can any one explain me what does the below code does.
    This is the code written in one of the BADI (ME_PO_PRICING_CUST) .This badi will be triggered when a sales order delivery address is changed and while saving it this will be triggered. Over all what i come to know is they re trigerring a new version in this code. Can anyone explain me what exactly they are doing in this.Thanks...
                     <PROCSTAT> TYPE MEPROCSTATE,
                     <FRGKE> TYPE FRGKE,
                     <YNAST> TYPE TABLE,
                     <WA_YNAST> TYPE NAST.
      IM_EKKO-PROCSTAT = 02.
        IF <FRGKE> = 'R'.
          <PROCSTAT> = '02'.
        IF <FRGKE> = 'R'.
            <WA_YNAST>-AKTIV = 'X'.

    r_htkl must be a range table. check the declaration part of it.
    p_htkl is a parameter on selection screen i hope.
    so, there are four fields on a range table.(range table are similar to your select options)
    1. SIGN ( I or E  - Inclusive or Exculsive)
    2. OPTION(options like EQ = euqal, BT = Between, CP = contains pattern etc)
    3. LOW (value)
    4. HIGH (value)
    IF NOT p_htkl IS INITIAL. " checks if some thing is being passed to the parameter
    r_htkl-sign='I'. " give the sign a value I i.e it make inclusive sign
    r_htkl-option='EQ'. " EQ to option means you value will be checked for a equal to condition
    r_htkl-low=p_htkl. " the low field in now assigned the same value of the parameter p_hktl
    APPEND r_htkl. " the range table is appended.
    so this range table can be used in select statements as :
    select * from abcd into gt where xyz in r_hktl. ==> this will check for a EQ condition with value in r_hktl-low in database or
    in if statements like : if abc in r_hktl. ==> this will check the EQ condition of abc with the r_hktl-low.
    Had it been
    then the condition is same but with a NOT.. that means NOT EQ or NOT BT etc.
    as exclusive of the option.
    hope this is clear.

  • Please help me with this error in this code snippet!

    Code Snippet:
    data : f1(2) type c,
           f2(2) type c,
           f3(10) type n value '12345'.
      clear: f1 with 'X',
             f2 with f1,
             f3 with '3'.
    write :/ f1 ,f2, f3.
    Process Error:
    The field "F1" must have the length 1.

    hi ,
    ther is not syntax with clear with 'X".
    but you can do one thing to get the one character.
    data : f1(2) type c,
    f2(2) type c,
    f3(10) type n value '12345'.
    clear: f1 with 'X',  "Comment this
    f1 = f1+0(1).        "write this
    f2 with f1,
    f3 with '3'.
    write :/ f1 ,f2, f3.
    now f1 containd one charater instead of 2.
    now you can display as usuall

  • Can anyone explain this code snippet

    I'm revising for my exams and this is one of the question that came up in the previous exams. Can someone help answe the questions at the end. Also what object is 'time_t' and how why do they use 'input_time -= 24*60*60;'?
    Read the following code carefully before answering the questions.
    time_t normalise(time_t input_time)
         bool finished;
         // This produces a formatted time string like:
         // Thu_Nov_24_18:22:48_1986
         string str_time = format_time( input_time );
         while( str_time.substr(1,3) != "Sun")
              input_time -= 24*60*60;
              str_time = format_time( input_time );
         while( str_time.substr(11,2) != "00" )
              input_time -= 60*60;
              str_time = format_time( input_time );
         while( str_time.substr(14,2) != "00")
              str_time = format_time( input_time );
              input_time -= 60;
         while( str_time.substr(17,2) != "00")
              input_time -= 1;
              str_time = format_time( input_time );
         return input_time;
    1) Briefly explain what you think the overall purpose of this function is (do not describe each line of code).
    2) There are two bugs in this code that prevent it from functioning correctly; circle them.
    3) What would actually happen when this code is run?
    (a) as originally written
    (b) with the first bug fixed?
    4) Discuss the efficiency of the code assuming the bugs have been fixed.

    Looks like it is trying to increment the time parameter back to represent midnight of the previous Sunday.

  • Launching Photoshop CC from dock asks for serial number [was:what is this?]

    What is this? I just want to use photoshop on my laptop using the same license I use for my desktop. Please help

    photoshop CC
    Laptop = OSX 10.8.5
    Desktop = OSX 10.8.5
    Launching photoshop from dock. It asks for serial number. I enter serial number copied directly form my account with adobe.
    Error says "This serial number is not valid for Adobe Photoshop CC."
    I'm confused as to why Photoshop worked before on my laptop but now it does not. Did something expire? Do I need a separate serial number for a different computer (ie. my laptop). I don't understand.

  • HT4061 Hello:  My 4S phone went off and I tried to restore it but get a 4014 error code.  What is this code and how can I get it to restore?

    Hello:  My 4s phone turned off and when I tried to restore I got a 4014 error.  What is this error and how do I restore the phone?

    Hello Linda,
    Thank you for the details of the error you are getting when trying to restore your iPhone.  I recommend the steps below for error 4014:
    Error 4000, 4005, 4013, 4014, and 4016
    After you perform each step, try to restore your device.
    Restart your computer.
    Disconnect all your USB devices from your computer and connect to another USB port.
    Use a different USB cable.
    Uninstall third-party security software.
    Try restoring using an alternate computer.
    You can find the full article here:
    iTunes: Specific update-and-restore error messages and advanced troubleshooting
    Thank you for using Apple Support Communities.
    Sheila M.

  • Serial port control

    is it possible to control, using labview, the inputs and the outputs of a serial port as they were simple digital on/off channel?
    for example in order to use them to turn on/off a relay or to read the state of a switch
    I've searched among the labview examples but they show only complex communication to an hardware using strings...
    thankyou in advance
    Go to Solution.

    You can control the handshaking lines Request to Send (RTS) and DTE Ready (DTR).  You can read the handshaking lines DCE Ready (DSR) and Clear to Send (CTS) as digital inputs.
    They are accessed through property nodes of the VISA reference under Serial Settings / Modem Line settings.
    Be careful of any loads you apply to them or signals you enter in terms of voltage and current so you don't fry your computer.
    Message Edited by Ravens Fan on 09-10-2009 04:27 PM
    Example_VI_BD.png ‏2 KB

  • What does this code do

    hi friends, i came across this code, and i am struck at understanding this code,
    usually loop keyword will be followed by itab, but here there is nothing, same with sort.
    some code
    some code
        AT DETAIL.
          / MSEG-LGORT,
          SKIP 1.
          WRITE: 'x y z..'
          SKIP 1.
         WRITE: 'x y z..'
    an some one please explain me this code, little briefly.
    thank you.

    sorry friends, i forgot to tell that the following piece of code was above this code:
    MSEG-WERKS                             "Plant
    MSEG-MATNR                             "Material
    MSEG-MBLNR                             "Material document
    MSEG-ZEILE                             "Material item
    LIPS-VBELN                             "Delivery
    LIPS-POSNR                             "Delivery item
    MSEG-LGORT                             "Storage location
    MSEG-BWART                             "Movement type
    MSEG-MENGE                             "Quantity
    MSEG-SHKZG                             "Debit/credit
    MSEG-MEINS                                                  "UoM

  • TS3694 error 1656, what is this code?

    My iphone decided to run down it's battery and I have spent the past few hours trying to restore using itunes. But the most recent code I got (1656) I cannot find on teh apple code page and have no idea what it is. Can anyone help? Think I am ready to go mad at this point!

    Errors 3000-3999 (3004, 3013, 3014, 3018, 3164, 3194, and so on): Error codes in the 3000 range generally mean that iTunes cannot contact the update server ( on ports 80 or 443.
    Update to the latest version of iTunes.
    Verify the computer's date and time are accurate.
    Check that your security or firewall software is not interfering with ports 80 or 443, or with the server
    Follow Troubleshooting security software. Often, uninstalling third-party security software will resolve these errors.
    An entry in your hosts file may be redirecting requests to (see "Unable to contact the iOS software update server" above).
    Internet proxy settings can cause this issue. If you are using a proxy, try without using one.
    Test restoring while connected to a known-good network.
    Jailbreaking your device can also trigger this error.

  • ADF 10g: What does this code do?

    What is the difference between this and calling createRootApplicationModule() ? I'm looking for some definitive documentation on this.
       FacesContext fc = FacesContext.getCurrentInstance();
                ValueBinding vb = fc.getApplication().createValueBinding("#{data}");
                BindingContext bc = (BindingContext)vb.getValue(fc);
                DCDataControl dc = bc.findDataControl(amName);
                ApplicationModule am = (ApplicationModule)dc.getDataProvider();I understand it (the above code) is no different from picking it from a specific pageDefinition (say where an action binding to a method of that AM is present) or the above -
    both return an AM instance from the data controls within the current FacesContext. But still, any documentation that would relieve this information itch would be much appreciated.
    Also, any thoughts on the 'best practiceness' quotient of doing the above?
    This is posted just to seek clarification - please refer to the whole thread, links provided as references and the developer guide for the recommended approaches.

    posted will grab the one that has been checked out for the page by the binding filter.Here's the thing: this AM, its methods or any of it's constituent VO attributes do NOT have a binding (but could have, since this AM is exposed in the data controls)
    Just note the use of that #{"data"} EL used above (not #{"bindings"} or #{"data.pageDefName"} ).
    In most all cases, you want the same one that has already been checked out - so getting it via the binding context is preferred.Precisely - is there official documentation that confirms that this is a preferred way?
    It is generally pretty rare where you need to createRootApplicationModule,In fact, not at all - except in test code.
    but you might do so in cases where there is not one already checked out for you (for example, if you are interacting with ADF BC from within a servlet).It would be great to have documentation that says it's ok to do so. Otherwise, I strongly think things could be designed better to even avoid doing that.
    Furthermore, it would be even more preferred not to interact with the AM directly in code, but to expose any methods you might want to call via the data control.Method bindings would be 'ideal'. Using the client interface is currently 'ok' (or at least a lesser evil).
    In any new code I wouldn't interact with an AM in UI code - just that there is a whole lot of legacy code which does so. I'm just making sure that the above alternative to createRootApplicationModule is not just equally bad. (i.e. does not require an explicit 'release' call) agree with with the above - and yet get hold of an AM instance via its interface the 'right' way in old code that needs it.
    Thanks for the response.

  • What does this code do? Causing xtra space below Flash

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="538" height="146" id="FlashID4" title="debt solutions">
    I have spaces below every SWF file. But when I remove this - it goes away. (Shows up in FireFox)
    What will happen with this deleted? I don't SEE any visual difference, but not sure what functionality it provides. As always, THanks!

    This is the active-x code required for the flash player in IE, removing it will stop the flash working in the IE browser.

  • What does this code implies pls eloborate

    i need eloboratation on the below code and functionality
    1) nast table entries and functionlaity how it works etc details
    2) function module called and how data is transfering into the table from it
    3) bold codes specially
    call function 'RV_PRICE_PRINT_REFRESH'
                tkomv = tkomv.
      clear komk.
      clear komp.
      clear <b>nast_anzal.</b>      "Clear aux. variable for number of outputs
    <b>  if nast-objky+10(6) ne space.
        vbco3-vbeln = nast-objky+16(10).</b>
        <b>vbco3-vbeln = <i>nast-objky</i>.</b>
      vbco3-mandt = sy-mandt.
    <b>  vbco3-spras = nast-spras.   what is happenign her how the values from nast coming where it is getting populated intitally?
      vbco3-kunde = nast-parnr.
      vbco3-parvw = nast-parvw.</b>
      call function 'RV_BILLING_PRINT_VIEW'
                comwa                        = vbco3
                kopf                         = vbdkr
                pos                          = tvbdpr
                terms_of_payment_not_in_t052 = 1
                error_message                = 5
                others                       = 4.
      if not sy-subrc is initial.
        if sy-subrc = 1.
          syst-msgty = 'I'.
          perform p_update.
    form p_update.
    <b>check xscreen = space.
      call function 'NAST_PROTOCOL_UPDATE'
                msg_arbgb = syst-msgid
                msg_nr    = syst-msgno
                msg_ty    = syst-msgty
                msg_v1    = syst-msgv1
                msg_v2    = syst-msgv2
                msg_v3    = syst-msgv3
                msg_v4    = syst-msgv4
                others    = 1.</b>

    Sorry couldn't see your message,
    Anyways, Baiscally OBJEKY is Document number which uniquely identifies an object (for example, an order). The object key is assigned by the system.
    It is an internal Process.
    For e.g: Purhcase Order or Sales Order.
    Once you Enter Message type in NACE transaction corresponding documents with their message types gets into NAST table.
    Suppose you have P.O. No: 00000001 and if you preview P.O. It will refer entry from NAST table internally as OBJKY: 00000001 whcih is your P.O.
    You can directly write into a Program routine NAST-OBJKY, it will automatically picks up the PO no while previewing or Printing it.
    Now in your case Sales Doc.Access Methods: Key Fields: Document Printing
    vbco3 is the table defined in the same program. Double click to check it.
    You are storing corresponding values from NAST to vbco3 table.
    As you get entire row from NAST referring to your Document.
    'RV_BILLING_PRINT_VIEW': Shows Preview of a document.
    Now if it returns an error it will update the log for NAST that if you want to see the print log can be seen.
    Hope this helps.
    Reward if usegful!

  • What does this code mean?

    private static ThreadLocal serialNum = new ThreadLocal() {
             protected synchronized Object initialValue() {
                 return new Integer(nextSerialNum++);

    That code appears to be cut from this sample code found in the LocalThread javadoc:public class SerialNum
        // The next serial number to be assigned
        private static int nextSerialNum = 0;
        private static ThreadLocal serialNum = new
                protected synchronized Object initialValue()
                    return new Integer(nextSerialNum++);
        public static int get()
            return ((Integer) (serialNum.get())).intValue();
    }The lines you're asking about declare a static ThreadLocal by the name of "serialNum". They assign to it an inline definition (extension) of LocalThread which specifies a custom initialValue() method. That initialValue() method is designed to get its value from the nextSerialNum variable (static, and incremented each time).
    The neat thing that happens with the ThreadLocal instance is in the get() and set() methods. Here you see the get() method being called:return ((Integer) (serialNum.get())).intValue();That get method returns a different object for each thread which calls it. When a new thread comes into the get() method, the initialValue() method is called, creating for that thread a new serial number. When THAT thread calls get() again later, it is given that same serial number.
    This one (static) instance of ThreadLocal can be accessed by any number of threads, but each thread will get()/set() a different variable, specific to that thread. This serial number implementation sets up a very simple counter for the Integer object the various threads will receive. When calling get(), the first thread will always receive an (int)0, the second thread will always receive an (int)1, the third an (int)2, and so on.

Maybe you are looking for

  • How can I use the concept knowed as "MasterPage" with "Content" in JSF ?

    In ASP.NET ( Microsoft .NET ) and in PRADO Framework (PHP) there is concept to separate the portions of page in separate templates. For example, all pages of this site share the same header and footer portions. If we repeatedly put header and footer

  • Creation of GL Accounts

    I am trying to create GL Account centrally in chart of account, am getting error message " No PYCCAL statement account type is defined in chart of accounts YCCA. I have redifined my chart of account gruop to include profit and loss still am still get

  • How to read files from MIT-BIH arrhythmia database using labview

    hello friends, How can i read the files from MIT-BIH arrhythmia database using labview 8.6. These file extensions are in different format ie is .atr, .dat and .hea  The link for the following database is below, any example vi for reading this data in

  • Air File is Damaged

    Hi, Went to start Adobe Acrobat and it won't start, pops up with I need to update Air first. But when you click to update, an error is reported that "the air file is damaged." So I downloaded the latest Air from and ran install, no problems

  • Help With addItem Please

    I have an Array Collection whose source is a node of an XML file such as this individualsArray = event.result.PhoneDirectory.People.Person The XML looks like this <Person FirstN="Jane" LastN="Doe" Sex="F" ACode="312" Phone="466-8300" Dept="New Busine