Writing bytes to serial port in each iteration of loop

Hello everyone,
                  Well I am new to labview, my question might of beginner's level but i have searched the forums and didnt find content regarding it. Kindly help me through it as i am really stuck in it for last three days. 
                  I have to make a packet of bytes in each iteration depending upon the bytes i get from array which is input to for loop. Taking five bytes and then making packet according to protocol. Once packet is made i have to send it to serial port in the same iteration. So for each iteration i have to send packet to serial port. I have tried the shift registers, local variables, and also the autoindexing which returns the array at the end of loop. But these things dont solve my problem. Kindly help me solvng this issue.
Many many thanks in advance
Engr. Yasir Amin 

First of all thanks alot for your reply.
                         The problem is that i have made separate subVI for this protocol stuffing and the output of that subVI is attatched to the serial visa write in another main  VI in which i am using this VI. I have sent parameters to subVI which makes the packet and then send the output, the output is then sent to visa serial write. Actually that visa serial write is common to many subVIs, On the interface its user's choice to select the request he wants to send. The based on the request the particular subVI is chosen and then that subVI generates the string which is in main VI. which is written to serial port. All other subVis are working fine becoz they dont have loop they simply make the string and send it to port. But this subVi with the loop has the problem as it sends only the last iteration string to port.
I cant post the code as i am using my laptop in my room and the code is in office laptop But tomorrow i can share it from office
Thanks
Yasir

