Reading/Writing character commands to serial connection

Hey! I'm currently working on a project where part of it is to write a labview program to read and write commands through a serial connection to our PIC24F16KA304 board.
I basically have no knowledge on labview, I've been messing around on it for a few weeks trying to get myself familiar with it but I'm not having much luck.
Essentially I'm programming a train simulation control box. The PIC board will have a sensor that is connected to a train track that sends the character 'A' (for arrived) when a train stops at the station to lab view. I then want to be able to tell Labview to turn a LED on relevant to the station and then respond with the character 'M' for move. I need to repeat this situation for 6 stations
I also need to be able to 'R' for reversing the simulation, 'J' for jump (miss a station) and 'E' for end
If anyone with a bit more experience and knowledge then me can help I would be eternally grateful!

ChrissyC87 wrote:
I suggest that you read some of the LabVIEW basics: http://www.ni.com/gettingstarted/labviewbasics
A state machine would be a good starting point for this project (and your understanding of LabVIEW).
You can always wire constants to VI inputs on the block diagram instead of having controls on the front panel that you have to type into. Just right click on the VI >> create >> constant.
The LabVIEW basics will help you out with all of these simple problems. 
Good luck,
-CC 
Mega-Dittos!
My thoughts exactly. Adding to what Chrissy posted...
Your question reads like "How do I unlock the door to my car and win the Daytona 500?" The first part is simple (use the constants like Chrissy said) but the second part is much more invloved.
plese take the advise posted above and go thorugh the tutorials and learn to use state machines. AS yo udo this other questions will come up and you should feel free to start a new thread on ech question. Stick with it, play nice and we'll get you to the finish line.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction

