Shop OBEX P1 Docs P2 Docs Learn Events
Serial Input Problem, LabVIEW — Parallax Forums

Serial Input Problem, LabVIEW

paul1985paul1985 Posts: 8
edited 2007-06-22 15:02 in BASIC Stamp
I'm having a problem with my BS2.· I wrote a simple program that turns a pin high or low, depending on whether the BS2 receives a "1" or·a "2" through the serial input pin.· When I open the debug terminal in the Basic Stamp Editor and test my program, everything works fine.· I will press the sequence "a, 1, x" and the pin will go high.· Here is my code below:

SerData VAR Byte

Loop:
SERIN 16, 16780, [noparse][[/noparse]WAIT ("a"),DEC SerData]
IF SerData = 1 THEN Sub
IF SerData = 2 THEN DoThis
GOTO Loop

Sub:
HIGH 8
GOTO Loop

DoThis:
LOW 8
GOTO Loop

The problem arises when I try to write to serial port with lab view.· I write the string "a1x" to the serial port through LabVIEW, and nothing happens, and the particular pin does not go high.· What could be the problem?· Is this a timing issue?· Any help/insight would be greatly appreciated.

Thanks,
Paul

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-03-14 17:43
    What does the x do? Make sure labview sends a CR.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • paul1985paul1985 Posts: 8
    edited 2007-03-14 20:22
    The formatters receive bytes of data, waiting for the first byte that falls within the range of characters they accept (e.g., "0" or "1" for binary, "0" to "9" for decimal, "0" to "9" and "A" to "F" for hex, and "+" or "-" for signed variations of any type). Once they receive a numeric character, they keep accepting input until a non-numeric character arrives or (in the case of the fixed length formatters) the maximum specified number of digits arrives.

    The "x" tells the formatter to stop receiving input.· I'm still having trouble using LabVIEW to communicate with the BS2 through a serial port.· The carriage return idea did not work.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-14 20:41
    I think what Franklin may be saying is that you could replace the x with a CR which may be more intuitive and serve the same purpose. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-03-15 00:17
    paul1985,

    Is your LabView sending upper-case or lower-case?· It'll make a difference to the Stamp (as shown, it's waiting for lower-case.)
  • Jim_BJim_B Posts: 3
    edited 2007-06-22 02:35
    I'm a day late and dollar short but just in case anyone is still watching this thread:

    The default termination character in LabVIEW is the Line Feed, which when viewed in a LabVIEW string indicator with hex display selected is "OA" or with '\' codes selected is "\n".· The Carriage Return as displayed in LabVIEW in hex is "0D" or in '\' codes is "\r".· In LabVIEW, when you configure the serial port you can specify whatever termination character you want to use but the default is the Line Feed character.

    ·In a typical serial port read (in LabVIEW), you specify the number of bytes to read.· If the termination character is encountered in the string before the specified # of bytes is read then LabVIEW stops reading at the term character and returns the string and also a numeric value for the # of bytes actually read.· If LabVIEW does not hit a term character in the string then it just reads the # of bytes it was told to and returns that string and # of bytes.· If there are unread bytes·still remaining then an error code is also reported.

    A few years ago a LabVIEW·serial I/O example was posted on the forum,·but it had some flaws (wouldn't run faster than 4800, had extra spaces inserted up front and then additional functions trying to remove those extra spaces in the back, reading too few bytes, not using a termination character or reading all the bytes and getting timeout errors and "data not read" warnings, etc.· I have cleaned up that LabVIEW example using LabVIEW 8.21,·the library (.LLB with two .VI's) is attached.· I tested it at baud rates from 1200 to 38400 with no errors running LabVIEW 8.21 through USB to Serial adapter connected to the RS-232 port connected to a BS2p24.·· The original LabviewIO.BS2 file worked·as advertised but was getting the blame for the bad coding in LabVIEW, it is also attached, hope thats okay with the original author.

    Regards,
    Jim
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Arguing with an engineer is like mud wrestling with a pig.
    You both end up covered in mud and the pig likes it.

    Post Edited (Jim_B) : 6/22/2007 4:56:41 AM GMT
  • Jim_BJim_B Posts: 3
    edited 2007-06-22 15:02
    Big·apology to anyone trying to use my attachments.··when I started digging deeper I discovered that no data is actually being transferred between LabVIEW and the BS2.· The LabVIEW VI does write to the serial port, but then it is just reading back whatever was sent to the port, there is no interaction with the BS2, so of course it appeared everything was working at all speeds.·

    Back to the drawing·board.
    Jim
    Jim_B said...

    I'm a day late and dollar short but just in case anyone is still watching this thread:

    The default termination character in LabVIEW is the Line Feed, which when viewed in a LabVIEW string indicator with hex display selected is "OA" or with '\' codes selected is "\n".· The Carriage Return as displayed in LabVIEW in hex is "0D" or in '\' codes is "\r".· In LabVIEW, when you configure the serial port you can specify whatever termination character you want to use but the default is the Line Feed character.

    ·In a typical serial port read (in LabVIEW), you specify the number of bytes to read.· If the termination character is encountered in the string before the specified # of bytes is read then LabVIEW stops reading at the term character and returns the string and also a numeric value for the # of bytes actually read.· If LabVIEW does not hit a term character in the string then it just reads the # of bytes it was told to and returns that string and # of bytes.· If there are unread bytes·still remaining then an error code is also reported.

    A few years ago a LabVIEW·serial I/O example was posted on the forum,·but it had some flaws (wouldn't run faster than 4800, had extra spaces inserted up front and then additional functions trying to remove those extra spaces in the back, reading too few bytes, not using a termination character or reading all the bytes and getting timeout errors and "data not read" warnings, etc.· I have cleaned up that LabVIEW example using LabVIEW 8.21,·the library (.LLB with two .VI's) is attached.· I tested it at baud rates from 1200 to 38400 with no errors running LabVIEW 8.21 through USB to Serial adapter connected to the RS-232 port connected to a BS2p24.·· The original LabviewIO.BS2 file worked·as advertised but was getting the blame for the bad coding in LabVIEW, it is also attached, hope thats okay with the original author.

    Regards,
    Jim
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Arguing with an engineer is like mud wrestling with a pig.
    You both end up covered in mud and the pig likes it.
Sign In or Register to comment.