Shop OBEX P1 Docs P2 Docs Learn Events
The command GET for BS2p, Has a equivalent command for BS2? — Parallax Forums

The command GET for BS2p, Has a equivalent command for BS2?

Jaacan MartinezJaacan Martinez Posts: 10
edited 2004-09-25 03:29 in BASIC Stamp
Hello, I have been working whit BS2 device, and I have a litle problem, I need to get data from a gas meter device in string form and store in memory in the BS2, after that information is shift from ASCII to decimal character by character.
I was reading "Stamping on Down the Road" by Jon Williams published in The Nuts & Volts of Basic Stamps Vol. 4, Column # 103, page 175 and I funt a soubrutine that helped me to do my task:

The soubroutine is:

Parse_Field:
workVal = 0 'clear return value
IF (FLDWIDTH < 6) THEN 'valid FLDWIDTH?
DO WHILE (FLDWIDTH > 0)
workVal = workVal * 10 'Shift results digits left
GET IDX, char 'get digits from field
WV = WV + (char - "0") 'convert, add into a value
FLDWIDTH = FLDWIDTH - 1 'decrement field width
IDX = IDX + 1 'point to the next digit
LOOP
ENDIF
RETURN

The point is that these code is for BS2p and I need to do that with BS2.
The problem is that command GET is not valid for BS2, and I would like to kwnow if there is a command equvalent to GET for BS2 device.

