Serial Input Problem, LabVIEW
paul1985
Posts: 8
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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 Savage
Parallax Tech Support
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.)
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
Back to the drawing·board.
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Arguing with an engineer is like mud wrestling with a pig.
You both end up covered in mud and the pig likes it.