Shop OBEX P1 Docs P2 Docs Learn Events
more than 4 digits from barcode — Parallax Forums

more than 4 digits from barcode

mrgoshmrgosh Posts: 23
edited 2005-05-18 00:17 in BASIC Stamp
Hey guys. Ok, heres a new one.

I'm reading hex formatted barcodes into the basic stamp. These barcodes are anywhere from 5 to 20 or so digits long. The hex formatter, as you know, will only format up to 4 digits total, giving me only a section of the barcode. I've devised a system of getting the first and last four digits of the barcode, but with a couple problems (the biggest of which is that you have to scan twice).

I'm new to this whole thing, so I was wondering if there is anyway to get more than 4 digits of a barcode assigned to a variable (or even several variables) within the program. My biggest consideration is that I would like everything to happen in one scan, as this is for an installation piece that will be used by the public, so ease of operation is paramount.

I'm using a bs2.

Any help you can offer would be appreciated.

Hearts,
-Mike

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-05-12 15:37
    Are these arriving on a serial port? If so you might stream all 20 digits into memory with SERIN using the STR modifier. Or, on the multibank Stamps with scratchpad, the SPSTR modifier. Once in memory, parse the string. Please provide more detail.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • mrgoshmrgosh Posts: 23
    edited 2005-05-12 17:18
    yes! They are arriving on a serial port, transferring at 9600 baud.

    How would I go about using STR in this manner?


    Thanks for your help,
    -Mike
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-12 18:36
    Mike,

    ·· This information is available in the help file under SERIN.
    Help File said...
    STR ByteArray \L {\E}Input a character string of length L into an array. If specified, an end character E causes the string input to end before reaching length L. Remaining bytes are filled with 0s (zeros).
    You will need to delcare the array.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • mrgoshmrgosh Posts: 23
    edited 2005-05-12 21:59
    Ok, this works great for getting the whole numbers into the program. But I'm having trouble accessing the individual digits of the STR array. Is the syntax myVariable(n) where n is the position in the array, or what?

    The results that I'm getting are not what I would expect.


    Thanks again for all your help.

    -Mike
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 17:40
    Hello? Anyone?

    I feel like what I'm trying to do should be really easy: input a large number via serial and have access to each individual digit (i.e. be able to assign them to variables)

    ex.

    wholenumber = 123456789
    var1 = 1
    var2 = 2
    var3 = 3
    var4 = 4
    etc

    could someone please explain to me how to do this on a BS2?

    -Mike
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 17:48
    Mike,

    ·· The number you used as an example is too large to store in a single Word variable.· It would need to be broken up.· It would be more strategic to break up the data as it arrives.· I would like to confirm, you wish to put each individual digit into a separate variable?· If that's the case you could just use an array for the incoming data and assign each array element to a new variable (Although this would waste variable space).· Could you please explain exactly what you're trying to do?· There might be a simpler, easier way to do it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 17:52
    Mike,

    ·· If you're reading the data into an array (I just realized we covered this before), then you should have the digits in the individual array elements already.· For example:

    incoming data = 123456789

    MyArray(0) = 1
    MyArray(1) = 2
    MyArray(2) = 3
    MyArray(3) = 4

    etc...Is this not what you're getting?· If not, what are you getting?



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-05-17 17:55
    Converting strings of large numbers into binary numbers is a problematic thing to do (possible but not a simple task), perhaps your best bet is to convert the string into BCD (binary coded decimal), where each nibble holds one digit (and contains values 0-9 and A-F are not permitted), your example of a 9 digit number would require two 16 bit variables (for a total of 8 BCD digits) and one nibble.
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 17:57
    Gladly.

    I am inputing large numbers into the program via a serial connection (barcode scanner, to be specific). That number is then being used to input the parameters for the FreqOut command so each barcode has its own specific, unique sound.

    The freqout part of the program can be broken up into several subroutines, so it is fine to assign each successive number to the same variable. for example:

    main
    read barcode.
    assign to variable barcodeinVar
    go sub1

    sub1
    digit = barcodeinvar digit 1
    make sound
    go sub 2

    sub2
    digit = barcodeinvar digit 2
    makesound
    etc etc

    I have experimented with the DIG command, but of course.. it cannot handle large numbers.

    I would like to get as many numbers as possible into the program, but I definitely need atleast 5 to 10.


    I hope this answers some questions.
    Thanks for your help.

    -Mike
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 18:09
    here is something straight from the debug window:

    04029311275 <--- barcode number input to array

    0 <--- array key 0

    9 <--- array key 1

    1 <--- 2

    2 <--- 3

    5 <--- 4

    Is this simply a formatting issue?

    -Mike
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 18:12
    Mike,

    ·· Could you please post the code you're using to do this...It's as if numbers (digits) are missing inbewteen.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 18:29
    surely:

    barcodeinVar VAR WORD(13)

    main:
    SEROUT 10, 16468, [noparse][[/noparse]STR barcodeinVar\12]
    SERIN 11, 16468, [noparse][[/noparse]STR barcodeinVar\12]
    DEBUG STR barcodeinVar, 10, 13
    DEBUG barcodeinVar(0)
    DEBUG barcodeinVar(1)
    DEBUG barcodeinVar(2)
    DEBUG barcodeinVar(3)
    DEBUG barcodeinVar(4)
    'GOSUB Var0
    GOTO main
  • NewzedNewzed Posts: 2,503
    edited 2005-05-17 18:31
    You can't use words in an array.· They have to be bytes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Need a bezel for your LCD?

    Newzed@aol.com
    ·
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 18:35
    Well holy Smile.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-17 18:56
    "Arrays handle only Bytes" -- not obvious, eh? Sorry about that.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 19:10
    Hello All,

    ·· Actually you can have a Word array, which is why he's not getting a compiler error.· There·is an inherent problem with this though.· As the code stands there is NO variable space whatsoever left.· Bytes is definately the way to go.· Also, you cannot receive WORD variables via SERIN, only BYTES.··One·question too...why are you sending the array out to another pin serially before you get the array in?· Another question, is after you make corrections, does it work now?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 19:36
    It works, yes. Thank you all for your help.

    For some reason, I'm having timing problems (its running rather slowly) but this is something I think I'll be able to remedy.


    Thank you again.

    -Mike
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 19:37
    Mike,

    ·· It's going to run slowly because of all those DEBUG statements, and possibly due to sending out the data to the other I/O pin.· Why are you doing this?· There's nothing in the array to send on the first pass anyway.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 20:42
    Ok, I take it back. Still some problems.

    When I access the individual numbers of the array, im getting all numbers in the 50s.

    example:

    502632810

    barcodeinVar(0) = 2

    barcodeinVar(1) = 53

    barcodeinVar(2) = 48

    barcodeinVar(3) = 50

    etc

    the code is:

    main:
    SEROUT 10, 16468, [noparse][[/noparse]STR barcodeinVar\10]
    SERIN 11, 16468, [noparse][[/noparse]STR barcodeinVar\10]
    DEBUG STR barcodeinVar, 10, 13
    DEBUG ? barcodeinVar(0), 10, 13
    DEBUG ? barcodeinVar(1), 10, 13
    DEBUG ? barcodeinVar(2), 10, 13
    DEBUG ? barcodeinVar(3)
    GOTO main

    since my timing is based on these numbers, it would explain why it is running to slowly. 53 * 100 in a freqout object would be over 5 seconds. How do i fix this?

    As far as the serout part, it is something my professor suggested, and the program actually wont run without it. I haven't had the time to figure out why.

    -Mike
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 20:49
    Also, here is a small sectio of the freqout code, for reference. I think this should get across what I'm trying to suss out.

    Sub0:
    IF (barcodeinVar(0) = 0) THEN
    GOTO Sub1
    ELSE
    FREQOUT 1, (barcodeinVar(0) * 100), (barcodeinVar(0) * 100)
    PAUSE 100
    ENDIF
    GOTO Sub1
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 20:50
    mrgosh said...(trimmed)
    Ok, I take it back. Still some problems.
    When I access the individual numbers of the array, im getting all numbers in the 50s.
    example:
    502632810
    barcodeinVar(0) = 2
    barcodeinVar(1) = 53
    barcodeinVar(2) = 48
    barcodeinVar(3) = 50
    etc
    since my timing is based on these numbers, it would explain why it is running to slowly. 53 * 100 in a freqout object would be over 5 seconds. How do i fix this?
    As far as the serout part, it is something my professor suggested, and the program actually wont run without it. I haven't had the time to figure out why.
    Mike,

    ·· What is connected to pin 10?· It doesn't help us to help you if you're using code you don't even know why is there.· And you're mentioning FREQOUT timing, but nowhere in your code is that command used, therefore I must assume you're not posting the complete code.· You should attach the whole thing to the message as an attachment so it can be loaded into the Stamp IDE and be examined there.· And please, find out what you're sending data to, especially since in the first pass there's nothing to send to it.· This will help us all a lot.

    [noparse][[/noparse]Edit:] you posted some more of the code while I was replying, adding the code I said didn't exist, but you should still post the complete code...This is a perfect example of how fragments make it hard to help you.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 21:12
    Chris,

    Connected to pin ten is the receive of the barcode scanner that I am using.
    Connected to pin eleven is the send.

    Without the serout command, no matter how many times I scan something, nothing comes up. The scan will not go through. I assumed that this set up some kind of contingency where the barcode scanner only sent information once it received it back. Like some kind of handshake work-around. As far as I can tell, that is what this command does. I apologize for not knowing the full functionality of it.

    I have attached the full code.

    Again, thanks for all the help.
    If you wanna give me your mailing address, I can mail you a beer. You deserve it.


    -Mike
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 21:19
    Mike,

    ·· Please understand my frustration in helping you.· You're making an assumption about how the line works.· And you may be correct, that without the SEROUT you get nothing, but perhaps there is a command that needs to be sent to it.· Perhaps configuration information.· For all we know, the data you're sending back is affecting the data it's sending out.· This is entirely possible.· If I were you, I would also get the spec sheet on the reader.· Perhaps try sending one byte to it, instead of the same array you're trying to receive from it.· Think about what I was saying...On the first pass through the code, the array contains nothing, yet you're sending that to the device.· After that, it should contain the data from the previous read, but at this point it's obvious that the data is either incomplete, corrupt, or being altered, possibly by what you're sending back to it.· I will check your code, and see if I can simulate the setup, but for the record, I think that SEROUT is a major suspect.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 21:33
    Okay,

    ·· New question...You had a GOSUB with no return in a loop which didn't need to be there.· Also at the end of each section of code, the GOTO is not needed since the code will fall right into the next routine.··What my question is though (I know you're sitting at the edge of your seat) is how many speakers are you using?· The first FREQOUT command uses pin 1, the second one uses pin 2, and the rest all use pin 3.· Before I hook this all up I wanted to make sure they were all supposed to be like that...



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 21:45
    mrgosh said...(trimmed)
    Ok, I take it back. Still some problems.
    When I access the individual numbers of the array, im getting all numbers in the 50s.
    example:
    502632810
    barcodeinVar(0) = 2
    barcodeinVar(1) = 53
    barcodeinVar(2) = 48
    barcodeinVar(3) = 50
    etc
    Ya know, this was bugging me for a little bit, until I realized, these are the exact codes you should be getting!· They're the ASCII values of the numbers you listed, except the 2, which could be some sort of start value, or something...
    53 = ASCII 5
    48 = ASCII 0
    50 = ASCII 2

    I would bet the rest are the same way...All you have to do is subtract 48 from each digit (Not counting that 2) to get the actual value.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 5/17/2005 10:02:06 PM GMT
  • mrgoshmrgosh Posts: 23
    edited 2005-05-17 22:04
    Chris,

    Yes. I completely understand your frustration. I'm working on figuring it out the SEROUT line right now.


    And yes, there should be a couple different freqout pins. That is correct.


    -Mike
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-17 22:05
    Mike,

    ·· What are the pins going to (FREQOUT)?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • mrgoshmrgosh Posts: 23
    edited 2005-05-18 00:17
    Chris,

    Everything is now working perfectly. I had to sort of do some round-about math, but its giving me correct results thanks to your noticing the true ascii values.


    once again, thanks a million. i wouldn't have been able to finish this without your help.

    -Mike
Sign In or Register to comment.