Sending commands and reading data - RS232

Hello guys !
I have a special problem communicatin through RS232 with a PIC microcontroller.
The problem :
On push of a button i want to read a value from the microcontroller.
On another push of a button, i want to write a value to the microcontroller.
However, i get an error : "VISA:  (Hex 0xBFFF0015) Timeout expired before operation completed."
I've tried to search the forum for similar problem, but i haven't found a suitable answer.
I also post my current code for reference. I'm using LabView 8.5.1.
The RS232 communication is working fine (i can read and write from the PIC).
I tested the connection extensively so i think that te problem is not there.
Can u help me ?
Thank you !
Attachments:
Serial-1.vi ‏53 KB

Are you waiting for a response from the device after you send it a command? Are you getting any data back? A simple delay is not a very good solution since your program may work for one given situation but the hard delay may not in others. You can use a VISA event to wait for data at the serial port. How much data are you expecting? If it is a larg eamount of data you may want to calculate the timeout for the read based on the amount of data and your given BAUD rate. If you expect a large amount of data you may not have your timeout set long enough for all the data to arrive, especially if you are using slower BAUD rates.
I noticed in your code that you have enabled the read to look for a termination character. Does your device send one? If not, you may be getting the error because you have not received the 1000 bytes you indicating you want to receive. If you will not be getting a termination character and you don't know how much data you will be receiving you need to create some type of algorithm to read data and decide when to stop. Th eapproach I use is to read a single byte. This read will contain the maximum timeout to wait for the data to arrive. Once a single byte has been read I continue reading chunks of data using a small timeout value. This value should be long enough to allow any small delay that occurs in the data as it is being sent from the device but short enough to indicate the data is complete once a timeout does occur. This timeout error is discarded since it is not a true communication error.
NOTE: You should avoid using controls as variables. You have your Byte to Read controls set as default values and hidden. Therefore they are nothing more then a constant. Hiding controls simple to hide "variables" is not a good coding practice. Either expose the controls to teh user or use a constant.
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot

Similar Messages

  • Best way to control and read data from multiple instruments?

    Hello,
    I'm building an application to test power supplies involving multiple pieces of equipment over a couple of different comm busses. The application will also send control instructions to some of the instruments, and read data from some of the instruments. The reading and control profiles will not run on the same schedule (variable length control steps, configurable read interval).
    I was thinking of using a queued statemachine (producer/consumer) for the control profile and another to read the data, but I got concerned that there would be collisions between sending control commands and read commands to the same machine. Is there a suggested design pattern for implementing something like this?
    Timing of the commands isn't critical down to the milisecond, but I need to collect reasonably accurate timestamps when the data is read. The same is true for the control commands.
    Here are the instruments I'm going to use, if the are control, read, or both, and the communication method
    Instrument Funtions Comm Method
    Power Supply Read data Communicates to PMBus Adapter
    PMBus to USB Adapter Read data USB (Non-Visa)
    Switch control relays USB (VISA)
    Power Dist. Unit read data/control outlets SNMP (Ethernet)
    Electronic Load read data/control load GPIB (VISA)
    Thermal Chamber read data/control temp Ethernet (VISA)
    Thanks,
    Simon

    Hello, there is a template in LV called "Continuous measurement and Logging".
    It can give you some idea how to properly decouple the "GUI Event handler" top loop (where your Event structure is) from the DAQ and other loops.
    You do not need to totally replicate the above example, but you can find there nice tricks which can help you at certain points.
    The second loop from the top is the "UI message loop". It handles the commands coming from the top loop, and regarding to the local state machine and other possible conditions and states, it can command the other loops below.
    During normal run, the different instrument loops just do the data reading, but if you send a control command from the top loop to a certain instrument loop (use a separate Queue for every instrument loops), that loop will Dequeue the control command, execute it, and goes back to data reading mode (in data reading mode the loop Dequeu itself with a "data read" command automatically). In this way the control and data read modes happen in serial not in parallel which you want to avoid (but I think some instrument drivers can even handle parallel access, it will not happen in really parallel...).
    In every instrument loop when you read a value, attach a TimeStamp to it, and send this timestamp/value couple to the DataLogging loop via a Queue. You can use a cluster including 3 items: Source(instrument)/timestamp/value. All the instrument loops can use the same "Data logging" Queue. In the Datalogging while loop, after Dequeue-ing, you can Unbundle the cluster and save the timestamp and data-value into the required channel (different channel for every instrument) of a TDMS file.
    (Important: NEVER use 2 Event structures in the same top level "main" VI!)

  • How to write and read data in a specific memory location ??

    Hi Everyone:
    Does anyone know how to write and read data in a specific memory location by using Java ?
    I need pointers, but I don't know how to do it ??
    Thanks for answering
    Rodger

    Hi Everyone:
    Does anyone know how to write and read data in a
    specific memory location by using Java ?
    I need pointers, but I don't know how to do it ??
    Thanks for answering
    RodgerWith Java you cannot write to a specific memory location. Java does not have pointers. If you really want to do it, you need to use JNI, i.e write the required functions in C (or other languages that support pointers) and make those functions available to Java (through JNI). This approach is not portable. You can have a look at http://java.sun.com/docs/books/tutorial/native1.1/index.html
    Regards.

  • How do i delete my cell # from my daughters ipod touch?  I have changed the #'s in my apple id but it is still using the other cell # in their ipod touch for imessage which allows them to send recieve and read texts to that #.

    how do i delete my cell # from my daughters ipod touch?  I have changed the #'s in my apple id but it is still using the other cell # in their ipod touch for imessage which allows them to send recieve and read texts to that #.

    You can only uncheck the cell phone number. The only way to delete it is to use for FaceTime and Messages an Apple ID not associated with the iPhone.

  • Sending commands and getting answers

    Hi,
         In the given attachment, you have a set of textboxes under checkbox and more down to the tabcontrol. Now, i want communicate with the SMPS(inbetween i have a microcontroller)for getting answers. I dont have any basic idea regarding the task. My instructor gave me a bunch of commands and i have to slect some commands(PM bus) from and used in the application.
        Can any one give suggestions about this, Thanks in advance.
    Attachments:
    rajvi.vi ‏64 KB

    now, i have taken the sequence structure and tried to implement all the commands appending together but its not working, Because my device will undestand only hex and i think i am sending normal string so far. The thing what i am doing is exactly wrong and for tommorow's metting i need to show some thing. In my case, i need to monitor and control the SMPS. I am using PMBus protocol(i have taken commands from http://pmbus.org/docs/PMBus_Specification_Part_II_Rev_1-1_20070205.pdf and in that you can see commands in last pages) on slave side to get and set the data. in my attched VI the 5 numeric indicators shown down to tab control are monitor stuff i.e those are only read parameters. Right now, i am just sending the command code for tommarows meeting but indeed i need to send a packet structure to get data and set data. My basic doubt is how can implement set of commands everytime to write one by one continously and each command cost a result back which i need to store that in the textboxes(not all only below 5). Other text boxes can read the data as well write to the device drictly from numeric indicators. Dont have any basic idea to do that. Can any one help me.  
    Attachments:
    rajvi.vi ‏68 KB

  • How to find out the failed sql command and its data from DEFERROR

    Hi,
    has anybody a procedure or some other possibilities to read the content of column USER_DATA of the advanced replication view DEFERROR in order to find out the failed sql command and its column values?
    Thanks in advance.

    Hi Vishwa,
                 The control would be something like this for navigation in Get_p_xxx method u mention as link and u mention a event name which gets triggered on the click of this hyperlink. So your GET_P_XXX method would have the following code:
    CASE iv_property.
        WHEN if_bsp_wd_model_setter_getter=>fp_fieldtype.
          rv_value = cl_bsp_dlc_view_descriptor=>field_type_event_link.
        WHEN if_bsp_wd_model_setter_getter=>fp_onclick.
          rv_value = 'EXAMPLE'.
    Now you have to create a method as EH_ONEXAMPLE at your IMPL class and within which you would give an outbound plug method. Within the outbound plug the target data would be filled in the collection and window outbound plug would be triggered.
    This is a huge topic and  i have just mentioned you basic things.
    Regards,
    Bharathy.

  • Having problem with adding and reading dates to/from database !!!

    Hi
    I am new in J2ME
    I am trying to code a simple software.
    My problem is with dates.
    I have a datefield on my menu and the user will choose the date from here. By default, datefield shows todays date. But when I try to write that date to database using rms, date value transforms to java.util.Date@acfdb0fe.
    As I read from tutorials this is common problem of date class, so I tried to use calendar class.
    But with Calendar class I cannot let user to choose date from screen like DateField. datefield dowsn't work with calendar.
    later, I will use that date for sorting records
    Summary : I need a sample code that read date from screen (preferably with datefield), write it to recordstore. and then read it from recordstore asnd write to screen.
    I searching internet for a sample code through days.
    Please help me
    Thanks

    Hi,
    The best i would suggest is instead of storing the date as 19 Jan 2004 or something like this better store the date in milliseconds.
    DateField df = new DateField();
    Date d = df.getDate();
    long ms = d.getTime();
    store the value of ms in RMS. This is the commonly used way to store date in RMS for j2me.
    You can get back date using
    Date d = new Date(ms);
    DateField df = new DateField();
    df.setDate(d);
    Prabhu.

  • Mssql and reading date

    hi there,
    I am reading data from mssql server and all things are working ok except l can not read date column from the database (l checked date is int type ). However, l used to assign int type variable , it does not work.
    If any one knows please, please help.
    ResultSet result = stm.executeQuery("SELECT a_create_date from ihd_helpdesk") {
    int adate;
    whle(next())
    adate = result.getInteger(a_create_date);

    As DrClap suggests - it is highly likely it is an offset from a specific time in the past. This in not uncommon in the past before nice things like date fields existed. Also this made a date easy to compare and was a very efficent (in terms of storage). If you try taking todays date and subtract the number in seconds from it you will most likely come close to the reference date. Then you should be able to guess the reference date as it will be something very obvious. Get someone to update a record date to today and use it.
    For example.
    Calendar cal = Calendar.getInstance();
    java.util.Date currentDate = cal.getTime();
    // the negative value of the int in the database
    int offSet = -1079618812;
    cal.add(cal.SECOND,offSet);
    java.util.Date test = cal.getTime();
    System.out.println("Reference Date="+test);
    // Reference Date=Thu Jan 01 04:10:37 MST 1970

  • Send html and  image data to browser

    Hi,
    Is it possible to send both html and image data to browser.
    Can I dynamically generate the image and send the image data without storing the image in web server's hard disk.
    Can you plz tell me what areas that I should look for and learn in order to do this.
    THanks a lot,
    Chamal.

    u can make use of jakarta`s commons fileUploader classes to upload ur file to the server
    here is a small example i made
    html is like this
    <html>
    <form method="post" action="/uploadFile" enctype="multipart/form-data">
    <input type="text" name="uname"/>
    File
    <input type="file" name="upfile"/>
    <input type="submit"/>
    </form>
    </html>
    my servlet contains these code
    FileUpload fup=new FileUpload();
              boolean isMultipart = FileUpload.isMultipartContent(req);
    //          Create a new file upload handler
              System.out.println(isMultipart);
              DiskFileUpload upload = new DiskFileUpload();
    //          Parse the request
              List /* FileItem */ items = upload.parseRequest(req);
              Iterator iter = items.iterator();
              while (iter.hasNext()) {
              FileItem item = (FileItem) iter.next();
              if (item.isFormField()) {
              System.out.println("its a field");
              } else {
              System.out.println("its a file");
              System.out.println(item.getName());
              File cfile=new File(item.getName());
              System.out.println(cfile.getName());
              System.out.println(getServletContext().getRealPath("/mine"));
              File tosave=new File(getServletContext().getRealPath("/"),cfile.getName());
              item.write(tosave);
    for more info
    http://sun.calstatela.edu/~cysun/documentation/jakarta/commons/fileupload-1.0/apidocs/org/apache/commons/fileupload/FileItem.html

  • How to acquire and read data before trigger?

    Hi, all:  
             I want to acquire a impluse signal, and the data when the signal begins is very important to me. So, I want to using a digStart trigger to acquire it, but then i'll lose what i want, maybe i can acquire it continuously, and use the trigger to start read the buffer after a delay(in order to wait the signal end), i don't know if there is any ANSI C functions I can use to do it in this way. I am using PCI6220, DAQmx9.02 and ANSI C.   If anyone have some info on this please let me know. thinks.

    Hi Cris Brown:
                   From your application,I suggest that you can use DAQmxCfgDigEdgeRefTrig function; define  pretrigger samples fitting for your application.
    Try it. Best Regard!

  • How can I send commands and recive rs232 with this Dll

    / programmer commands
    INTERFACE char* (WINAPI DYNAMIC KeyCmd)( char const* cmd, char* rsp, int maxrsp);
    INTERFACE void (WINAPI DYNAMIC DoCmd)(char const*cmd, char *rsp, int maxrsp);
    Note: I see "char*", is this a pointer or a char String. I aspect to get Volt levels to plot a graph.

    louX2,
    char* is the same as LabVIEW's C String Pointer (CStr) data type. I would not worry about the const for the first character strings as this just means they will not be changed in the function.
    Randy Hoskin
    Applications Engineer
    National Instruments
    http://www.ni.com/ask

  • Issues with AR Invoice form after sending barcode and tab data to PC

    Hi,
    We have a barcode system to scan ItemCodes and send 5 x tabs 'keypresses' to the checkout users PC.
    This basically populates all the required fields on the AR Invoice row and jumps down to the next row ready for the next barcode.
    We have recently upgrading to 8.8, and we have developed an annoying issue.  Intermittently, the PCs not behaving as expected.  Here are some of the bad results we have experienced:
    1. The barcode scan is done, but the tabs being sent to the PC are not registered..  The PC just sits there with the cursor at the end of the (populated) ItemCode box without recognising that tabs have been sent
    2. The barcode scan is done and the ItemCode box is populated as expected.  However SAP has not processed all the expected tabs and the cursor remains one of the next few fields awaiting user input.
    3. As above the barcode scan is done and the ItemCode box is populated as expected.  However SAP has not processed all the expected tabs.  Also, the cursor is not present within the current 'selected' field - it seems to have almost lost focus from the fields on the form.  Note: the SAP window remains the active Window.
    All of this means that the processing of Invoices is being delayed as tabs are not being processing and form focus is being lost.
    The form settings are correct as they are unchanged from being working to suddenly stopping working.  The issue is occasionally resolved by a reboot of the client PC in question. 
    Is this a known issue in 8.8?  If not, is this most likely to be caused by display issues or SAP 8.8 not being able to handle the receipt of tab commands in such quick sucession?
    Any pointers or comments from your experience would be appreciated.
    Regards
    OB

    Which patch level are you using as this should be fixxed. I would also look if there are any conflicts with the add-ons as there some major changes in the SDK.

  • Writing and reading data from a form

    I am trying to write a save and load feature for an application using mostly Jtextboxes and things. Basically I have a form that the user enters data into. I want to be able to save this data and load this data. I am relatively new to working on a GUI and I'm not quite sure if my knowledge of I/O applies to this. This is my stab at it but if I am completely off I would not be surprised. I don't want to print it to the command line but this was all I could think of right now. Any help would be greatly appreciated.     
    private void SavePrefs() {
              File SavePrefs;
              // get filename:
              fc.setDialogTitle("Select Filename For Site Data");
              int result = fc.showOpenDialog(f);
              if (result == JOptionPane.OK_OPTION) {
                   SavePrefs = fc.getSelectedFile();
                   // default file extension ".CMM"
                   if (!SavePrefs.getName().endsWith(".CMM")) {
                        // filename does not meet requirmeents:
                        System.out.println("NO CMIMS in filename");
                        SavePrefs = new File(SavePrefs.getAbsolutePath() + ".CMM");
                   // continue with save code:
                   System.out.println("File Selected:" + SavePrefs.toString());
                   //Creates a .cmm file with a code in it containing the data from the first site tab.
                   FileOutputStream out; // declare a file output object
    PrintStream p; // declare a print stream object
                   try
    // Create a new file output stream
    out = new FileOutputStream(SavePrefs.toString());
    // Connect print stream to the output stream
    p = new PrintStream( out );
    p.print(_SitePropPanel);
    p.close();
    catch (Exception e)
    System.err.println ("Error writing to file");
                   JOptionPane.showMessageDialog(null,
                             "File is saved.");
              // not OK selected (cancel or.?)
         private void LoadPrefs() {
              File loadPrefs;
              // get filename:
              fc.setDialogTitle("Select Filename For Site Data");
              int result = fc.showOpenDialog(f);
              if (result == JOptionPane.OK_OPTION) {
                   loadPrefs = fc.getSelectedFile();
                   // default file extension ".CMM"
                   if (!loadPrefs.getName().endsWith(".CMM")) {
                        // filename does not meet requirements:
                        System.out.println("NO CMIMS in filename");
                   // continue with save code:
                   System.out.println("File Selected:" + loadPrefs.toString());
                   try
         // Open the file that is the first
         // command line parameter
         FileInputStream fstream = new
                                  FileInputStream(loadPrefs.toString());
         // Convert our input stream to a
         // DataInputStream
                             DataInputStream in =
         new DataInputStream(fstream);
         // Continue to read lines while
         // there are still some left to read
         while (in.available() !=0)
         // Print file line to screen
                                  System.out.println (in.readLine());
                             in.close();
         catch (Exception e)
                             System.err.println("File input error");
              JOptionPane.showMessageDialog(null, "Feature is not yet implemented.");
         }

    Oh and the GUI is a window with menus where the save feature resides, but the data is in tabbed panels. That is where the _SitePropPanel comes in. I know I want it to write the input from the panel and not the panel. What would would I use for that? I tried getInputContext().                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Issuing commands and receiving data

    I'm using a Stanford Research Counter (SR400) and trying to issue commands to it (specifically the SS command which queries the status byte). I want to receive the byte after I issue the command, but it doesn't seem to be working correctly. I'm using a GPIB interface and have tried the GPIB Write and GPIB Read commands as well as the MISC ones and some others. I'm not sure how labview gets the data from the instrument, but when I query the status byte, it just get the default 0. Thanks for any help!
    - Jon

    I've tried the GPIB Status and Serial Polls, but neither of them return the status byte that contains a bit that indicates whether there's data ready to be collected. I was thinking of using this bit to trigger my program, but now I'm not quite sure how. Thanks for the tip.
    - Jon

  • How to open and read data from text file in PL/SQL

    We have a project ,need to open a file containing entries of data
    ,then process those data records one by one to update the
    database.This operation shoulbe be done in the database
    enviroment. Is there any hint about the file operation in
    PL/SQL? How to open the file and get one record ,maybe one line,
    and parse and get the data field ?
    thanks
    defang

    There was also a question on this over at AskTom
    (asktom.oracle.com) about a week ago complete with sample code.
    The pointer to the sample code is here:
    <A HREF="http://asktom.oracle.com/pls/ask/f?
    p=4950:8:::::F4950_P8_DISPLAYID:464420312302
    TARGET=_blank>http://asktom.oracle.com/pls/ask/f?
    p=4950:8:::::F4950_P8_DISPLAYID:464420312302</A>
    Admittedly it's about Win95, but the principles should apply.
    Yours faithfully, Graham Reeds.
    [email protected] | http://omnieng.co.uk/

Maybe you are looking for