Shop OBEX P1 Docs P2 Docs Learn Events
Aggrivated with Interfacing Labview to BS2 — Parallax Forums

Aggrivated with Interfacing Labview to BS2

rage404rage404 Posts: 17
edited 2009-02-08 06:19 in BASIC Stamp
Hey all,
I've been working on using Labview with the BS2. I want to click a button in labview and run a program on the BS2. Has anyone created a program that can perform this task? All i want is to flash a led.

High 2
Pause 500
Low 2
pause 500

Instigated by some input·from labview.

If I could get this to work it seems like i could figure all the more complicated stuff out.
I am a mechanical engineer so if you are gracious enough to help me out I would appretiate it if it were lower level explanation, else I will just be more confused and aggrivated

Jeff

Post Edited (rage404) : 2/2/2009 3:38:18 AM GMT

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-01 20:03
    ·Assuming you know how to generate a signal from LabView.· This program will wait for an input pin (LV_input) to go HI then it will drop through and execute the hi/lo lines.· [noparse][[/noparse]You'll have to declare the pin an input, etc.]
    Main:
     IF LV_input = 0 THEN Main 
     High 2
     Pause 500
     Low 2 
     pause 500
     
    GOTO Main
    
     
    
  • rage404rage404 Posts: 17
    edited 2009-02-01 20:20
    Maybe I should add some details.
    I am communicating between my computer and the BS2 by means of a serial cable. I am looking to use the serin serout commands. My program may be working since I can use the debug terminal to activate my LED blink.

    It seems that the issue is with LabVIEW. How can I get it to recognize a usb to serial adapter?

    Any labview experts out there?
    Jeff
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-01 20:26
    You need LabView to recognize a COM port is all, I think.

    http://www.parallax.com/dl/sw/labviewbs2.pdf

    Please advise as to your progress.
  • rage404rage404 Posts: 17
    edited 2009-02-01 20:30
    I've been looking over that document and i'm sure it would work great if i had a serial port on my computer. I am forced to use a usb to serial converter to communicate with my BS2.
    This is an issue with LabVIEW. I'm not sure why but it does not want to recognize the com port that is connected to my BS2 and I get error messages.
  • rage404rage404 Posts: 17
    edited 2009-02-02 00:40
    Does anyone know how to Get LabVIEW to recognize a usb to serial adapter as a comport?
  • FranklinFranklin Posts: 4,747
    edited 2009-02-02 01:57
    The drivers for the USB to serial cable create a com port on your system and all you need to do is send data to whatever port that is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • KatyBriKatyBri Posts: 171
    edited 2009-02-02 03:33
    I used Labview a lot several years ago.

    While using it I learned that most of the time serial communications did not work it was either the protocol in Labview and the target were not set the same (speed, parity, stop bits, etc), or the target was expecting an acknowledgment character.

    Also, always start at a very low speed to get it to work, then ramp up until it fails. Use a speed somewhat less than the max.

    Sorry I can't contribute more-I wish I was still developing with Labview, it is fun and nice that you don't have to deal with dll's and deployment issues.
  • rage404rage404 Posts: 17
    edited 2009-02-02 03:34
    Ok, Thanksfor all the help so far. Here is the current situation. With the following code. I can get led's to blink by entering Axxxx or Bxxxx, anything starting with A blinks an LED attached to pin 2 and anything starting with a b will blink an led attached to pin 1.

    Running the below program I get the desired result.
    To test this run the bellow program with an LED hooked in series to a resistor from pin 1 to Vdd.
    Once the debug terminal appears enter Axxxx into the white input area, LED on pin 2 flashes. entering Bxxxx makes led on pin 1 flash.
    This is exactley what I want from my program.

    I want to accomplish the same thing using labview as a front panel. Entering text into the basic serial read write program returns no results.
    Using the measurment and automation program and exploring the appropriate com port allows me to access a test connection section. In this area I can get a response only if I enter my comman twice. Does anyone have an explanation for this?


    stamp program

    ' {$STAMP BS2}
    baudmode CON 84 'serial code to set baudrate (pg.321, BASIC Stamp® Manual)
    'For pin 16 (noninverted): 9600=>84, 19200=>32, 38400=>6
    'For pins 0-15 (inverted): 9600=>16468, 19200=>16416, 38400=>16390

    comm VAR Byte(3) 'command data char
    val VAR Word 'command value
    comm(2) = 0

    'LabVIEW command I/O loop

    top:
    DEBUG CLS, "enter a string of 5 digits starting with an a or d", CR
    SERIN 16,baudmode,[noparse][[/noparse]STR comm\2, DEC3 val] 'get command and value
    'Signal Data Received...always a 2 char command plus 3 digits
    IF comm(0)="A" OR comm(0)="a" THEN A
    IF comm(0)="D" OR comm(0)="d" THEN D
    GOTO top
    A:
    HIGH 2
    PAUSE 500
    LOW 2
    PAUSE 500
    SEROUT 16,baudmode,[noparse][[/noparse]"AA ", DEC3 val, CR]
    GOTO top
    D:
    HIGH 1
    PAUSE 500
    LOW 1
    PAUSE 500
    SEROUT 16,baudmode,[noparse][[/noparse]"BB ", DEC3 val, CR]
    GOTO top
  • rage404rage404 Posts: 17
    edited 2009-02-02 23:04
    Does anyone know why it would execute every two times I send Ao123, is there a protocal I'm missing?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-02 23:06
    What if you send (from LV) "A" followed by a carriage return?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-03 01:41
    OK, you are sending more than A or D, putting some numbers ("decimal characters") in the mix.· Fine.· Same thing.· You need to terminate your LabView generated message with a CR or a letter, because --

    From PBASIC Help regarding SERIN:

    Decimal Formatter Specifics
    The decimal formatter is designed to seek out text that represents decimal numbers. The characters that represent decimal numbers are the characters "0" through "9". Once the SERIN command is asked to use the decimal formatter for a particular variable, it monitors the incoming serial data, looking for the first decimal character. Once it finds the first decimal character, it will continue looking for more (accumulating the entire multi-digit number) until it finds a non-decimal numeric character. Keep in mind that it will not finish until it finds at least one decimal character followed by at least one non-decimal character.

    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-02-03 02:49
    Hi Jeff,·a couple of things that might make a difference,

    P16 is the programming port·with a line driver and the baud should be 9600 inverted which is 16468.

    Also P16 echoes all data it receives back to the PC which can·sit in the PC's serial buffer and get mixed in with your next transmission, best if you can give an·"emptybuffer" instruction before sending data·each time. The suggestion of a terminating CR or null character can only be a good thing .

    Apart from that the BS2 stuff you have looks good to me.

    Jeff T
  • rage404rage404 Posts: 17
    edited 2009-02-03 04:16
    How would i go about implimenting a empty buffer command or a terminating CR. Is that done on the stamp side or on the labview side?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-02-03 04:52
    Hi, don't know in Labview, but to implement carriage return the last byte needs to be a value of 13 . When bytes are read that normally removes them from the buffer that could be one way to clear it. Does Labview have a help file , that should describe the instructions available .

    Jeff T.

    EDIT this all needs to be done at the LabView end the Stamp code looks fine.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-02-03 12:01
    It doesn't have to be a carriage return, it could be any "non-decimal character": an "x" or a "!" or... anything else which is not "0"-"9".
  • rage404rage404 Posts: 17
    edited 2009-02-04 03:23
    Well I have decided LabVIEW is a hellatious pile of "enter unholy explative". It is so aggrivating that it works in the stamp programmer perfectley yes sending three digits and two letters is four days worth of difficult in labview.
    PBasic·code development time = 20 min
    cost = $0

    Labview painstaking trial and error = 4 days
    Cost = $4000 for a commercial license. (I'm glad I didn't pay that.)

    So here are some questions I hope will get me all straightened out.
    How many bits does a letter require?(2)?
    How can labview read my stamp and return the value I entered when my stamp is powered off?
    Has anyone else been able to sucessfully communicate with labview to a BS2?
  • rage404rage404 Posts: 17
    edited 2009-02-08 06:19
    So after days of code checking and being pissed at labview and the basic stamp i stumbled upon a solution. I rigged my serial cable from serial pin5 to vcc and from pin 2 and 3 to there normal positions the program works perfectley. Why does this pin need to be ground in order to communicate with the stamp?
Sign In or Register to comment.