Thank you for your atenttion, I hope that you can answer my cuestion.
2K

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-07 18:33
    There is no GET or PUT commands with the BS2 because there is no Scratchpad RAM in the BS2. GET and PUT treat the Scratchpad as an array, so you could use an array variable.

    Instead of:

    · GET idx, char

    You would do:

    · char = myArray(idx)

    If you've got information stored in EEPROM, you can uses READ and WRITE just like GET and PUT.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Jaacan MartinezJaacan Martinez Posts: 10
    edited 2004-09-23 22:14
    Hello Mr. Williams, It´s me again.

    First of all I want to Thank you for your tip, It helped to me to develop my work.

    This time the problem is with the BS2p, I need to collect a string from a gas metter and the lecture can be from one to 7 character, i.e., 0 or 999,999.

    I´m storing the string in memry and using GET command, I need to catch these string, convert to decimal number and later send it to the screen, but I been had a big trouble because I don´t know how many characters the meter sends to me.
    The question is how can I cout the number of characters that the meter sends to me, and after want t get these characters and display them on the screen, like in your article "Stamping n Down the Road.

    Thank you for you attention.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-23 22:27
    The difficulty you have is that you maximum value exceeds the capacity of 16-bit variables that the BASIC Stamp uses. If, for example, your input was never going to be more that 65535, AND (this is important) the value was followed by a NON-NUMERIC character, you could use the DEC modifier:

    SERIN pin, mode, [noparse][[/noparse]DEC meter]

    Does your program output provide any additional information? What does the string output look like, exactly?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Jaacan MartinezJaacan Martinez Posts: 10
    edited 2004-09-23 23:34
    The input looks like

    0 to 999,999

    The comma is put when number is greater than 999

    I want to get the input in pairs, i.e, first two characters will be stored in a variable, next character in another variable, the comma will be excluded from the reading and next character will be stored in another variable and the last two character will be stored in a fourth variable that in the case that the size of the string input will be 7 characters, but it can be of one, two.... up to seven char.

    The output data format will be in the form

    serout pin, mode, [noparse][[/noparse]DEC VAR1,DECVAR2,",",DEC VAR3, DEC VAR4] 'IN CASE THAT THE

    STRING SIZE WILL

    BE 7 CHARRACTERS

    WHEN THE STRING SIZE WILL BE LESS THAN 7, THE NUMBER OF VARIABLES WILL BE LESS TOO, BUT THE FORMAT OUTPUT WILL BE SIMILAR
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-24 00:01
    If you're saying that the output will ONLY be one to seven characters and nothing else, then I'm stuck. How do you know when the device is done sending you information?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Jaacan MartinezJaacan Martinez Posts: 10
    edited 2004-09-24 00:19
    That's the prblem I don't know how many characters it will be sent, May be one or maybe 7 including comma.
  • Jaacan MartinezJaacan Martinez Posts: 10
    edited 2004-09-24 00:22
    The caption of infrmation from the meter will be at 2 times at day, at 23:59 hours and at 11:59 Hrs.

    This meter is working all time and we need to get the data two times every day.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-24 00:27
    There's probably somebody smarter here that can figure it out, but without knowing how many characters are coming or without any trailing characters, gee whiz... I just don't know.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-09-24 01:04
    >>The caption of infrmation from the meter will be at 2 times at day
    >> at 23:59 hours and at 11:59 Hrs.
    >> This meter is working all time and we need to get the data two times every day.

    Maybe a timout? Something like:
    FOR idx=0 to 7 : PUT idx.$ff : NEXT ' initialize to $ff
    ' at 11:58:45 and 23:58:45 waiting:
    SERIN mpin,mbaud,65000,continue,[noparse][[/noparse]SPSTR 7] ' bails out if it does not get 7
    those unreceived contain $ff

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jaacan MartinezJaacan Martinez Posts: 10
    edited 2004-09-24 01:28
    Is there a way to cout the number of character on the string that I read from the meter with the SPSTR command?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-24 04:32
    No, SPSTR waits for a specified number of characters -- your challenge is the variable-length string.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ionion Posts: 101
    edited 2004-09-24 13:17
    Most of the devices using RS232 to send data out are programable to send a start transmision character and end transmision character. Can your meter be programed the same way ?
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-09-24 16:12
    >> Is there a way to cout the number of character on the string
    >> that I read from the meter with the SPSTR command?

    If the SPSTR command terminates with a timeout, your program can count how many characters were actually received. For example, if the following command only receives 5 characters, it will after 20 seconds (BS2p) execute code at "bailout", and the idx=5.
    FOR idx=0 to 15 : PUT idx.$ff : NEXT
      SERIN mpin,mbaud,50000,bailout,[noparse][[/noparse]SPSTR 15]
    


    Then, assuming that you preinitialized all of SPRAM locations to a character that will never appear in your input string ($ff), you can count how many were actually received in the time allotted.
    bailout:
      FOR idx=0 to 15
          GET idx,char
           IF char=$ff THEN EXIT 
       NEXT
      ' exit with idx=number of characters received.
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-24 17:36
    Good solution, Tracy! YOU are the man.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Harry StonerHarry Stoner Posts: 54
    edited 2004-09-24 18:16
    If the baud rate can be set low enough, then you could read a character at a time and execute some commands in between. One other clue would be, if you read a comma, then you know you have exactly 3 more characters to go.

    Harry
  • Jaacan MartinezJaacan Martinez Posts: 10
    edited 2004-09-25 01:58
    Hello, I'm ashamed but I don't know how to preinitialize all the SPRAM locations, I have been looking for in Basic Stamp Help how to do that and I couldn´t find it.

    How can I preinitialize that with $ff value?

    Post Edited (Jaacan Martinez) : 9/25/2004 3:27:34 AM GMT
  • edited 2004-09-25 03:29
    I am working with Jaacan, and we have problems with the signals.

    We have a pressure meter that give us the date, hour and pressure, but the problem is that the pressure can have one digit, two or more with a comma between the digits (0-999,999)

    We dont know how to read that number and make a distinction when we have only one digit or more digits.

    First of all, we are working with the Computers, not with the meter to make probes and see how to use and manipulate the information from the meter.

    We check how to implement the instructions that you gave us, implemented with the PC:

    FOR idx=0 TO 15
    PUT idx.$ff
    NEXT
    SERIN 16,16468,50000,bailout,[noparse][[/noparse]SPSTR 15]
    bailout:
    FOR idx=0 TO 15
    GET idx,char
    IF char=$ff THEN EXIT
    NEXT

    We don't know hot to preinitialice the SPRAM Locations
Sign In or Register to comment.