Serial port: Input/output signal errantly combined

I am currently in the process of using LabView to replace another user interface for a scientific instrument.
LabView is connected to this instrument through a serial port.  The instrument streams 25 bytes of binary data every second to the computer.  I can read the binary string (VISA Read) and save contiuously to disk using a while loop.  In addition, there are a few instructions I can send to the instrument that will do various functions (start logging, turn LEDs on/off, etc).  I can successfully send these instructions to the instrument using the previous interface, and in a stand-alone vi using VISA Write, but when I place the VISA Write function into the larger interface vi, signals go haywire.  Specifically, there are two separate LEDs that I can toggle with two different commands, but when in the larger interface vi, both commands toggle the same LED.  Also, it appears that the singal I send to the instrument (a single ASCII character) immediately bounces back to the computer into the 25 bytes of streaming binary data.  In other words, after I press the LED "on" key, one column of my streaming data changes when it is not supposed to (ex: after Binary to ASCII conversion, it changes from a single digit to a twenty digit value).
Initially, I thought the problem was the sequence of VISA Read/Write.  In the current configuration, I read all data, then allow for Write commands.  Both the VISA functions are within the same While loop to continuously monitor the data.  Is it possible the Write signal output is not leaving the while loop and being read as input?  What would make the instrument read two different commands as the same one?  My goal is to run an interface that displays the streaming data as ASCII, and allows for a few different toggle options while the interface is running - is there are more efficient/elegant way than a while loop?
~Going Bananas
Solved!
Go to Solution.

New replies now in gray.
CodeMunkee wrote:
1.  If you keep giving me good advice like this, I'll be tempted to change the background to Baltimore prison purple.
I'll ignore this statement.
2.  The buffer now lives outside the loop.  I understand clearly.  Part of the problem might be my instrument - when I cycle power the 19 digit number that was 'echoed' disappears.  Forget about that display stuff, it works properly - I accidentally removed the time delay when editing the vi.   But you do bring up an interesting point...
Without the delay, the loop ran much faster.  If the bytes weren't at the port, the read statement would have returned nothing when it read zero bytes, thus blanking out the indicator rather quickly.
Yes, Hexadecimal display shows 04 to indicate the end of the 25-byte data sample.
Doing a bytes at port read is not always a good idea.  If not all the bytes had arrived yet when you ask for the read, you won't get all the data.  The remaining data being sent in that stream from the instrument will show up at the front of the buffer on the next read command. 
While this isn't a common occurence, it does happen.  How can I prevent this from ever happening?
Since you know each commands ends with a hex 04 (ASCII character for EOT), you could enable the termination character when you configure the serial port.  Set the termination character to be 4.  Then when you execute the VISA read, read a large number of bytes such as 25 or more.  The read will terminate at either the timeout, the requested number of bytes, or when the termination character is read.  With this setup, you could eliminate the wait statement and also not request the number of bytes as the port.  The VISA read will control the pacing of the loop.  Any extra bytes after the termination character are part of the next frame of data and will wait around until the next time you read the VISA port.
  3.  Implementing your ideas for the latch button works better.  I am still encountering issues with these commands however.  Attached is the new vi.  There are two commands I want to send, 't' turns on the LED light (they blink for 30 sec then time out), and the latch works perfectly for that, 'p' turns on the magnetometer light (an additional 'p' is required to turn it off), but I cannot get the command sent to the mag while the loop is running.  It turns on either at the beginning of the vi, or at the end of the vi (after Finish button is pressed).  This leads me to think the command 'p' is stuck inside the loop.  I tried adding another film strip (see attached vi) for the toggles to force the issue, but it didn't work. Additionally, the 'p' command effectively works as a 't' command, and the LED lights begin to blink when I press the 'p' button.  This isn't supposed to happen, and leads me to believe the 'p' command does in fact exit the loop but in the wrong manner.
