LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communicating To Basic Stamp with RS232

I am new to programming in Labview.
I recently have a requirement to use LabView to control a Test Setup rigged with a Basic Stamp 2p Mircocontroller.
All I need to do is to get Labview to send some coded commands to the stamp so that it can retrieve execute the commands and then return some data that it collected from the sensors that it is monitoring.
 
Below is how I try to manage the communication:
1. Labview send out "0" then read from COM1, timeout in 5secs. It will repeat this until it get a reply from the Stamp wihtin 5secs.
2. Basic Stamp will not reply if it is doing something else. It will reply "0" if it is ready to receive instructions. And "1" if it is ready to send data.
3. When Labview get a "0" reply, it will send out the two coded instructions. If the reply is "1" Labview will read from COM1.
 
Here's the problem.
I start my experiment by sending the first set of instructions to the Stamp. Which it has no problem executing.
But when I try to send a 2nd instructions, i.e. when Labview try to send out "0" and wait for a "0" reply. It reads the value of the last instruction it sent out. Depending how many bytes I set it to read, LabView will cycle until the last byte of the previous instruction is done then it will read in the "0".
 
I do not believe the problem is with my Stamp program or the hardware as I tried to manually sent instructions using Hyperterminal(with echo off) and I do not see the instructions returning.
The way Labview behave seems like ECHO ON in hyperterminal. Just that the data I sent out seems to be sitting in the read buffer.
 
I manage to bypass this by doing something really stupid. Each time I need to read from the COM port, I close the VISA connection and Open it again. This seems to help clear the buffer. But this put in substantial amount of wait time in both my Stamp and Labview program as I have to ensure each side is ready to communicate and they wait for each other to get ready.
 
Does anyone know how I can stop the data I sent out to appear when I read from COM port?
 
The only configuration that is not default on the VISA connection is that I stepped the Baud rate down to 4800 to ensure that the Stamp do not loose data.
 
Thank you.
 
0 Kudos
Message 1 of 10
(5,779 Views)

Can you "zip" your program and attach it to a post to this thread? If we can look at it we can have a better idea of what may be the problem.

 

P.M.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 10
(5,775 Views)
Attached is my LabView Code. Thanks.
0 Kudos
Message 3 of 10
(5,760 Views)
This is some pretty complex code to do what you're trying to do, so let's just check to see if this works on a more basic level. Open the example finder (help -> Find examples) and search for serial. There is a basic serial read/write VI that you can use to test things like this. Send your 0 and see if you get a 0 back. Then send your command and see what you get back from the device. If it works with this basic VI (which would work just like the hyperterminal) then you know that it will work in LabVIEW and it's all a matter of debugging your code to find out where the error is happening.

Let us know how that goes.

-Matt S.

LabVIEW Integration Engineer with experience in LabVIEW Real-Time, LabVIEW FPGA, DAQ, Machine Vision, as well as C/C++. CLAD, working on CLD and CLA.
0 Kudos
Message 4 of 10
(5,725 Views)

I tried using the Send/Read Example. But since my Stamp is programmed to communicate in 4800 baud rate, I have to add the VISA Config in the Labview example to get it talking properly. Well the results are the same. I see what I send out in the read message box and my stamp is not program to echo message. The only thing I can think of that could cause this is the serial cable. I have to rig an adapter to diasble the stamp from resetting I rigged the cable so that pin 2, 3 & 5 on the DB9 cable is connected to the stamp. Pin 1, 4 & 6 are tie together. Pin 7 & 8 are tied together. (As suggested in the basic stamp manual, Pg 399). Would this cause the data to be routed back to the read buffer?

Thank you.

0 Kudos
Message 5 of 10
(5,713 Views)
If pins 2 and 3 aren't connected, you shouldn't be routing your output directly to your input. Check with a continuity tester or multimeter to find out if they are. Pins 2 and 3 are the transmit and receive pins for 232. Double check to make sure they aren't connected. This might cause the result you're seeing, but I would expect that behavior to be mirrored in Hyperterm as well.

Let us know what you get from that test.

-Matt S.

LabVIEW Integration Engineer with experience in LabVIEW Real-Time, LabVIEW FPGA, DAQ, Machine Vision, as well as C/C++. CLAD, working on CLD and CLA.
0 Kudos
Message 6 of 10
(5,694 Views)

Matt,

  No. I checked. Pin 2 & 3 are not connected. No short. The behavior, interestingly enough is not reflected in Hyperterminal neither does it occur on the debug window for PBasic software. That's why I jump to the conclusion that it has to be some setting or programming in LV. What if I severe the recieve pin? If the mirroring is in the computer where I am running Labview, then I should see the message mirrored in the Read Message Text Box when I run the LV example for serial comm. Right? If I severe receive pin connection and I do not see the message mirroring then I can conclude that the mirroring occurs at the Stamp.

  Does this make sense? Sorry, I am ME background so I am not very familiar with computer communications.

Regards,

Louie

0 Kudos
Message 7 of 10
(5,689 Views)
One way to find out if this is a LabVIEW issue or not is to test this out in MAX. If it gets the same results with a VISA Session in MAX, then it's a VISA setting somewhere. If it doesn't get the same result in MAX, then it is something in your LabVIEW code that would need to be reconfigured. What do you get if you try to do a VISA test panel through MAX and send the same commands?

-Matt S.

LabVIEW Integration Engineer with experience in LabVIEW Real-Time, LabVIEW FPGA, DAQ, Machine Vision, as well as C/C++. CLAD, working on CLD and CLA.
0 Kudos
Message 8 of 10
(5,632 Views)
Same behavior in MAX.
I opened a VISA Session in MAX with baud rate @4800 on COM1. The rest of the settings are at default value.
 
Went to Send Tab
Sent: "0\n"
Went to Read Tab
Read "0\n"
Went to Send Tab
Sent: "55234\n"
Went to Read Tab
Read "55234\n"
 
It seems to be repeating what it sent out as my stamp did not seem to have received any data. I placed an LED on one of my Stamp Pin so that when it gets the "0\n" it would turn the LED off to tell me it got something. So, the problem I think is still on the PC side, be it settings in Labview or the Windows XP.
 
Thank you for your suggestions so far.
 
Regards,
Louie
0 Kudos
Message 9 of 10
(5,628 Views)
I wanted to check something quickly on this, because it seems as though your instrument is echoing everything back. You said that in hyperterminal you dind't see the echo. Do you see the original command you write? If you do, you're probably just seeing the echo. By default you won't see the commands you type out in hyper terminal. You should be getting the exact same results from both hyperterm and the visa test panel. Send us a screenshot of what you see in Hyperterm with echo turned on and with echo turned off. We'll go from there.

Regards,
Matt S.

LabVIEW Integration Engineer with experience in LabVIEW Real-Time, LabVIEW FPGA, DAQ, Machine Vision, as well as C/C++. CLAD, working on CLD and CLA.
0 Kudos
Message 10 of 10
(5,604 Views)