Similar Messages

  • 0 bytes at serial port after Visa Write

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

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

  • Bytes at serial port returns allways zero value

    hello, in my code don't works Bytes At Port as I'm expexting. Program receieves data normally, but Bytes At Port return allways zero.
    2nd problem: It is possible to use VISA Read in both of parallel loops ? Purpose of my first loop is sending commads and I want to evaluate synchronous answers imediatly in this loop. Second loop receieves and evaluates asynchronous data flowing from the measurement device when measurement is acitivated.
    Thanks.

    You're sort of answering your first question with your second question. In the first loop the Bytes at Port is meaningless, unless you are intending to use it to perform a read in there. However, since you're reading in the second loop (incorrectly, by the way - more on that later), then there's nothing in the buffer, so you'll get zero.
    You can read in as many places as you want. Whether or not it makes sense to do is a different story. It depends on how the data is coming over the serial port. If the instrument you're talking to is sending data continuously, but "sneaks" in a response to a command between two messages, then you obviously don't want to be reading the response to the command in your second loop. The serial port is just one pipe. It's up to you to determine where the data belongs. Furthermore, you can't be guaranteed of getting all of the bytes at once, which means you might read, say, part of the "asynchronous" message, then get the rest in the next iteration as well as the responsed to a command you sent. As far as the Bytes At Port is concerned, it just sees a bunch of bytes. It doesn't know that, for example, the first 2 are the remainder of the asynchronous message, and the rest are the response to the command. Does the instrument not have something in the communication protocol to  allow you to distinguish?
    As promised, the way you're doing the read: You are setting up the configure VI to disable the termination character, yet you are wiring a termination character. Which is it? Do you want the read to stop at the termination character, or not? If you don't use a termination character, then you need to use Bytes At Port so you know how many bytes to read. You have that property node in the second loop, but you are not using it. Instead you are wiring a constant of 1000 to the VISA Read. This will only work if you have termination enabled. But you don't. See the problem?

  • Java program to receive byte from serial port

    hello everyone, i am recently working one a project which require communication between pic16f877 and PC. My pic continuiously measure a voltage and send the result (a byte ranging from 0 to 255) to the rs232 port. One the pc side, my java program keep reading the serial port and it works for values 0~127 and 160~255. But if the byte value is between 127 and 160, it cannot received correctly, i get something like 375,8224,or even 65532 etc(no obvious path but more likely to be 300+,700+,8000+ or 65500+). I have been trying very hard to solve this and i think the problem is due to the pc software. I am feeling so frustrated and any suggestion will be much appreciated.
    p.s. : i used Bufferedreader.read() in my program
    --mengyao                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    fumengyao wrote:
    hello everyone, i am recently working one a project which require communication between pic16f877 and PC. My pic continuiously measure a voltage and send the result (a byte ranging from 0 to 255) to the rs232 port. One the pc side, my java program keep reading the serial port and it works for values 0~127 and 160~255. But if the byte value is between 127 and 160, it cannot received correctly, i get something like 375,8224,or even 65532 etc(no obvious path but more likely to be 300+,700+,8000+ or 65500+). I have been trying very hard to solve this and i think the problem is due to the pc software. I am feeling so frustrated and any suggestion will be much appreciated.
    p.s. : i used Bufferedreader.read() in my program
    --mengyaothis may not matter in your case - but don't use a Reader, use a Stream (BufferedInputStream maybe)

  • How to display raw, not ascii, bytes from serial port?

    Hello, I have an instrument that outputs raw data, not ascii, bytes to a serial port.  How do you display raw data, not ascii, bytes from a serial port?  Since raw data bytes are not displayable, there is got to be something in labview to interpret/display the received bytes the way it is as data in HEX or Binary.  The STRING-TO-HEX and STRING-TO-BINARY functions are not applicable in this case because the bytes were not string type in the first place.  For example, if the receive byte is 0x4D, I need to display 4D in HEX or 77 in Decimal and not the ascii character "M" corresponding to 0x4D ascii code.  I am using a VISA-RD function currently to receive the data from a COM port.  VISA-RD outputs string type.  Thank for any feedback or suggestion in advance.

    BC@Baxter wrote:
    ...The STRING-TO-HEX and STRING-TO-BINARY functions are not applicable in this case because the bytes were not string type in the first place...
    Of course they are string type, just not formatted in a human readable form. So, YES, these functions are not appropriate.
    BC@Baxter wrote:
    For example, if the receive byte is 0x4D, I need to display 4D in HEX or 77 in Decimal and not the ascii character "M" corresponding to 0x4D ascii code. 
    Dennis is right, but there is no "decimal" display for strings, so the second requirement needs a tiny little bit more code.
    If you have a single byte string, you can typecast it into a U8 number and set the display format as decimal, hex, octal, or binary as desired. In decimal, it would display the number 77. Since it is now a numeric, you can even do math with it.
    In general, the string has multiple bytes, and you would typecast it into an array of U8 numbers (Since this is an often used function, there is also a "string to byte array" which does the same thing).
    Typecasting is the secret. You can e.g. easily typecast 2 bytes into a U16, 4 bytes into a I32, 8 bytes into a DBL,  etc. For more detailed requirements, there is also the "unflatten from string". Check the online help for details. Good luck!
    LabVIEW Champion . Do more with less code and in less time .

  • Bytes at serial port are unreadable?

    I am trying to communicate to an Omega HH42 Digital Thermometer. I receive Bytes at the port but they do not show up in the display. I have tried the codes disply, Hex etc..... Has anyone seen this before? I am not new to serial communication but this has me stumped.

    Hey Carl,
    I'm trying to serially communicate with the HH42 as well.
    Do you still know what combination of timing and termination characters that you had to use to read temperature?
    Thanks

  • Closing a serial port after executing a for loop of write and reads.

    Hello,
    Labview is opening and then closing each write to the port. I have tried to leave the close outside of the for loop, but labview wont allow it. What do I need to change to make all the writes and reads execute on 1 open and close of the serial port.?
    Thanks.
    Attachments:
    Controller.vi ‏27 KB

    J_es--
         The program that you posted looks to be ok for the most part, you might consider putting an open after your configure (but that's trivial). The other thing that is a minor issue is the loop tunnel coming out of your for loop is currently being auto-indexed.  This function is used to index data for each interation of the loop.  You are using a static address (not an array) and so you don't need this.  If you right-click and remove the auto-index the broken wire will go away. Other than that it should be ok.
         I would suggest looking at one of the shipping examples that come with LabVIEW.  "Basic Serial Read and Write" is essentially the same thing that you are doing and is tested here and might save you a bit of time.  Anyway, take a look if you have a second. Best of luck with your application!
    John H.
    Applications Engineer
    National Instruments
    http://www.ni.com/support

  • Writing to serial port 1 from a PDA

    ok this program is driving me NUTS! i have this microchip which uses a certain protocol... now this protocol requires that you send it some characters in hexadecimal so it'll reset... afterwhich it'll send you a data packet containing the version of the microchip etc etc (it's an aduc812... which you can find on www.analog.com)... anyway, that's not important... i am having trouble actually WRITING to serial port 1... i noticed that doing it through an actual PC requires some sort of "open serial port.vi" which is not available in the pda version... all i have is init.vi which is apparently not enough from what i am told... i thas to be opened first... initialized next... then written to then read from... does anyone know how i can acc
    omplish this open procedure with the pda module? is that some sort of software i'm missing? why isn't it included with the pda module add on... etc etc... thank you in advance... i really need help with this so as much information as possible would be appreciated... let me know if you need further info...
    christina

    Hey Christina,
    Here is a link to a knowledge base one simply writing to the serial port from a PDA.
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=E011F478861443EFE034080020E74861&p_node=%20DZ52363&p_source=External
    Hope this helps.
    Brett

  • Can not access serial port while upgrading from LabVIEW 6.1 to 7.0

    Hi,
    I built an application under LabVIEW 6.0.2. few years ago. This application uses LabVIEW serial features. When I upgraded to LabVIEW 6.1, my application was still working correctly.
    Today, I upgraded to LabVIEW 7.0, mass compile all VIs and now my application can not communicate with my peripheral !!!
    The program is sending the command to the peripheral. The peripheral answers but LabVIEW serial driver does not see any datas on buffer even if datas are available ... "Bytes At serial port.vi" always returns 0. I am sure that datas are available, using a COM port psy.
    Does anyone has an idea?
    I saw a lot of solutions in the forum, but I would like to know the best solution with minimum work, te
    st, and so on ... on my program.
    Regards,
    Pascal.

    Hi Pascal,
    Which is your version of NI-VISA?
    Please see the link bellow :
    http://digital.ni.com/manuals.nsf/websearch/E8D86CD680B0753D86256D2C005D8EA0
    The first test to be made is to test the communication with your serial port using MAX (Measurement and Automation Explorer) :
    Open MAX, Go to "Devices and Interfaces", then "Ports", select COM1 (or ASRL1::INSTR). Right clic on it and select "Open VISA Session" the go the "Basic I/O" then Write data, execute, Read data, execute.
    Be sure that the communication is OK. Be sure that you use the same Alias existing in MAX in your LabVIEW program.
    Now, if all is OK, try to use Serial communication examples existing in LabVIEW Help>>Examples Finder. These examples use NI-VISA VIs.
    If all above is OK and you
    still have the same problem, try to follow these instructions :
    "In order to use the old Serial Compatibility VIs in LabVIEW 7.x, you must copy the following files from a previous version of LabVIEW to the LabVIEW 7.x directory:
    Replace the serial.llb in LabVIEW 7.x with the serial.llb from a previous version of LabVIEW. This file is found in C:\Program Files\National Instruments\LabVIEW\vi.lib\instr.
    Replace the _sersup.llb file in LabVIEW 7.x with the _sersup.llb from a previous version of LabVIEW. In LabVIEW 6i and 6.1 this file is located in C:\Program Files\National Instruments\LabVIEW\vi.lib\platform. In LabVIEW 7.x (and 5.x) this file is found in C:\Program Files\National Instruments\LabVIEW\vi.lib\instr.
    Copy the file serpdrv to the C:\Program Files\National Instruments\LabVIEW 7.x directory. This file is not installed with LabVIEW 7.x, so it only needs to be copied from a previous version of LabVIEW, not replaced."
    I hope that my answer will help you.
    Sa
    naa T
    National Instruments

  • Serial port vi taking too much time to communicate?

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

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

  • Not correctly reading serial port data after first cycle

    I set up a VI for serial communication using RS232 with a pressure transducer meter. The pressure readings are in a loop along with a series of calculations in that loop. The readout from the first cycle is correct, but i just see garbage characters on every subsequent cycle. The VI was running fine when the loop was just reading the pressure data and not performing any calculations. What could be the reason for this discrepancy.
    The OS is windows NT and software is Labview 6.1
    Thanks

    Thanks for your response,
    I am using a VISA. The bytes at serial port are fixed, that is for a particular command the response number of bytes is fixed. The read operation in the first cycle (of a loop) is correct but it reads garbage characters for every other cycle. I am using a 9600 baud rate and the meter responds directly in strings, no handshake is used.
    Thanks for the response,
    PS: The computer with the code is not connected to the net, i will need to transfer it to post the code.

  • To read 512 bytes using serial communication

    I want to read 512 bytes of data using rs 232 with the timeout of 30ms. I am using "Serial read with timeout -Palm.vi". Is there a limitation of the number of bytes I can specify to this VI?
    Thanks!!
    Attachments:
    Serial_Read_with_Timeout--Palm.vi ‏63 KB

    Hi software enigineer,
    It is not possible to transfer 512 bytes per 30 ms here. To do this would require a baud rate of 136533 (512*8/.03) and the maximum possible baud rate is 115000. The recommend baud rate for a serial transfer is 9600, which would mean transferring at most 36 bytes if the timeout is kept at 30ms. Moreover, there is usually some overhead involved in serial communication, and I would recommend sending a little less than the maximum 36 bytes every time too.
    On another note, I noticed that in your block diagram, you are using the Bytes at Serial Port vi. Definitely use the output of this vi to determine how many bytes to read at a time and read the bytes as they become available in the serial buffer rather than reading in a large buffer
    all at once. Continuously read and append the output until there are no more bytes to be read or until the termination character is read. This will avoid any lost data transmission due to overflow.
    Good luck with your program!
    Kileen Cheng
    Applications Engineer
    National Instruments

  • MEASURING FORCE ON BALANCE USING AN ELECTRONIC BALANCE FROM THE SERIAL PORT

    Hi,
    I am trying to measure FORCE using an electronic BALANCE from the serial port. My measurements are strange! The BALANCE sometimes give ZERO reading! Is it because of the sample rate, baud rate etc? I have attached the readings concerned.
    Attachments:
    databalance.doc ‏144 KB

    I think your problem is due to the way you read the weight :
    1/ask the balance to send the data
    2/oversee the byte number on the serial port until it is constant
    3/read the bytes received
    4/convert to number
    During step 2, you compare the bytes at serial port with the previous value. So far, you have been very lucky to be able to read something : the answer here is always ZERO since the readings occur BEFORE the balance has been able to send anything! means that your loop stops immediately (if you are not convinced, jujst add an indicator to display the loop index. However, since you added a wait (0.8 s), when going to step 3, the balance has had some time to send something. Here, you should not have read again the number of bytes at serial port, but that unwillingly corrects the previous error and you can read most of the received data...
    You should modify completely your algorithm. Usually, a balance send the weight as a string with some terminator (RC or LF). Accordingly, the algorithm should be :
    1/ask the balance to send the data
    2/read the serial port, concatenating the received chars until a terminator char is received or a timeout has occured
    3/convert to number
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • Hola!!!Yesterday, I asked a question about serial port comunication, because I wanted to find a function in Labview similar to "ProcessSystem Events" in Labwindows!!

    My problem is that I have written a comand through the serial port, and I doesn´t receive the answer. If I execute the programm step by step, I don´t have any problem but if the program runs i don´t get the answer!!!It is not a problem of the bytes that I write and receive, i have used the function "Visa Bytes at Serial Port"!!I have used th function "wait" but it doesn´t work!!!!i have used a Flat sequence but it hasn´t solved the problem!!so, i don´t know what i can do!!!
    I attach the "different versions" that i did, maybe someone find a solution!!
    Dennis, I have the problem, when
    I read the last time in the program, I don´t receive the answer!thank you!!!
    Gracinda
    Attachments:
    salida_analogica.vi ‏67 KB
    config_rango.vi ‏41 KB
    salida_ana_v1.vi ‏69 KB

    Dear Mads;
    Thank you for your answer.
    I don´t have a termination character but I know the number of bytes that I have to receive. I tried checking the number of bytes that I received, using "Bytes at Port", but it gets a value and it isn´t refreshed, it has a value so my program stop in the while structure that I have added. I attach the vi. I don´t know how to do that. I am starting with Labview, and it is a little difficult for me!!
    In the first change that I did, I added the function "Bytes at Port" inside the While loops, but it doesn´t work either !!!
    Thank you!
    Attachments:
    entrada_analogica.vi ‏94 KB

  • How can detect the serial port is active

    I made a program. It can read datas via serial port. But the datas wont came all the time, so the other part of the program not need to run. I want to put before the "reading serial port" a detection about the serial port is get a data. So the reading is wont start before datas are not coming. Can anybody help me how can i solve this problem?

    Hi Zoyo, if you use the VISA- VIs, the functionyou need is "VISA Bytes at serial port". It shows, how many Bytes are available in the input buffer. You can find it here:
    greets, Dave
    Message Edited by daveTW on 11-22-2006 02:01 PM
    Greets, Dave
    Attachments:
    Bytes at serial port.png ‏20 KB

Maybe you are looking for

  • Importing photos

    I'm finally getting around to putting some photos on my iPod. I've tried 3 times and each time I get the message: unknown error (-50) and disk could not be read from or written to. I'm trying to import from the my pictures folder. It looked like doin

  • How do i the pdfs in ibooks to sync across iOS and my Mavericks Mac

    i have ios7 on ipad and iphone, and mavericks on my Mac. Im a uni studnet who uses alot of PDFs etc. how can i sync them with ibooks. i dont want to use dropbox.

  • Reating an HTML Table Contents using named Anchors

    I have a on website: http://www.vpea.org/Bylaws/Test/bylaws_toc.htm a table of contents for our Association Bylaws. Just in case I've created named anchors using titles such as article_I, article_II, etc. is there anyway to make when clicking on a gi

  • Can you play lexulous on ipad

    I'm in the market for either a mac book or ipad for my wife. Her main uses are facebook, lexulous, bejouled blitz. Can you not play lexulous on ipad? I presume there is not a problem with a mac book?

  • Iphoe 3g power switch doesn't appear to work

    I have an older 3g.  The power switch doesn't seem to work, so I can't turn it off.  Nor can I re-boot it. Neither holding the power switch nor the home and power switches together seem to have any effect. Any ideas what to do next? Thanks