Small program problem
Newzed
Posts: 2,503
I have 9 characters - i.e., 414E50A2B -· stored at @Rx_data.· I would like to extract the last· 5 characters - 50A2B -· and compare them to a constant or an expressed VAR.· How do I do that?
Thanks
Sid
·
Thanks
Sid
·
Comments
PUB rfid
· DirA[noparse][[/noparse]Enable_Pin]:= Out·
· text.Str(String("· Reading RFID Tag ID",13,13))
· text.str(string(12,4,"Press G:· "))
· kb.clearkeys
· OutA[noparse][[/noparse]Enable_Pin] := 1
· if kb.getkey == "g"···························································
····· OutA[noparse][[/noparse]Enable_Pin] := 0··· 'Enables RFID
····· Index := 0
····· Repeat 12················· 'Gets 12 bytes from RFID reader
······· Rx_Data[noparse][[/noparse]index++] := BS2.SERIN_CHAR(RX_Pin, 2400, BS2#NInv, 8)
· OutA[noparse][[/noparse]Enable_Pin] := 1··· 'Disables RFID
· Index := 0·
· text.Str(@RX_data)
· text.out(13)··
· BS2.PAUSE(1_000)···········
· Rx_data[noparse][[/noparse]9] := 0·········· ' mark end of string
· if strcomp(@Rx_data+4,@strConst)
··· text.str(string("Admitted",13))
· else
··· text.str(string("No admittance",13))
· text.str(string(12,6,"Press any key to continue",13))
· if kb.getkey
··· start1
···
DAT
strConst byte "50A2B",0
***************************************************
When I read the tag the VGA displays 414E50A2B but I still get a
"No admittance" response.· Have I overlooked something?
Sid
text.str(@RX_data+5)
and the VGA displayed E50A2B so I changed it to data+6 and it displayed
50A2B.· hoever, I was still getting "No admittance".· So....I changed
Rx_data[noparse][[/noparse]10] := 0
to read
Rx_data[noparse][[/noparse]11] := 0
and now it works!!· If I scan the right tag it says "Admitted".· If I scan any other tag it says "No admittance".
Now then I have to see if I can make it "admit" multiple tags.· Thank you very much, Mike.
Sid
Sid
PUB rfidpart
When I select this option from the menu, I read a tag.· The program compares it with (@tag1) and if it matches the VGA displays (@part1).·
(@part1) says:
Part is BS2 BOE - Value $40.00
If no match it compares it to (@tag2), and so on, displaying the appropriate (@partN). · If no match is found the VGA displays:
Part not found.
This frees up my BS2pe which I had been using to store my inventory, and a Super Carrier board.
Is it OK if I promote myself to First Class Junior Apprentice Propeller guru?
Sid
Sid
I·want to add a method to enter a part number, compare it to a DAT list, and if it is in stock display the quantity on hand.· I wrote:
**************************************************
PUB parts
··· text.str(string(12,4,13,"Enter part number",13))
··· index := 0
··· Repeat· 4········ 'Enter 2803
······· Parts_data[noparse][[/noparse]index++] := kb.getkey
··· Parts_data[noparse][[/noparse]index++] := 0
··· text.str(@parts_data)········'debugged entry displays 2803
··· if strcomp(@Parts_data,@stock1)
······· text.str(@stock1)
······· text.str(@stock1a)
······· text.str(string(12,6,13,"Press any key to continue",13))
······· if kb.getkey
········· start1
··· elseif strcomp(@Parts_data,@stock2)
······· 'text.str(@stock2)
······· text.str(@stock2a)
······· text.str(string(12,6,13,"Press any key to continue",13))
······· if kb.getkey
········· start1
*****************************************************
This works fine as long as I enter a 4-byte part number.· But since all part numbers are not 4 bytes, I tried to modify the above by terminating· the variable length with Enter:
****************************************************
PUB parts
··· text.str(string(12,4,13,"Enter part number",13))
··· index := 0
··· Repeat· while kb.getkey<>13·· 'Enter 2803 + Enter
······· Parts_data[noparse][[/noparse]index++] := kb.getkey
··· Parts_data[noparse][[/noparse]index++] := 0
··· text.str(@parts_data)······ 'debugged entry displays 83
··· if strcomp(@Parts_data,@stock1)
······· text.str(@stock1)
······· text.str(@stock1a)
······· text.str(string(12,6,13,"Press any key to continue",13))
······· if kb.getkey
········· start1
··· elseif strcomp(@Parts_data,@stock2)
······· 'text.str(@stock2)
······· text.str(@stock2a)
······· text.str(string(12,6,13,"Press any key to continue",13))
······· if kb.getkey
········· start1
***************************************************
As you can see, the entry skips the 1st, 3rd, 5th and so on byte, displaying only the even numbered bytes, which naturally returns a "Not in stock".· I know the problem is with the "repeat" command -· I just don't know how to overcome it.· I've tried every modification of repeat I can think of to no avail.
So who is going to rescue me this time?
Sid
You probably want something like this:
Looking at your code, you're going to get very tired of typing each case of a long parts table
as "elseif" statements with essentially the same action for each entry. This is a task for
superhero "table lookup"!
I tried to write a lookup routine to eliminate all the typing you referred to but I'm not haveing much luck.· Here is the DAT list I'm using:
stock1···· byte· "2803",0
stock2···· byte· "3624",0
stock3···· byte· "595", 0
stock1a··· byte· "· Qty is 3",0
stock2a··· byte· " 24-pin DIP - Qty is 0", 0
stock3a··· byte· " Shift register - Qty is 4",0
I was reading stock1 to get a match, then displaying stock1a·to·get the quantity on hand.· Do you have time to show me how to write a lookup routine that will match stock1, then display its companion stock1a.· If not, I can live with what I have so far.· Time consuming, but it works.
Sid
*****************************************************
PUB parts
··· text.str(string(12,4,13,"Enter part number",13))
··· index := 0
····· repeat while (temp := kb.getkey) <> 13
······· Parts_data[noparse][[/noparse]index++] := temp
····· Parts_data[noparse][[/noparse]index++] := 0
··· text.out(13)
··· len := index
··· index := 0
··· repeat until index == len - 1
····· if Parts_data == stock1
······· text.str(@stock1)
······· text.str(string(12,6,13,"Press any key to continue",13))
······· if kb.getkey
········· start1
····· elseif Parts_data == stock2
······· text.str(@stock2)
······· text.str(string(12,6,13,"Press any key to continue",13))
······· if kb.getkey
········· start1
····· elseif Parts_data == stock3
······· text.str(@stock3)
······· text.str(string(12,6,13,"Press any key to continue",13))
······· if kb.getkey
········· start1·····
····· else
······· text.str(string(13,"Not in stock",13))
······· text.str(string(12,6,13,"Press any key to continue",13))
······· if kb.getkey
········· start1
*****************************************************
I chnged my DAT list to:
stock1···· byte· "2803","· Qty is 3",0
stock2···· byte· "3624"," 24-pin DIP - Qty is 0",0
stock3···· byte· "595"," Shift register - Qty is 4", 0
******************************************************
now if I enter "595 + Enter" my VGA displays:
595 Shift register - Qty is 4
That simplifies things a bit.
Sid
The string comparisons are not working the way you think. You're comparing only the first byte of the entered
text to the first byte of the stock numbers. It seems to be working because they all start with different characters.
You've split the stock code and additional text into two strings, but there's no advantage. The compiler just
lays them out in successive memory locations. Did you want a zero byte at the end? You'll have to put one there
yourself.
Are all your part numbers numeric? Let me know either way and I'll see if I can make up a sample lookup routine.
Mike
Sid
stock1···· byte· "2803",0
stock2···· byte· "3624",0
stock3···· byte· "595",0
stock4···· byte· "12pf",0
stock5···· byte· "6pf",0
stock6···· byte· "LM340",0
stock7···· byte· "3640",0
stock8···· byte· "MCP23016",0
stock1a··· byte· "· Qty = 3",0
stock2a··· byte· " 24-pin DIP· Qty = 0",0·
stock3a··· byte· " Shift register· Qty = 4", 0··
stock4a··· byte· " Crystal for 1307· Qty = 1",0·
stock5a··· byte· " Crystal for 1302· Qty = 1",0·
stock6a··· byte· " 5V regulator· Qty = 2",0
stock7a··· byte· " 40-pin DIP· Qty = 1",0 |
stock8a··· byte· " Port expander· Qty = 2",0
Sid
an example of the use of the @ and @@ operators, and stock quantities as numbers, not strings.
I haven't tested it yet, but it should work as written. Let me know if this helps.
Mike
PUB lookup(nameAddr, tblAddr) : index
Sid
change it to lookup1 or some such and change all references to it to the same.
dan
PUB readItem | p
· p := 0
· text.str(string(12,4,13,"Enter item name <",13))
· repeat until (buffer[noparse][[/noparse]p] := kb.getkey) == 13
··· text.out(buffer[noparse][[/noparse]p++])
· buffer[noparse][[/noparse]--p] := 0
· testRoutine(@buffer)
PUB testRoutine(nameAddr)
· index := lookup1(nameAddr,@itemNo)
· if index == -1
··· text.str(string("> Item not found"))
··· return
· text.str(string("> ",13))
· text.str(@@itemDesc[noparse][[/noparse]index])
· text.str(string(", "))
· if itemStock[noparse][[/noparse]index] == 0
··· text.str(string(" out of stock"))
· else
··· text.dec(itemStock[noparse][[/noparse]index])
··· text.str(string(" items in stock"))
· text.str(string(12,6,13,"Press any key to continue",13))
····· if kb.getkey
······· start1
PUB lookup1(nameAddr, tblAddr)' : index
· repeat until byte[noparse][[/noparse]tblAddr] == 0
··· if strcomp(nameAddr,tblAddr)
····· return
··· index++
··· tblAddr += strsize(tblAddr) + 1
· return -1
The DAT lists were copied and pasted from your program.
Sid
·····························
Sid
because if you did, and you did not initialize index to 0 , the following line
index++ would leave you with unexpected results i think...
would be better to sub index_local like this
PUB lookup1(nameAddr, tblAddr) : index_local
repeat until byte[noparse][[/noparse]tblAddr] == 0
if strcomp(nameAddr,tblAddr)
return
index_local++
tblAddr += strsize(tblAddr) + 1
return -1
because you would be refering to a different index....
sorry if i'm butting in
dan
Sorry for the bugs. The problem is actually in the input routine. It was stuffing the zero on top of the last character
in the string instead of on top of the 13. The attached works on my Propeller Demo Board.
This means that if I want to check a part I will have to go to the DAT list, count down to see what Item No it is, then enter that.· Is there any way to change it so I can search by part name instead of Item No?· I could always put a comment alongside each Item No to indicate what part it is but I would still have to refer to the DAT list each time I wanted to check something.
Sid
I assumed you'd use the part number for the actual item name. Now you've got an item name, an item description, and a stock count that you can do arithmetic on. You can add a command to increase the stock and decrease the stock (checking for zero).
Hoo boy! What's next? Maybe you'll have to add some hardware for memory to save the inventory numbers!
Post Edited (Mike Green) : 8/29/2006 1:25:09 PM GMT
item0Desc byte "Shift register· Qty 4",0
and then disabled the lines that read the ItemStock quantity, so now when I enter 595 the VGA displays:
Shift register· Qty = 4
When I start the actual inventory listing, I'll keep my eye on Stack/Free to see how much memory I'm using.· If I get in a bind I could serout the data to the Stamp and have the Stamp store it in my AT45 4MB EEPROM.
Thanks for all your help, Mike.· My Propeller program is getting very efficient.
Sid
item1Desc byte "ULN2803 Digi 497-2356-5",13,"8-channel Darlington DIP·Qty 2",0
Now if I enter 2803 the VGA displays:
ULN2803 Digi 497-2356-5
8-channel Darlington DIP Qty 2
Pretty neat, huh?
Sid
itemDesc· word· @item0Desc, @item1Desc, @item2Desc, @item3Desc
Thise four entries take up 46 columns.· By the time I enter 40 items, I will have used 1840 columns and I don't even know if there are that many available.· I could probably modify the program so that if there was no hit
on itemDesc I could go to itemDesc1 and repeat the process, but it seems it would be a lot easier if it could just be bypassed.
Sid
You call "locate(index,@itemDesc0)" and this returns the address of the descriptor string for the item whose index is in "index". The descriptor strings have to be in order by index and there needs to be an extra zero byte at the end (to catch errors). The descriptor table looks just like the item name table in format.
Sid