The "film strip" is another frame of a flat sequence structure.  It enforces the order of execution.  The next frame can't execute until everything in the prior frame has completed.  It isn't necessary in your case because the Error and VISA wires determine the order of execution with respect to the other VISA statements.  But it shouldn't hurt.
There is no reason the "p" case structure should behave any differently than the "t" case structure.  Although you should wire the error wire through in the False case of the "p" structure like you did for the "t" structure.  There is no "exiting of the loop" in either case.  The loop runs until the stop button is pressed.  I would check the manual to see that t and p commands do what you think they should do.  Do they need a termination character of their own when they are sent?  Should they be upper case letters rather than lower case?  You can run NI Spy on your serial port and see the operations occurring with it and see the data coming in and what data is going out.  I would be suspicious that the device is not handling the command properly.
Any ideas?  I think I've tried to put the toggle buttons outside the loop before, but then could only toggle once before the loop took over.  Ideally, these toggles would be available at any time while the data is streaming, so therefore inside the loop?
The toggle buttons need to be within the loop so that they can be read on every iteration of the loop.  Outside the loop, as you discovered, they are only read once at the very beginning before the loop is started.
4.  Thank you for the suggestion about the Selection Mode for the Open/Create File option.  It is annoying to create a file first.  I made the change, but I still get error messages when I use a file that does not yet exist.  LabView takes me to the first Open/Create/Replace vi when the error occurs.  Is there something else I must do?
On the open file VI, there is an input that is Open as default when unwired.  Create a constant there and change to Replace or Create.
Remember, if you have any questions about the way LabVIEW is handling something with serial ports, close the port within LabVIEW.  Open Hyperterminal and try the commands from there.
Message Edited by Ravens Fan on 01-13-2009 03:55 PM

