Jump to content
Sign in to follow this  
blasata

function problem

Recommended Posts

blasata

Hi partners, I'm a little confused about the functions in autoIt. I think it is not working ok. My function are:

Global $dll, $SN[10], $num_TAGS

;fucntion to interrogate a RFID reader, it gives me how many TAGS there are and in SN[] I will have the SerialNumber of every one.
Func Interroga()
    Local $cad=""
    _CommSendByte(214,0)
    _CommSendByte(0,0)
    _CommSendByte(5,0) 
    _CommSendByte(254,0) 
    _CommSendByte(0,0) 
    _CommSendByte(5,0) 
    $cad = rec()
    $num_TAGS = StringMid($cad,16,1)
    If $num_TAGS=0 Then 
        Return 0
    Else 
        For $i = 0 to $num_TAGS-1 Step 1
            $SN[$i]= StringMid($cad,17+16*$i,16)
        Next
        Return 1
    EndIf
        
    EndFunc

;this is to activate every TAG in SN[].
Func activarArray()
        For $i=0 to $num_TAGS-1 Step 1
            Sleep(50)    ; Important
            $return = DllCall ( $dll, "int", "calcCRC", "str", "000C09" & $SN[$i] & "DA")
            ;Here I prepare every command to send to every TAG RFID (with SN=SerialNumber from function Interroga())
                        $bBinData = Binary("0x" & "D6000C" & $SN[$i] & "DA" & Hex($return[0],4) )
            $iNumbytes = BinaryLen($bBinData)
            $tBinData = DllStructCreate("byte["&$iNumbytes&"]")
            DllStructSetData($tBinData, 1, $bBinData)
            $iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1)
            If @error Or $iRet = -1 Then ConsoleWrite("!Error: " &  @error & @CRLF)
        Next
    EndIf           
EndFunc 



;*******************And then in the main loop, I will look for TAGS, If there are not, I will interrogate again, if there are, I will activate them
While (1)
    Slee(100)
    $retIn=Interroga()
        ;MsgBox(0,"","retIn:" & $retIn & "and numTAGS: " & $num_TAGS)
    If $retIn<>0 Then   ; If there are TAGS, activate it
       activarArray()  
        EndIf
WEnd

The problem is that when I put the reader near the TAGS and then I put the reader far away...the program keep trying to activate...but there are no TAGS phisicaly..but the function interroga() gives me a number>0, what is impossible.

The problem is solved if I comment activarArray(). But Why!? :)

Why with this function the software see(or remember?) TAGS when there are not?

Please help... ;)

Share this post


Link to post
Share on other sites
enaiman

For some reason your $num_TAGS is never equal to 0 - check the string you receive and the 16th character in that string.

Put a messagebox after you get the value for $num_TAGS to show you the value for your $cad and $num_TAGS.

If $num_TAGS is never 0 - your interroga() function will always return 1.

Do a little bit of debugging and you'll figure what is going wrong.

Slee(100)
how does that work for you??

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
blasata

ok sorry Slee is Sleep.

And, yes, I have done to put a msgbox and see the value returned, it is "1", should be "0"

The way that I have found at last is add this new function. The same as interroga() but with no extraction of the SN[] information, just how many.

Func verTAGS_return()
            _CommSendByte(214,0)
            _CommSendByte(0,0)
            _CommSendByte(5,0) 
            _CommSendByte(254,0) 
            _CommSendByte(0,0) 
            _CommSendByte(5,0) 
            _CommSendByte(250,0) 
            _CommSendByte(64,0)
            $cad = rec()
            $cad = StringMid($cad,16,1) ;how many
            Return $cad
EndFunc

iniside of Func activarArray() in this way:

Func activarArray()
    $num_TAGS= verTAGS_return()
    
            For $i=0 to $num_TAGS-1 Step 1
              Sleep(50)    ; Importante
              activa($SN[$i])
           Next
    
EndFunc

Then, the program stops of trying to activate TAGS (because there are not) when put the reader away.

But it is very strange.

Other of my attempt before was this:

Func activarArray()
    interroga()
    If $num_TAGS>0 Then
            For $i=0 to $num_TAGS-1 Step 1
              Sleep(50)    ; Importante
              activa($SN[$i])
           Next
        EndIf
    
EndFunc

But fail too. :)

Very strange this AutoIt...The original program in C works, but now the people above me said that I have to do in AutoIt, so,..

I'm becaming a little angry with it, it is the second strange problem I have with..

Share this post


Link to post
Share on other sites
enaiman

I don't really understand what is the meaning of:

when I put the reader near the TAGS and then I put the reader far away

but anyway.

I think the problem here is $num_TAGS is never 0 and that could be because you are reading the wrong character from your string. Are you sure the correct reading is the 16th character from whatever you receive??

If you have read my previous post more attentively you would have noticed:

Put a messagebox after you get the value for $num_TAGS to show you the value for your $cad and $num_TAGS.

So - use this messagebox to check the whole info:

Msgbox(0, "", "$cad = "&$cad&", $num_TAGS = "&$num_TAGS)

When the messagebox shows - count the characters to see if the result is accurate. Also something to keep in mind: AutoIt:

start The character position to start. (1 = first character)

; if you have translated the script from other programing language, that one might have a different start (position for first character is 0).

Well, I am 99% sure that the error is here:

$num_TAGS = StringMid($cad,16,1)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
blasata

Well, I am 99% sure that the error is here:

$num_TAGS = StringMid($cad,16,1)

Hi, sorry my level english is very poor I think..

Thanks man. :) You were right. Then reader (an antenna) send a ACK command for every command I send, so I take one of this (thinking that it will be a response with the number of tags inside) as the command to take the num_TAGS, but I was wrong, I have to wait until the reader finish to send ACKs. I solved like this

Do
   $cad = rec()   
Until StringMid($cad,7,2)="FE"  ;FE is the command response and will contain the num_TAGS.

It works very fine. ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.