Shop OBEX P1 Docs P2 Docs Learn Events
.NET and BS2 — Parallax Forums

.NET and BS2

zeroxzerox Posts: 9
edited 2008-08-13 23:09 in BASIC Stamp
Hi, I created a VB .NET interface and want to communicate to the Stamp Basic 2 board. For example if I push a button in my VB .NET program I want a LED to turn on which sits on the stamp board. at this point, all is Ok, but i want to change the value of VAR into the program charged on the basic stamp, using VB.NET, but when i send a character (for example) i dont know how to send the value directly to the VAR into the BS2 Please any have would be a big help.

PS: VAR = Variable
Thank you, all

Jack

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-09 04:08
    You can't send a value directly to a variable on the BS2. You have to use the SERIN or DEBUGIN statement to receive characters and convert them to values that get stored into variables. For example, say you have two variables, AA and BB, declared as words on the BS2 and you want to send two numbers from your VB program to the BS2 and set the values of AA and BB to say 1001 and -1002 respectively. Your VB program would need to send the following characters: "1", "0", "0", "1", " ", "-", "1", "0", "0", "2", CR. CR is a return character whose byte value is 13. Truthfully, it could be any non-numeric character.

    The BS2 would need the following: SERIN <pin>,<Baud>,[noparse][[/noparse] SDEC AA, SDEC BB ]

    <pin> is the pin number to be used. If you're using the serial port normally used for programming, then <pin> is 16.
    <Baud> is a constant that specifies the Baud for the serial port. The Stamp Basic Manual and the Stamp Editor help file both have tables with the values needed for each Stamp model for each standard Baud. I think 9600 Baud for the BS2 is 84. The SDEC AA and SDEC BB indicate that a signed decimal value is expected as a sequence of digits with optional sign, separated by non-numeric characters like spaces and returns.

    Read the chapter in the Stamp Basic Manual on the SERIN and SEROUT statements and on the DEBUG and DEBUGIN statements for lots of detailed explanations and examples.

    Post Edited (Mike Green) : 8/9/2008 4:13:50 AM GMT
  • zeroxzerox Posts: 9
    edited 2008-08-10 02:27
    Thanks for answer so fast, i already sucess making the connection with the COM port (thank to your help) but, when
    i send a signal with a string (letter by letter), the BS2, receive this
    without any problem, but when i disconnect the BS2 of the PC, the value of the string , is re-started at his original value, how can i make permanent the value of the string on the BS2?
  • FranklinFranklin Posts: 4,747
    edited 2008-08-10 04:05
    You would need to write the program so it stored the string into rom and read it back after the next start.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-10 04:37
    Look at the READ and WRITE statements in the Manual. They're intended for storing data to and retrieving data from the EEPROM.
  • zeroxzerox Posts: 9
    edited 2008-08-12 01:34
    thanks, i think i have an idea about what i have to do next, to save the data into the BS2 in execution time, but i still have one more question, when i send data to the BS2, with the VB.NET interface, what type of data read the BS2, because i send the number "2" as char and the BS2, can´t receive the number "2", maybe ia m using wrong the serin command, i read something about sending HEX numbers to the BS2, because BS2 only can receive HEX number, is this true? thanks for your help.-

    Jack
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-08-12 19:02
    Hi Jack, the serin instruction has formatters that interpret the information it receives. If you are sending·an ASCII char value representing a number you would use SERIN rx,baud,[noparse][[/noparse]DEC sdata]. If you expect the values to be greater than a single digit number·a better way would be to define the maximum number of digits likely to be transmitted SERIN rx,baud,[noparse][[/noparse]DEC3 sdata]. This example will wait for a 1 to 3 digit number (for a byte that is 0-255) that is followed by a CR or LF, in VB this can be accomplished using the WriteLine instruction of the serialport object which automatically appends a LF to the string.

    Jeff T.
  • zeroxzerox Posts: 9
    edited 2008-08-13 23:09
    thanks to all, i sucess to send and receive strings and numbers whit sendin and sendout, i post another question about saving a value when the power is off, or the bs2 is reseted, is this posible? thanks for all.-
Sign In or Register to comment.