Similar Messages

  • Java applets in a browser, and Serial port input

    I know that there is a special package for serial port input in java. (java.Comm.SerialPort)
    What I am trying to figure out before a final decision on design is made, is if there is anyway of reading serial port input into a java applet that is running inside of a browser.
    I have found lots of reference to Serial port input, but nothing that really goes in the direction that I am lookind for.
    Any little tid bits of information pertaining to this would be greatly appreciated.
    Cuervo

    You should also consider that applets are not allowed to access their client system's hardware without being signed; in other words, the user must agree (by clicking a button) to disable the applet security features. Why would you use an applet to do this? Applets are meant to be an extension of a website. You should use an application in this situation.

  • Macbook Pro hardshell with port / input output port protection?

    Dear All,
    This is my first post. Just a recently bought the 2012 Unibody (non-retina) 15" MBP Pro antiglare to replace my aging 2008 black MB.
    Throughout all my months (and perhaps years) of looking at cases, shell cases etc - I find it quite surprising that there's no hardshells out there that also protects the Input / Output / ports on the side as well as the DVD drive entry?
    My 2008 MB has accumulated so much dirt in the input output connectors over the years of use even with reasonable/adequate care, surely there is at least a port protection kit there somewhere on the net that someone has seen before?
    Any help would be greatly appreciated.

    19 views so far and no replies. Maybe no one cared about cleaning and protecting their connector ports after all?

  • Filter serial port input

       Hi All,
    I am sending in a signal from a pic to labview. I am sampling at 480 hz. I can plot it perfectly(i just use a time scaler of 1/480 in the graph) but I'd also like to show three seperate plots... narrowband filter at 0-5 hz, 5-8, and 8 - 30. But I can't seem to implement even a sample filter, I get the message Digital Filter Design Toolkit:  The filter object is invalid. I'm not sure what this is about but this isn't totally necessary to my project but I'm doing EEG waves and separating the signal into three narrowbanded results would be great. Any ideas would be greatly appreciated!
    Attachments:
    usart_and_filter.vi ‏74 KB

    Hi,
    Thanks for your post and I hope your well today.
    Ive noticed you've not received any support thus far.
    I would like to look into this issue tomorrow (when im in the UK office), to see what I can find out.
    Are you still having an issue, an update would be great!
    What version of LabVIEW are you using? and which toolkit are you using - im assuming you have the DFDT toolkit installed.
    Kind Regards,  
    Kind Regards
    James Hillman
    Applications Engineer 2008 to 2009 National Instruments UK & Ireland
    Loughborough University UK - 2006 to 2011
    Remember Kudos those who help!

  • "Example on reading combined signals from a serial port and separating them for display purposes". I am a beginner in Labview and would appreciate if anyone help with that

    I am working on a wireless vital sign monitor. I have 3 signals; heart rate and temperature. I filter and amplify the signals before converting them into digital form. I then pass them via MAX232 before passing them to RS232 serial cable.
    I am therefore working on a program to receive the combined signal and separate them.
    I have come across serial read and write examples on ni.com but am looking for one where I can actually separate combined signals and display them separately.

    Reading the serial port will give you a string. How you divide the channels depends on how the data was formatted before it was sent over the serial channel.
    If you are designing the instrument, as it seems from your query, then you can set up any form you wish. If your data is always floating point numeric, you could use space or tab characters to separate data words. You could use and XML format. If the instrument is provided by a vendor, contact them for the protocol.
    If tabs are used between words and returns between sets of readings, the resutlant string can be interpretted by the Spreadsheet String to Array function in LV.
    Things to avoid are characters often used by serial communications systems as control characters. Carraige returns are
    often used as command terminators by serial protocols, but may also be used by the port.
    Lynn

  • Asserting the RTS signal for serial ports

    I've posted a few times, about asserting the DTR signal line for the serial
    ports.
    To start off with, i have now come to the realization that I was STUPIDLY
    trying to set the wrong thing... I needed to set the RTS, not the DTR!!!
    Most of the replies I got said to use the IN PORT and OUT PORT vi's, from
    the advanced, memory/portI/O palette.
    When i had a fiddle around with these, and looked them up in more depth, I
    found a few things...
    1. I have read a few times, that these are not portable, because of machine
    dependancy... Can anyone tell me how portable they are? Such as, are they
    fine for all Intel based architechure's, or what
    2. I found that if I initialize the serial port, using the Serial Port
    Init.vi, and then use
    the Out Port.vi, to set the RTS, by addressing the
    register at 0x2FC, for COM 2, the next thing I did, which was write to the
    serial port, hung. When I highlighted execution, it was stuck in the Serial
    Write.vi Can anybody tell me what I'm doing wrong?
    Your help would be greatly appreciated!
    Slade Squire
    Programmer
    Rectifier Technologies Pacific
    Melbourne, Australia
    [email protected]

    You should read replies to your posts more carefully since Craig Graham have
    pointed out that VI to use to assert RTS and DTR lines of a serial port. You
    also should search this group for the RS485 and RTS/DTR topic; it is a
    recurrent question and there are some pitfalls on toggling RS485 direction
    in LabVIEW.
    As for RTS flow control, you will see something only when the input buffer
    of the serial port is full, in which case RTS is asserted to signal the
    transmitter to pause transmission.
    Jean-Pierre Drolet
    "Slade Squire" a �crit dans le message de news:
    [email protected]...
    > Something else I forgot to mention....
    >
    > When I try and set RTS in the flow control parameter of Serial Port
    Init.vi,
    > it doesn't do anything!
    > Why?
    > (I know it doesn't do anything, because I have an oscilliscope set up on
    the
    > end of the com cable, wired to the RTS pin)
    >
    > "Slade Squire" wrote in message
    > news:[email protected]...
    > > I've posted a few times, about asserting the DTR signal line for the
    > serial
    > > ports.
    > > To start off with, i have now come to the realization that I was
    STUPIDLY
    > > trying to set the wrong thing... I needed to set the RTS, not the
    DTR!!!
    > >
    > > Most of the replies I got said to use the IN PORT and OUT PORT vi's,
    from
    > > the advanced, memory/portI/O palette.
    > >
    > > When i had a fiddle around with these, and looked them up in more depth,
    I
    > > found a few things...
    > >
    > > 1. I have read a few times, that these are not portable, because of
    > machine
    > > dependancy... Can anyone tell me how portable they are? Such as, are
    they
    > > fine for all Intel based architechure's, or what
    > >
    > > 2. I found that if I initialize the serial port, using the Serial Port
    > > Init.vi, and then use the Out Port.vi, to set the RTS, by addressing the
    > > register at 0x2FC, for COM 2, the next thing I did, which was write to
    the
    > > serial port, hung. When I highlighted execution, it was stuck in the
    > Serial
    > > Write.vi Can anybody tell me what I'm doing wrong?
    > >
    > > Your help would be greatly appreciated!
    > >
    > > --
    > > Slade Squire
    > > Programmer
    > > Rectifier Technologies Pacific
    > > Melbourne, Australia
    > > [email protected]
    > >
    > >
    > >
    >
    >
    LabVIEW, C'est LabVIEW

  • How to get a signal from the serial port to start a labview program?

    I need to synchronize the data obtained from a program (which is not in Labview)with the data collected with Labview on a different computer. I can send some data strings to the serial port of the computer running the Labview program when the other program starts. However, I need to be able to read the trigger in my Labview program. Do you know what I should do? Thanks.

    If you don't have any other programs listening on the COM port, you need to let a LV program run BEFORE the signal comes, otherwise you won't be able to read it. You can have the program wait in a slow timed loop so that it doesn't use up too much CPU time, and when the required "trigger" comes, to move into the main part of the program.
    You basically need a while loop waiting for a certain string in the serial buffer. Once the string is found the while loop is exited, and the data acqquisition or whatever else you require from the progam can be performed.
    In the example attached the program wait for ANY text to be sent to the COM port. Please note that you need to configure the VISA resource before using it. Once there is something at the COM port, the loop will exit and the rest of the program will be executed.
    Hope this helps
    Shane
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
    Attachments:
    Wait for serisl message.vi ‏17 KB

  • Send signal to serial port

    Hi, I have a trouble.
    I need to send a signal to serial port to pilot a relè.
    I can't find how to send a Vcc signal for some second on a pin in java.
    Someone have an idea?
    Thanks a lot!
    Edited by: Alberto.Marcigaglia on Aug 29, 2008 2:27 AM

    There are many results from the search below:
    http://www.google.com/search?q=java+serial+port
    I suggest that you use the 3-rd party RXTX package rather than the obsolete javax.comm package. There are a number of very detailled posts in these Sun forums regarding the installation and use of RXTX - search for them.

  • How to create 2 output signal locked in phase from a one input signal

    Hi all,
    I have a case in which I want read in a signal analog input (voltage) from a photodiode, I want to create a 2 sinewave signal locked in with same phase as the input signal and output them as analog output to my 2 laser diode. the frequency of the input signal is low aroud 15 Hz , the 2 output signal i want to be  around 120 hz and 150 hz . 
    I am using USB - 6003 daq card.
    I have created a vi to see the input signal but I dnt know how to create 2 signal from the waveform generator locked in the phase as the input signal. I have seen a PLL vi , but dont know how to use that with my program.
    can any one tell me how to proceed.
    thanks
    AG
    Attachments:
    pulse_PLL.vi ‏27 KB

    Hi AnkitG,
    Here are a couple of links that might help you understand a little more how the PLL work and a way to synchronize the task to perform a PLL.
    http://digital.ni.com/public.nsf/allkb/07BC8D77D4E9AE258625708B007CE74F?OpenDocument
    http://digital.ni.com/public.nsf/allkb/2F675A9F2162EA24862572570059A308?OpenDocument
    Also, you should be able to find a lot of examples on how to accomplish the synchronization of tasks on the community, if you consider that the only consideration is that both must start at the same moment. 
    I hope, these examples might show you some useful concepts:
    http://digital.ni.com/public.nsf/allkb/EBD603683446EC13862575B3006A63A2
    http://digital.ni.com/public.nsf/allkb/9E71F8D7D3CD1B0886257688004AE353
    Regards,
    Luis C.
    National Instruments

  • Using two ports or Using two Input / Outputs

    I'm explaining my project. It s almost done. I send message and data to server and it is stored in server. From the begining I'm using
    BufferedReader - PrintWriterAnd I cannot send files because they are binary. I have to use
    BufferedInputStream - BufferedOutputStreamI cannot change my input / output. So I found two solutions:
    1) Connecting from another port with another socket. -> Using this it blames the ports. I cannot transfer anything from my first port.
    2) Using another input / output streams from the same port. -> I didn't tried it . Does anyone tried this. Is it possible to do this.
    That's the end of my project. I will give the name of project who gives me a good answer :D
    Best Regards, Bulent.

    I cannot change my input / output. Why not?
    So I found two solutions:
    1) Connecting from another port with another
    er socket. -> Using this it blames the ports. I
    cannot transfer anything from my first port.Huh? Unless the server stops you, there is nothing in sockets that prevents you, as a client, from connecting to the server twice.
    2) Using another input / output streams from the
    he same port. -> I didn't tried it . Does anyone
    tried this. Is it possible to do this. Nothing stops you from using an InputStream to create two different buffered solutions.
    I wouldn't even attempt this myself. It would create a very fragile application. But you could try it. You would need to carefully control when the two connections were used and in particular when they were closed. You could do this by wrapping both in a class.

  • Start a program with a signal from serial port

    Hi, my program need to continue when it's gets a signal from the
    serial port, I've understand that i need to use Java Communications 3.0 API.
    couldn't install it.
    when i import, in my program, javax.comm.* it can't be resolve.
    thank for eny help..:-)

    Glad you got it to work. I would only say 2 very important things:
    1) Do not use an IDE as long as you can't code using notepad and command console and don't understand the concept "classpath". Now you've to learn both the IDE and the Java language basics. This is going to take a longer time than when you learn it one by one.
    2) You should NEVER place any 3rd party libraries in JRE/lib or JDK/bin. This is receipt for major future troubles. You should define the classpath yourself. You shouldn't misuse the default classpath.

  • Detect input signs at serial port

    Hello,
    It is posible using Lingo detect input signs at computer serial port??
    Thanks for your help

    This is certainly possible - check the Mile High Table for xtras that can help with serial communication

  • Signal at Serial Port

    Hello,
    I am receiving signal at the serial port through wireless communicator at a baud rate of 9600. I want to analyze this signal and for that i need to know that what sampling frequency i should use and what is its relation with the baud rate.
    Thanks alot

    Abuzar,
    The sampling rate for your signal is the rate at which the digitizer in the microcontroller takes samples.  If you are trying to get a good reprodcution of the waveform, the sampling rate is probably 300 to 1000 Hz.  If you are anywhere near 1000 Hz sampling, you will not be able to transmit all the data through your 9600 baud link (~ 1 ms per byte).
    Lynn

  • My input/output port is no longer functioning. After hitting the proper buttons in the System Requirements/Sound, it still does not function.

    After having my MacBook Pro for just less than a year, the input/output port is suddenly not functioning. Even after clicking the correct buttons in the System Requirements/Sound section, I cannot record through the input and listen through the output modes.

    Hi Tim,
    Your MBP has a one year hardware warranty on it, so I would contact AppleCare or go in to an Apple Store.

  • How can I use the output value from SIMPLE PID to write something to the serial port?

    I am working on my Senior Design Project that requires the use of incoming compressed air, propotional valves, continuous servo motors, and a serial servo motor microcontroller.  I have figured out how to send byte sequences to the microcontroller through LabVIEW using the VISA serial write function.  The motors are attached to the valves to control the flow rate.  I have created my own simple feedback system using a bunch of case structures but I realized that I am basically trying to recreate the wheel (I basically was writing my own PID VI).   I have an older version of LabVIEW (7.0 Express) and theres no way to upgrade or buy the PID toolkit, so I am stuck using the Simple PID VI.  Also, the only way the motor works is sending an array of bytes to tell it to turn on/off, direction, and speed.  Is there any way I can use the Simple PID VI in conjunction with the VISA SERIAL write function, or is there any other way I can communicate with the serial port using this pid vi?  Any information would be appreciated.

    Hi gpatel,
    you know how to communicate to serial port, but you don't know how to send a value from SimplePID to serial port???
    You know how to communicate, but then you don't know how to communicate???
    You should explain this in more detail...
    Edit:
    From you first post you know what values your motor driver is expecting. You know which values the PID.vi is providing. Now all you need is a formula to reshape the values from PID to the motor. It's up to you to make such a formula. Unless you provide any details we cannot give more precise answers...
    Message Edited by GerdW on 02-28-2010 08:35 PM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

Maybe you are looking for