Similar Messages

  • VISA Read gets incorrect data from serial connection

    I am having difficulty using the VISA functions in LabVIEW to read data from a virtual COM port. Data is being sent from a serial to USB chip via a USB connection using OpenSDA drivers. I have a python program written to read from this chip as well, and it never has an issue. However, when trying to achieve the same read in LabVIEW I am running into the problem of getting incorrect data in the read buffer using the VISA Read function.
    I have a VISA Configure Serial Port function set up with a control to select the COM port that the device is plugged into. Baud rate is default at 9600. Termination char of my data is a newline, which is also default. Enable termination char is set to true. A VISA Open function follows this configuration, and then feeds the VISA Resource Name Out into a while loop where a VISA Read function displays the data in read buffer. Byte count for the VISA Read is set to 20 so I can read more of the erroneous datat, however actual data will only be 6-12 bytes. The while loop has a wait function, and no matter how much I slow down the readings I still get incorrect data (I have tried 20ms thru 1000ms). 
    The data I expect to receive in the read buffer from VISA Read is in the form of "0-255,0-255,0-255\n", like the following:
    51,93,31\n
    or
    51,193,128\n
    And occasionally I receive this data correctly, however I intermittently (sometimes every couple reads, sometimes a couple times in a row) get incorrect readings like this:
    51,1\n
    51,193739\n
    \n
    51,1933,191\n
    51,,193,196\n
    51,1933,252 
    51,203,116203,186\n
    Where it seems like the read data is truncated, missing characters, or has additional characters. Looking at these values, however, it seems like the read was done incorrectly because the bytes seem partially correct (51 is the first number even in incorrect reads).
    I have search but haven't found a similar issue and I am not sure what to try from here on. Any help is appreciated. Thanks!
    Attachments:
    Serial_Read_debugging.vi ‏13 KB

    The first thing is that none of the error clusters are connected so you could be getting errors that you are not seeing. Are you sure about the comm parameters? Finally, I have never had a lot of luck looking for termination characters. You might want to just capture data and append each read into one long string just to see if you are still seeing this strangeness.
    What sort of device is returning the data? How often does it spit out the data? How much distance is there between it and your computer? Can you configure it append something like a checksum or crc to the data?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Efficiency of reading/writing files character-by-character

    I've been assuming that when I do a file "open for access," that among the housekeeping functions set up behind the scenes, there is some sort of buffer created, the size of which is somehow related to the logical sector size of the disc in question, so that reading or writing short pieces of text, or even single characters, doesn't cause independent physical read/write actions at the disc drive.
    Does anyone know if this is true or false? Maybe the question would be clearer posed another way. Suppose I set up a loop to read or write 1024 characters, sequentially, but one at a time. Obviously the loop will require much more time to execute than a singe read or write statement calling for 1K of text all at once. But will there be significantly more activity at the disc drive itself? Will the data be read or written on 1024 successive spins of the platter, or will it be buffered down to one spin, or maybe a couple, depending on the exact location of sector boundaries and so on?
    Thanks.

    Thanks for this. I was sure some such facility was in operation, but I couldn't find anything explicit on the question. I have a task in which I'm trying to convert what looks like incredibly badly formed XML application files into properly tagged and well-formed XML so that I can then get them through a well-designed XML parser. To decode these utter shambles requires decision logic that goes nearly character-by-character. One tutorial page I found on Applescript file I/O suggested that reading/writing character-by-character was inherently inefficient, which I can see that it is, I just wanted to make sure the inefficiency didn't go all the way down to the mechanics of kicking the disc for every single character. The description in the tutorial was ambiguous, and a little disconcerting.
    The tutorial also suggested an alternative strategy of reading an entire file at once into a string and then working with the string. But my files are megabytes long, and I wonder how efficient operations are on megabyte strings, presuming there isn't a limit on string length. Short of trying to do some complex adaptive algorithm, which I might never get working right, I'm pretty sure that keeping to the KISS principal, and just going character-by-character, is a near-optimal strategy in my case.
    Cheers.

  • Problem --serial port reading one character at a time

    Hi Friend,
    I reading the serial port  one character at a time ,  i specified it in the "serial bytes to read" option in serial port read examples.
    The problem is ----------i can able to read  the data.
    but only the first character is reading again and again...and "reading string indicator" in the serial port example shows only the first character sent ..only for a single time.since i am reading continously ----aleast the first character should display as many times i running the program
    (i am running the vi by run continous option..........)..
    please help me ....how to read the character one by one.....
    regards
    rajasekar

    Hi jason...
    I can able to read the serial port by 1 byte or 2 byte or 4 byte as i can specify it in the serial port read bytes option..(in visa serial read)..
    I need to acquire 4 bytes of data and pass it to the Math-script node..and save these 4bytes of data in array (1 row and 4 column)..
    And split this array(just like array-indexing.vi) and processing it each each column separately....
    or suggest some method to achieve my task.....please.
    one more thing the math-script node is placed in a while loop.....in order to read sequence of bytes continously.......
    regards
    rajasekar

  • Serial communication to read single character

    Hi! List,
    I want to read single character using serial communication(see the attached VI).
    The initialization of the serial port is taken care.
    TIA
    Attachments:
    Serial_comm[2_read_single_character].vi ‏42 KB

    I'm not sure I can understand you. If you want to read just one single character why can't you do so by just passing 1 to the Serial Read function as the number of bytes to read?
    The diagram of above VI doesn't make to much sense to me I have to admit.
    Rolf K
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Sending characters VISA serial connection

    Hello.
    I am working on a project where I have to write characters to a PIC in the style of a train controller that controls the direction of a train simulation.
    I have the basic serial reading and writing working. Labview initially sends a 'S' to start the simulation on the PIC. Then it waits for the PIC to send characters relating to what station the train arrives at. Labview then lights the relevant LEDS on the front panel and then tells the PIC to move with a 'M' 
    However, I need to add some extra functions. I want to be able to send additional commands to the PIC such as 'J' to jump a station. 'E' to end the simulation and 'R' for reverse, so the train goes back a station instead of forward. I need these commands to be sent to the PIC when the 'M' is considered.
    So basically user sends a 'J' 'E' or 'R' then send 'M' however I am having trouble with this and not really sure where to put it.
    I've attached my VI so if anyone could give me some useful hints I would be very grateful!
    Attachments:
    Simulation2.vi ‏26 KB

    Looking at your code more closely... why do you have your Start button wired to the "Enable Termination Char" input of VISA Configure Serial Port?  That doesn't make any sense, nor does the comment next to it.  Outside the while loop, why are you reading a local variable of each indicator and then writing that same value to the indicator terminal?  That's not doing anything.  It would be better to get rid of the local variables entirely.  For example you could do something like this:
    Now, on to your question.  What do you mean by "how will this affect my code"?  Try writing it and see.  Start by just duplicating the code you have now, but with a shift register, an enumeration, and 4 cases (matching the 4 states in your current sequence structure). Once that works, you can probably simply add some code to the first case that checks if any command button has been pressed, and if so, send the corresponding character to the serial port.

  • Driver wizard error -1073807174 invalid character present in serial number

    Hello,
    I am trying to get a device working in LabVIEW.  This device does not advertize that it works in LabVIEW but I figured i woudl give it a shot anyway.  When I run the driver wizard I get this error:
    -1073807174 invalid character present in serial number
    The devie is from China so that may have something to do with it.
    usbview.exe is also not happy with the enumeratin of this device.
    I relize this is not a LabVIEW error or NI issue, what I want to know is:
    #1 is there any way around this issue?  Looking for legit or hack.
    #2 Anyone else ever run into this?
    James

    James_G1 wrote:
    I have what I think is the command set.  I assume they do provide an api, but not in labview so I would have to wrap that anyway.  I figured step one was make inf for VISA, but that failed for the reasons stated above.
    Have you been able to establish any kind of communication with the device? Have you tried using MAX to communicate using the API you have?

  • My iphone 4S only start whit cable plug in and then show battery very low (with red line end) then try to turn on but show searching in operator name command and not connecting and no work properly and when I plug out it turn off!!! what should I do?

    My iphone 4S only start whit cable plug in and then show battery very low (with red line end) then try to turn on but show searching in operator name command and not connecting and no work properly and when I plug out it turn off!!! what should I do?

    I'm afraid you'll have to get the phone serviced, dropping the phone must have damaged additional parts inside the phone.
    But Apple will not service the phone anymore, opening the phone and replacing the battery should only be done by authorized personal, not by users.
    You'll have to look for a 3rd party repair shop and see if they can fix this, sorry.

  • Question on reading one character at a time.

    Hi. I am assigned a program where I have to read a series of bits (for example: 01010101). Using this I have to make a "graph out of it". The way I am supposed to make a graph is as follows:
    Each bit interval will be represented in the output as a field taht is two characters wide.
    The value of the signal is represented using either + (to represent +voltage) or - (to represent - voltage) and is always the second character in the output field.
    The first character in the output field is either:
    ' . ' = to indicate no change from the previous signal value or
    ' / ' = to indicate a negative to positive transition or else
    ' \ ' = to indicate a positive to negative transition
    Example for input: 01010101 and the output would be . + \ - . - / + \ - . - / + . + \ - / +
    The code that I got so far is that I read the input from the command line as a argument which I know is nothing but I would just like to know how to read the character one by one and make a graph which is totally boggling my mind because I have no idea how I can do it. Thank you for your help.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Encoder
         public static void main(String[] args)
              int b = Integer.parseInt(args[0].trim());
              System.out.println("You spit out --> "+b);

    Alright I sorta got what you were sayin'. The code that I have now is:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Encoder
         public static void main(String[] args)
              String toEncode = String.valueOf(args[0]);
              StringBuffer result = new StringBuffer();
              char lastChar = toEncode.charAt(0);
              char curChar = '0';
              char lastSign = '+';
              int length = toEncode.length();
              for (int i = 0; i < length; i++)
              curChar = toEncode.charAt(i);
              if (curChar != lastChar)
              if (curChar == '0')
              result.append("\\-");
              lastSign = '-';
              else
              result.append("/+");
              lastSign = '+';
              lastChar = curChar;
              else
              result.append(".");
              result.append(lastSign);
              System.out.println("You spit out --> "+result);
    But it doens't work according to what I want it to do. What I need it to do is the following: Lets say we have the input of 01010101, the result we will get is ". + \ - . - / + \ - . - / + . + \ - / +". The reason for this is because of the following: The graph starts on the v all the time. When there is a 0 bit there is no change and when there is a 1 bit there is an inversion of the voltage level so since we started with a 0 bit at v, when we hit 1 bit we would make a inversion to -v and when we hit 0 bit there would be no change. I don't know of what I said is clear to you or not. For this program, what it does for the input of 01010101, the output is
    " . + / + \ - / + \ - / + \ - / + ". Thank you very much.

  • PC Suite - no USB and Serial Connection Type avail...

    I have been trying to solve this problem for days now. I have Windows XP and Nokia 5310. After I installed Nokia PC Suite, there is no USB or Serial connection type in the Connection Manager; it only has Blue Tooth and Infrared conection available. I have install and uninstalled PC suite and used PC Suite Cleaner to clean the installation. I also went into the add and remove program in the control panel and click on "change" to fix the Nokia Connection Manager and Nokia Connectivity Cable Driver. It still didn't work. The thing is that the first time when installed PC Suite on my laptop, it did have USB connection option. Later after uninstalled PC Suite and reinstalled it, it start to have this problem. I am extremly frustrated. Can anyone help please?

    Thanks for your reply. I have solved the problem by following your instruction below:
    Go to Start --> Settings --> Control Panel --> Software, there you need to uninstall all Nokia software (Nokia PC Suite, Nokia Cable driver, PC Connectivity Solution ...)
    Download and run Nokia PC Suite Cleaner
    Reboot your computer
    Download and install PC Suite here.
    Connect your phone via USB cable (if possible use a different USB jack) and follow the instructions on the screen.
    Maybe when I uninstalled Chinese version of PC suite, the order in which it was uninstalled was not the one you suggested above. So,I followed your instruction and uninstall order to uninstall PC Suite again. I also uninstalled all the antivirus, spyware, and firewall before I reinstall the PC Suite. It worked; then, I reinstalled all the other security software again after I had reinstalled the PC Suite. Although it worked, I still didn't know what exactly cause the problem the first place, PC Suite version, Security protection software, or the order which it was uninstalled? All it matters is it's working.

  • Using usb as serial connecting to cisco router not working

    Tried using ZOC and securecrt and both shows only /dev/tty-Bluetooth.....
    any ideas how can I use USB as serial connection to router?

    Hi and welcome to the forums!
    GREAT FIRST POST!! Very clear and specific. You don't know how rare that is
    Is the laptop in a docking bay?
    Content "encryption" meaning Content protection is turned off, right?
    Are you able to backup and sync with the Desktop software?
    Do you have the correct folders on the card?
    Blackberry, music, ringtones, pictures, videos, voice notes?
    (blackberry has to be first).
    Last one, how did you format the card?
    Thanks
    Update device drivers manually:
    http://www.blackberry.com/btsc/search.do?cmd=displ​ayKC&docType=kc&externalId=KB13336&sliceId=SAL_Pub​...
    Message Edited by Bifocals on 11-19-2008 08:36 PM
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • Read data from Vector object serialized in a file issue!!

    Hi all,
    I have two classes :CBase and CHelper class in a package and serializing some information in a file and then reading it. I am facing some problem while reading the data
    which was stored using vector of objects. Below is the detailed problem:::::
    ////////////CHELPER
    public class CHelper implements Externalizable, Cloneable {
    public string szname;
    //..other functions writeexternal read external
    ////////////CBASE
    public class CBase
    implements Externalizable, Cloneable {
    protected boolean bRead;
    protected boolean bWrite;
    protected Vector vData;
    public void addInstance(CHelper obj) {
    vData.addElement(obj);
    //..other functions writeexternal read external
    I am Serializing all the CBase information in a file and trying to read the contents from this serialized file::::
    CBase base = new CBase();
    CHelper obj = new CHelper();
    obj.setName("HELPER");
    base.addInstance(obj); // ADDING THE OBJECT DATA INTO THE VECTOR
    base.bRead = true;
    base.bWrite = true;
    // Writing to the file
    FileOutputStream fs = new FileOutputStream("d:\\temp\\Base.txt");
    ObjectOutputStream os = new ObjectOutputStream(fs);
    os.writeObject(base);
    os.close();
    //reading from the file
    FileInputStream fi = new FileInputStream("d:\\temp\\Base.txt");
    ObjectInputStream oi = new ObjectInputStream(fi);
    CBase read = (CBase) oi.readObject();
    PRINTING THE OUTPUT
    System.out.println("Vector = " + read.vData.firstElement().toString());
    System.out.println("Write = " + read.bRead);
    System.out.println("Read = " + read.bWrite);
    The output is something like:
    Vector = com.sp.CHelper@14b7453 // WHAT IS THIS ?? GARBAGE ?? NOT ABLE TO ANALYSE :(
    Write = true;
    Read = true;************
    MY PROBLEM:
    i.e How to get the information stored in the Vector ? I am getting something "com.sp.CHelper@14b7453 " whereas the expected output should be Vector = HELPER. I am
    writing and reading the vector as follows:
    // CHELPER
    public void writeExternal(ObjectOutput out) throws IOException {
    out.writeUTF(szName.toString());
    public void readExternal(ObjectInput in) throws IOException,
    ClassNotFoundException {
    setName(in.readUTF());
    Externalize in CBase Classs
    out.writeInt(getInstanceCount()); // getting number of objects in the vector
    for (int index = 0; index < getInstanceCount(); index++) {
    out.writeObject((CHelper)vData.get(index));
    out.writeBoolean(bWrite);
    out.writeBoolean(bRead);
    And reading like this::
    int iNumberofInstances; // number of instances
    iNumberofInstances = in.readInt();
    vData.clear();
    // Get the CHelper object and add it into the CFeatureBase vector
    for (int i = 0; i < iNumberofInstances; i++) {
    CHelper objbase = (CHelper)in.readObject();
    vData.add(objbase);
    this.bWrite = in.readBoolean();
    this.bRead = in.readBoolean();
    I suppose that i am correctly WRITING AND READING the data. B/w what can be the problem. All suggestions are welcome/
    Thanks,
    Rohit

    Vector = com.sp.CHelper@14b7453 // WHAT IS THIS ??
    GARBAGE ?? NOT ABLE TO ANALYSE :(
    Write = true;
    Read = true;************
    MY PROBLEM:
    i.e How to get the information stored in the Vector
    ? I am getting something "com.sp.CHelper@14b7453 "
    whereas the expected output should be Vector =
    HELPER.This is perfectly normal behaviour if your CHelper class doesn't override the toString() method. The default toString() method in Object just prints the name of the class and a hex representation of the object's hash code.
    Add a toString() method to CHelper that returns szname and you should see what you are expecting.

  • Reading newly opened command prompt output

    I need to use SSH to connect to a server. Rather than downloading a third party SSH API, I would like to use Putty which is already on my computer. The problem is that when using Putty from the command line to connect to a server it opens the connection in a completely different command prompt window instead of the original window. How would I read the output from the new window? I believe this code would have worked if it opened the connection in the same command prompt window...
    try{
    File test = new File("c:\\program files\\putty");
    Runtime rt = Runtime.getRuntime();
    Process output = rt.exec("cmd /c putty.exe -ssh username@host", null, test);
    BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
    String line = null;
    while((line = br.readLine()) != null )
    { System.out.println(line); } // display process output
    int exitVal = output.waitFor(); // get process exit value
    System.out.println("Process Exit Value : "+ exitVal);
    catch(IOException ioe){
    System.err.println(ioe);
    catch (Throwable t) {
    t.printStackTrace();
    }

    web definition of 'come unstuck' :
    come unstuck (British & Australian)
    if a person or something they are trying to achieve comes unstuck, they have problems which cause them to fail. Athletes who don't prepare properly for the humid conditions will certainly come unstuck. The negotiations came unstuck over disagreements about the wording.

  • Proper serial connections for Sun Fire v250

    I recently purchased a (gently) used Sun Fire v250 for use as a workstation. The machine had a graphics card installed by a previous owner, but I accidentally reset the factory defaults on the SCC (I was having a boot problem, and apparently a brain problem).
    My question is, how do I connect over serial to make the default boot up options 'screen' instead of 'ttya'? I know from the oracle docs that I need a specific type of serial cable, but I'm unsure where exactly I can go about finding this. Also, once I get the cable what software (for *NIX or windows) can I use to reset the SCC?
    Thanks,
    John Lambert
    Dychron, Inc.

    984429 wrote:
    I recently purchased a (gently) used Sun Fire v250 for use as a workstation. The machine had a graphics card installed by a previous owner, but I accidentally reset the factory defaults on the SCC (I was having a boot problem, and apparently a brain problem).
    My question is, how do I connect over serial to make the default boot up options 'screen' instead of 'ttya'? I know from the oracle docs that I need a specific type of serial cable, but I'm unsure where exactly I can go about finding this. Also, once I get the cable what software (for *NIX or windows) can I use to reset the SCC?
    Thanks,
    John Lambert
    Dychron, Inc.Search for a cisco console cable .... this is a typically a 9 pin to RJ 45 ... usually less than say $10 on at least well known auction site.
    If you laptop/desktop does not have a serial get a usb to serial converter as well.
    If you have a linux desk OS then it is possible to connect to a serial connection ... from solaris you would use tip .... from linux typically use 'cu' (built it) ... if I remember correctly.
    Or use recent versions of PuTTY from windows. ... which can also be configured for serial.

  • How do I read a character and advance the scanner to the next one?

    Hi,
    I'm writing a lexical and grammar analyzer and I don't usually program in Java. I have a method that reads one character and then parses it. The problem is that it keeps reading the same character over and over again, so my program gets stuck in an infinite loop.
    How do I make it so that BufferedReader advances to the next character in the string?
    Here is the code so far:
    public static void getChar()
                throws FileNotFoundException, UnsupportedEncodingException, IOException {
            BufferedReader reader = new BufferedReader(new InputStreamReader
                    (new FileInputStream(inputFileName), Charset.forName("UTF-8")));
            int c;
            if ((c = reader.read()) != -1){
                if (c != 32)
                    nextChar = (char) c;
                if (Character.isLetter(nextChar))
                    charClass = LETTER;
                else if (Character.isDigit(nextChar))
                    charClass = DIGIT;
                else
                    charClass = UNKNOWN;
            else{
                charClass = EOF;
                //System.out.println("Next Token is: RES_WORD. Next lexeme is: EOF.");
        } //end getChar.At first I just had a while loop, but I want this method to be called from another method and so I didn't think the while loop worked. Is there a better way?
    Help is much appreciated.
    EDIT: By the way, I don't want to read tokens. I need it to be characters. And it doesn't have to be BufferedReader. I'm open to suggestions.
    EDIT2: While I don't want to read tokens, if it's the simplest way then I'm open to it. The scanner class would work for that I guess, but then I would have to do a charAt stuff. I'm open to your insight.
    Edited by: RommelR on Feb 25, 2010 8:39 AM
    Edited by: RommelR on Feb 25, 2010 9:00 AM

    DrClap wrote:
    Every time you call that method, you open a new BufferedReader on the file and read the first character from it. So yes, you always get the same character. Solution: Don't open the BufferedReader in that method. Open it somewhere else, just once, and use it in that method.Thanks. That was stupid of me.

Maybe you are looking for

  • Trying to add email to FaceTime

    Trying to add email but says its already in use but when someone tries to call it doesn't work, and when I try to change my user I'd it doesn't take it.  I want to change my original apple I'd but can't. I change to a me.com account

  • Dulicate entry error

    hello i have a jsp form, from that i have insert my data to the database, and also the insert values shows on the other jsp file. i have used jdbc for that. My problem is that when i made the dulicate entry for the partocular on field value, it doesn

  • How to download module for opening raw files from D80o. I have CS6

    How to download a module for opening raw files from Nikon D800? I just bought a CS6 not containing this possibility

  • Z820 won't boot

    I have an HP Z820 with 32GB of RAM and two Intel Xeon E5-2687W CPUs running Windows 7 64-bit. The system had been in storage for the past several months while we were renovating our office. The system was working fine before being packed away. The st

  • MS Word documents in a tree structure

    I have around 2.500 Microsoft Word documents, that I would like to store on my iPad. To be able to find the documents back, I need a simple to use tree structure. Con you advise me what app to buy. Thank you for helping me out Robert