Shop OBEX P1 Docs P2 Docs Learn Events
String and array — Parallax Forums

String and array

hooktxuhooktxu Posts: 33
edited 2009-06-17 07:25 in Propeller 1
I want to pass an array to a string.
My piece of code is the next and the only thing missing is that the tag is a string.

id12.readRFID
repeat i from 0 to 15
tag:=id12.rValue(i)
''tagNum:=

Comments

  • hooktxuhooktxu Posts: 33
    edited 2009-06-08 09:36
    id12.readRFID
    ____repeat i from 0 to 15
    ______tag[noparse][[/noparse] i ]:=id12.rValue(i)
    ______'tagNum:=
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-08 12:29
    You should be more exact in your problem description ... and better use more words then less!

    I don't understand what your problem is currently, so I guess:

    You can not pass an array to the string() SPIN command, as it is -like the constant() command- something which is only relevant at compile-time. string() reserves some memory for the string given as argument and uses it's adress in the instruction in which string is involved.
    If your array already contains characters, then you can simply add a string terminator ( $0 ) and you can treat it like a string.
  • hooktxuhooktxu Posts: 33
    edited 2009-06-09 09:19
    tag[noparse]/noparse is an array and i want to pass it to a string, and then compare with another string with this method: strcomp.
    Is it possible?
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-09 10:10
    A string is nothing else than an array of bytes where after the last element of the string a 0 is used to terminate.

    var byte tag[noparse][[/noparse] 10 ]
    pub main
    tag[noparse][[/noparse] 0 ]:='T'
    tag[noparse][[/noparse] 1 ]:='E'
    tag[noparse][[/noparse]·2 ]:='S'
    tag[noparse][[/noparse]·3 ]:='T'
    tag[noparse][[/noparse]·4 ]:= 0

    is in terms of the content the same as

    dat
    tstr byte "TEST",0


    and for example

    strcmp( @tag, string("TEST") )
    strcmp( @tstr, string("TEST") )
    strcmp( @tag, @tstr )

    should all give you the same result.

    If you use string("xx") with the same string inside, it is better to use a dat-section, as it saves space and can be used as often as you want whereas string() will produce several sections in the memory even if the string is the same.

    So, in your case you should simply make sure that after the·last character in you array·there is really a 0 and then you can use strcmp with the array directly.
  • hooktxuhooktxu Posts: 33
    edited 2009-06-10 08:55
    But i want to compare these strings:
    aplicacionTwitter:= string("01072176AEFF")
    tagNum:=serialPC.tx(tag)

    strcomp(tagNum,aplicacionTwitter)

    is it correct?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-10 10:29
    1) "serialPC.tx(tag)" transmits the character "tag". It doesn't receive.

    2) The Extended FullDuplexSerial object (obex.parallax.com/objects/31/) has a routine to receive a sequence of characters into a byte array (RxStr). You can use any termination character you want (like a return - $0D - the default). The string is stored temporarily in a variable inside the object that can hold up to 15 characters. Parallax's RFID reader sends the bytes $0A,"0","1","0","7","2","1","7","6","A","E","F","F",$0D. RxStr replaces the $0D with the zero byte that terminates the string. You could do:
    OBJ serialPC : "ExtendedFDSerial"
    
    VAR byte buffer[noparse][[/noparse]16]
    
    ...
       serialPC.RxStr(@buffer)  ' Read in the tag information.  The first byte is $0A.
       aplicacionTwitter := string("01072176AEFF")
       if strcomp(@buffer+1,aplicacionTwitter) ' Compare starting after the $0A
          ' success
    
  • hooktxuhooktxu Posts: 33
    edited 2009-06-11 08:40
    serialPC.Start(31,30,0,9600)???
  • hooktxuhooktxu Posts: 33
    edited 2009-06-11 09:24
    I do this:

    VAR
      byte tag[noparse][[/noparse]16]
    
    OBJ
      serialPC:"Simple_Serial"
      duplex: "Extended_FDSerial"
    
    PUB Main
      serialPC.init(-1,30,9600)
      duplex.Start(31,30,0,9600)
    
      id12.readRFID
          repeat i from 0 to 15
            tag[i]:=id12.rValue(i)
            serialPC.tx(tag[noparse][[/noparse] i ])
    
      duplex.RxStr(@tag)
      if strcomp(@tag+1,@Str1)
    [/i]
    



    and it doesn´t work

    Post Edited (hooktxu) : 6/11/2009 10:22:12 AM GMT
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-11 11:43
    Why do you use 2 drivers for 1 serial port? The full duplex driver can do both, send and receive (or the extended full duplex in your case).

    I don't know the extended full duplex yet, but in your case you need to be sure that the buffer is big enough, because you first send out 15 characters after that you receive. So the buffer must be at least 15 bytes big.

          repeat i from 0 to 15
            [color=red]tag[/color][i][color=red]:=[/color]id12.rValue(i)
            serialPC.tx(tag[noparse][[/noparse] i ])
    [/i]
    

    ·Is this correct? I don't know the id12 object, but it looks like you get the RFID bytewise with the rValue(i) where i is the number of the byte. But you always store it in tag, which is equal to tag[noparse][[/noparse]0]. I guess you should say

    tag[noparse][[/noparse]i]:=id12.rValue(i)




    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-11 14:59
    We are working here without enough information. Please describe your system. Describe overall what you are trying to do. If you are using Parallax's RFID reader, it's enough to say that. If it's some other device, give details and provide a link to a datasheet. Give examples of what the PC is doing including sample messages. Show the delimiters coming from the PC (like carriage return and line feed if present). Have you checked to make sure the PC is sending the information you expect?
  • hooktxuhooktxu Posts: 33
    edited 2009-06-17 07:24
    I read a RFID and I want to compair it with another string. This is my main:

    [code]

    CON

    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000

    VAR

    byte tag[noparse][[/noparse]16]
    byte i
    byte idPB
    byte idOverlay
    byte tipoFuente
    byte datoEvento
    byte accion
    byte aplicacionTwitter
    byte aplicacionMaquinas
    byte tagNum[noparse][[/noparse]16]
    byte tagEstado
    long A

    OBJ
    sensorToq : "SensorToque"
    sensorMagnetico : "SensorMagnetico"
    id12: "RFID"
    id12accion: "RFIDaccion"
    ''iwifi: "iWiFiXXX"
    serialPC:"Simple_Serial"
    duplex: "Extended_FDSerial"
    'serialPC: "Extended_FDSerial"
    DAT
    Str1 word "01072176AEFF", 0 'Aplicacion Twitter
    Str2 word "0107216B1B57", 0 'Aplicacion Maquinas
    Str3 word "010721924CF9", 0 'Tag de estado

    PUB Main


    idPB:=1
    idOverlay:=0
    tipoFuente:=0
    datoEvento:=0
    accion:=0
    'tagNum:=string("01072176AEFF")

    aplicacionTwitter:= string("01072176AEFF")
    'aplicacionMaquinas:= string("0107216B1B57")
    'tagEstado:= string("010721924CF9")

    serialPC.init(-1,30,9600)
    duplex.Start(31,-1,0,9600)
    sensorToq.arrancar

    waitcnt(clkfreq*2 + cnt)


    repeat

    serialPC.str(string("Decision de la aplicacion: "))

    id12.readRFID
    repeat i from 0 to 15
    tag:=id12.rValue(i)
    serialPC.tx(tag)


    serialPC.str(string("Lectura del RFID correcto"))

    {{repeat i from 1 to 12
    tagNum:=serialPC.tx(tag)
    serialPC.tx(tagNum)
    serialPC.str(string("Pasa a String el RFID")) }}

    repeat i from 1 to 12
    serialPC.tx($0A)
    serialPC.tx($0D)
    serialPC.tx(tag)

    serialPC.str(string(" Vamos a comparar los strings "))
    'serialPC.str(string(" TagNum: "))
    'serialPC.str(tagNum)
    serialPC.str(@tag) 'Imprime el contenido del tag

    bytemove(tagNum,@tag+1,12)

    serialPC.str(@tagNum)

    'duplex.RxStr(@tag)

    serialPC.str(string(" LLega "))

    if strcomp(tagNum,@Str1) ''Aplicacion Twitter
    serialPC.str(string("Entra en el primer if"))
    idOverlay:= 1
    tipoFuente:= 1 ''Solo tenemos un tipo de dispositivo, que son los sensores magn
  • hooktxuhooktxu Posts: 33
    edited 2009-06-17 07:25
    It doesn´t work because it doesnt do this sentence:
    duplex.RxStr(@tag)
Sign In or Register to comment.