Serial port control

hello
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
paolo
Solved!
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
Attachments:
Example_VI_BD.png ‏2 KB

Similar Messages

  • 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!
    Sincerely,
    Curtis Osterhoudt
    Attachments:
    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
    Ben Rayner
    Certified LabVIEW Developer
    www.DSAutomation.com
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to take CameraLink serial port into use in VC6+MFC?

    I'm trying to use the CameraLink serial port.
    Developing environment is VC6 + MFC.
    Serial port controlling functions reside in CLSERNAT.DLL. clsernat.h is included in the project.
    Following code is used for accessing tjhe functions in DLL.
    --snip------------
    HINSTANCE hLib=LoadLibrary("CLSERNAT.DLL");
    &clSerialClose = GetProcAddress((HMODULE)hLib,"clSerialClose");
    --snip------------
    The compiling gives this error:
    error C2440: '=' : cannot convert from 'int(__stdcall *)(void)' to 'void (__cdecl *)(void *)'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    How the type casting should be made?
    Thanks!

    Hi Hannu
    I'm a C++Builder programmer, the borland's c++ syntax is quite diferent but I think I can help you.
    1- You could import the file CLSERNAT.lib in your project (in the VC enviroment), in this way you don't have to load the library yourself and you can use the funtion in your source code.
    2- If you have to load the library yourself define pointer to the function in the DLL
    typedef void __stdcall (*TFunctionInDll)(void*);
    Load the Dll:
    int IdentDLL = (int)LoadLibrary("CLSERNAT.DLL");
    do the typecast
    TFunctionInDll FunctionInDll= (TFunctionInDll)GetProcAddress((HINSTANCE)IdentLib,"clSerialCLose");
    and call the function the usual way
    FunctionInDll(NULL);
    The typedef definition must be with the same parameters of the function in the
    dll.

  • Control a generator with a control volage by serial port RS232

    Hello everybody,
    I would like to control a generator thanks to a control voltage. This last one would be sent to a switch wich turns on the generator.
    To do that, I want to link the switch and the computer with a serial port RS232 by using NI-USN 232 cable.
    I made some research on this subject and I am only a beginner on LabView but I would like to use one (or several) pin which will send 5V in voltage when I want.
    Is that possible? Is there another way to make it?
    Thanks in advance.

    Thank you for your answer.
    Maybe, I didn't explain myself correctly. 
    For example, on the Raspberry Pi, you can control a card by sending 3,3V signal with RS232 port (I made it last year so it makes a sense).
    What I want to do here is to control an electronic card that turns on my generator after. I don't have enough to buy a generator controlled unless you know one not very expensive.

  • Motion Control via Serial Port

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

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

  • Low level control of serial port?

    Hi there,
    We're using LabVIEW 7.1 and I would like to control some low level aspects of the serial port (I'm having a LOT of difficulty connecting to an ABU93 autoburette). Is there a way to set the DTR, DTS RTS and CTS in LabVIEW 7.1? Is this controllable through VISA?
    Thanks for any help,
    Russ

    The serial lines cannot be adressed using the Configure serial port VI. You need to dig a little deeper, and access the modem property node.
    See the attached vi.
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Serial line settings.vi ‏35 KB

  • How to add control buttons using Java thorugh serial port?

    Hi everyone,
    I'm new to this forum.
    I have some questions on Java and serial port.
    I want to write a Java program to control my robot, through serial port. For example, when I click "Forward", the robot will go forward, and so on.
    Now I already have the buttons, so next I would like to ask how to interface the buttons with the serial port.
    I already have all the javax.comm things installed.
    below is the code for my buttons:
    import java.awt.*;
    public class ControlButtons extends java.applet.Applet
         GridLayout myLayout = new GridLayout(3, 3);
         Button button1 = new Button(" ");
         Button buttonForward = new Button("Forward");
         Button button2 = new Button(" ");
         Button buttonLeft = new Button("Left");
         Button buttonStop = new Button("Stop");
         Button buttonRight = new Button("Right");
         Button button3 = new Button(" ");
         Button buttonReverse = new Button("Reverse");
         Button button4 = new Button(" ");
         public void init()
              setLayout(myLayout);
              add(button1);
              button1.setVisible(false);
              add(buttonForward);
              add(button2);
              button2.setVisible(false);
              add(buttonLeft);
              add(buttonStop);
              add(buttonRight);
              add(button3);
              button3.setVisible(false);
              add(buttonReverse);
              add(button4);
              button4.setVisible(false);
    }Now I would like to ask for direction on how to add in the code to make it work with serial port.
    Thanks

    The plan is, I have a robot device connected to the serial port.We don't know anything about that device. We don't know how to control it. We don't know what you have to write to the device to make it do anything. Only you know what.
    For example, when I click "Forward", the robot will go forward, and so on.So what do you have to send to make it do that? and same for the other buttons.
    Next, you need to work out from the javax.comm API how to open the serial port and send data to it. This is a standard exercise in learning a new API. You must be able to do this. Again and again.
    But the program is useless. The button can be clicked, but didn't do anything.Because (a) they have no ActionListeners and (b) there is no code to send anything to the serial port.
    You have to write all that. So you also have to look up ActionListener in the Java API and how to attach it to a button. You can do that. We all do that kind of thing every day.
    So next I would like to ask how to interface the buttons with the serial port.You've been asking nothing else since you started, but you've also only done enough investigation of your own to create the buttons. That's only the start.
    The problem is what method and command should I use to make those buttons actually functioning.See above. You've been told part of it several times. The rest only you can answer, because it's your robot.

  • How can I control a HP 33120A waveform generator with the serial port of my PC?

    Hello,
    I want to control a HP 33120A waveform generator with my PC using the serial port. I don't have any idea about how to do it. If you've done it or if you know how I can do it, please give me some indications.
    Thanks
    Jean-Baptiste Paillet
    PS: I don`t have G PIB port

    The answer to your cross-post in the LabVIEW General group seems to be right on the money:
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=50650000000800000032200000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0
    Regards,
    John Lum
    National Instruments

  • Control Camera Attibutes through serial port using VISA commands

    Hi there,
    I'm using a Basler acA2000-340kc camera through an PCIe-1473R FPGA as frame grabber.
    I would like to be able to configure the camera through the serial port just in LabView, not using a third-party as Pylon (which I can do now).
    According to this forum post 
    http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/My-Basler-acA2040-180km-NIR-is-not-visible-in...
    this is possible just taking the VI posted here
    https://decibel.ni.com/content/docs/DOC-5049
    and converting from IMAQ to VISA, as RIO frame grabbers cannot use IMAQ. I have been trying to do this by changing the IMAQ vi to their VISA equivalents, but I have no good results.
    Does anyone know which are the steps to go from that piece of code to one that can be used to control the camera in my case?
    Thanks a lot,

    Hi i.popa,
    Basler makes the Basler Binary Protocol Library for serial communication with their cameras. If you make sure you're running the serial server section of your FPGA code to keep the serial port open, you should be able to use calls from this library to communicate with your camera. We have a community example with more information on using the Call Library Function Node to call a DLL. This DLL will take care of all the processes needed to write from and read to the registry, so this implementation will probably be similar to the example program you listed above, using calls to this library instead of the IMAQ Serial functions.
    Good luck with your application!
    Emily C
    Applications Engineer
    National Instruments

  • How to control an Xserve G4 with the serial port

    I have an Xserve G4 first generation, and was wondering exactly how you would go about connecting to it via serial port incase I need to change something when there is a network issue. I have looked around the internet without much success. It has Leopard Server on it, so Apple says the baud rate is 56700, and 8bit, no parity. So that's all set in the client machine, which is a MacBook Pro with a USB to Serial adapter on it, which shows up in Zterm. Once I'm in Zterm, it just sits there, and pressing enter doesn't prompt a log in. Does anyone see what else I'm most likely missing?
    Thanks

    Thanks for the reply Cemelot. Yes, I did create a profile in ZTerm. This is what I have it set to.
    I also read that you're supposed to run the command "/usr/libexec/getty serial.57600 /dev/tty.serial" on the Xserve itself.  It made no difference if I did that or not. I also checked to make sure tty.serial was inside /dev/. Anything else I'm missing? Thanks again.

  • Controlled reading from serial port

    I'm trying to establish a connection to an external device through the serial port. This is done in a while-loop which sends an association request tries to get a response if a response is not recieved a new rewuest is sent, etc. At the moment this procedure does not work. I am considering two explanations for this. The first is that the loop does not wait long enough for a response to come and simply keeps pumping out requests, the other is that there is something wrong with the reading algorithm, that doesn't let it properly take in information from the serial port.
    Solved!
    Go to Solution.
    Attachments:
    association_loop.GIF ‏5 KB
    read_visa.GIF ‏8 KB

    I made a new version of the read case. The old version was a while loop, the new version is a while loop which will go on until it encounters an EOF character. In this case it is
    0xC1 or 'Á'. I thought the old version would break before getting any message. This doesnt get any signal either. I have probed it, and it doesn't get a string from which to take the length.
    Attachments:
    read_visa2.GIF ‏10 KB

  • How do I process serial port strings as bits

    In response to my commands, my instrument is sending bytes to my serial
    port. In one instance, 2 bytes are received. I want to treat these 2 bytes
    as a group of 16 bits.
    The VISA and Compatibility Serial functions return these bytes from the
    serial port to Labview clearly labelled a "string".
    Everything I can find in the way of Labview functions and .vis don't want to
    do bit twiddling, bit swapping, and bit dropping, with "string" data.
    I thought "hex string to number" could be used here, but I can't find a way.
    The 2 Bytes in question can be represented as hex, but the data are not the
    ASCII codes for the hex representation of a binary number, they are the
    binary number. This "hex string to number" seems to want ASCII c
    odes.
    You can feed a hex number typed into a "control" box wired into "hex string
    to number" and you get a meaningful number. You can feed the 2 bytes from
    the serial port into an "indicator" set to read in hex and you get a hex
    number that is a correct representation. But that is Labview handing them
    around to itself. I need to get my "hands" on them.
    I can't feed those same bytes that show up as a correct hex representation
    in an indicator into the "hex string to number" or anything else, so far,
    and get a number that is useful for further processing.
    I thought "variant to data", but I can't find enough reference material to
    understand how to use it. A boolean array seems like a bit of a weird
    approach, so I thought I'd ask before I looked into that.
    I'm used to dealing directly with binary numbers on the processor stack, I
    call them whatever I want, and turn them into anything I feel like.
    I'm sure I'm staring the solution in the face, but I can't find any way to
    persuade
    Labview to treat this "string" data as 16 bits.
    I've got the 16 bits, which is better than not having them, but I don't have
    much hair left.

    duh, well I finally discovered the "Unflatten from String" function. A guy
    just feeds in the bytes he's collected from his serial port that Labview
    thinks are a "string", and out come lovely little unsigned 16 bit numbers,
    or whatever other type of number he wants to turn the bytes into. And there
    are great little bit twiddlers available after that, like "swap bytes", and
    you can mask out bits with the logic operators, why this is fun. There's
    nothing like being a moron...... fly me to the moon...................
    "David Lewis" wrote in message
    news:[email protected]..
    > The two bytes would come from a serial port read.vi in Labview, classed as
    a
    > string. For instance, D3 and 02. The output wou
    ld swap the two bytes,
    i.e.
    > to 02 and D3, consider the two swapped bytes as 16 bits, drop the six most
    > significant bits, and output the ten bits that are left as an integer
    > classed by Labview as some kind of number, not a string.
    >
    > Your example StringToBits_Converter.vi I found on the ni.com site
    > unfortunately gives an error message and refuses to open on my system
    saying
    > it comes from a newer version of Labview 6 than I am running. Mine says
    > 6.0.1b3. Thank you very much anyway.
    >
    > "FightOnSCTrojan" wrote in message
    > news:[email protected]..
    > > In another words, you want to create a VI in which the input is 2
    > > strings (i.e. AB) and the output is the converted array bits (e.g.
    > > 1010101010101010)?
    >
    >

  • 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

  • "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

  • Help with reading information coming from a software into LabVIEW through Serial port

    Hi,
    I am new to LabVIEW and also an amateur in using RS232 for communication. I have this software that has these icons like speed increase/decrease, elevation up/down, start/stop. Now, when I click these buttons on the software, they perform the appropriate functions. For example, if I press start button, the signal must go through a serial COM port into LabVIEW to start the machine. How do I do that? How do I find what format the code word is when I press a button on the software? And how to decode the information to read whether the button pushed is start etc...? Any help would be appreciated.

    I may not be perfect, but I'm all I got!

    That information would be in the programming manual for the device you're controlling. Unless you have a device that has no documentation or you cannot get the documentation that's the first place you should look. If you cannot get the documentation at all then you've got some reverse-engineering to do. To do this you will either need a serial port sniffer (a hardware device), or you can try to use a software-based port capturing program. On Windows PortMon is the most prevalent. This will show you how the port was configured (baud rate, stop bits, etc). Warning: the information is technical.
    As far as how to get it running in LabVIEW, you should take a look at the serial port communication examples that ship with LabVIEW. The most problems occur in figuring out how to (a) terminate a write command, and (b) determining when to stop reading. For (a) this is typically done by appending a carriage return or linefeed to the command. This is device dependent. For (b) this is usually done by the byte stream ending with a character like a linefeed. Again, this is device-dependent. 
    You may also want to peruse this KB article: Serial Instrument Control Tutorial. There are also lots of tutorial on the internet for basic tutorials on serial port communication.

Maybe you are looking for

  • Advantages of using grub2

    What are the advantages of using grub2 over just grub? Why would I want to upgrade?

  • How can resources be emebedded in pdf file?

    in the Acro3DJS.pdf, exist 2 information 1) "Resource Objects Some objects, such as Image, are driven by content that is streamed from a file or over a network. To create an Image, load a .png, jpg, or .gif file as a Resource, which you may subsequen

  • Alerts management

    Hi All, How to use this Alerts management? When this will be used? Will this send an e-mail to the users ? Regards,

  • Getting the text of a Label from an inputField

    Hello everyone, In my application, I have an inputField and a Label. The labelFor property of the Label directs to the inputField. How can I get the text of the label from the inputField ? Any suggestions ? Thanks. Ruthie.

  • Manually entered contacts disappear from iphone

    Any contact (phone number) that I manuall enter on my IPhone disappears. Is it being wiped out by some mailbox that syncing? How do I stop it from happening?