-
Posts
6 -
Joined
-
Last visited
Everything posted by blasata
-
Mod() and Bitwise operations on 64-bit integers
blasata replied to jchd's topic in AutoIt Example Scripts
At last one right function for me! Thank you! With other functions for BigNum that I found the display was wrong (like 9.9997e10 etc) (I want to convert 0x002386F26FC0FFFF and show 9999999999999999 (16 digit) ) -
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.
-
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..
-
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...
-
Hi, at the end and because there are not much time, I put the C function into a dll . It is about 0.5MB in zip format, too big to attach, if anybody wants it, let me know. It is working, but I would like the other way.. Regards
-
Hello every body, I'm a total begginner in AutoIt and here is my first post. Hope could help me. I have searched for all the forum about CRC, also trying to translate codes from VB to Autoit but nothing give me the right result. I'm trying to take the CRC CCITT with poly 0x1021 in AutoIT. The string is 0005FE0005. CRC must be FA40. To check I'm using this web site: http://www.lammertbies.nl/comm/info/crc-calculation.html I have it working on C, and is ok. Here is: static void init_crcccitt_tab( void ) { int i, j; unsigned short crc, c; for (i=0; i<256; i++) { crc = 0; c = ((unsigned short) i) << 8; //printf("i vale %i y c es: %i y ",i,c); for (j=0; j<8; j++) { if ( (crc ^ c) & 0x8000 ) { crc = ( crc << 1 ) ^ P_CCITT; } else { crc = crc << 1; } c = c << 1; } crc_tabccitt[i] = crc; //printf("y el tab es %i\n",crc); escribetragados(crc); } crc_tabccitt_init = TRUE; } /* init_crcccitt_tab */ unsigned short update_crc_ccitt( unsigned short crc, char c ) { unsigned short tmp, short_c; short_c = 0x00ff & (unsigned short) c; printf("short_c es %i y c es %i:\n",short_c,c); if ( ! crc_tabccitt_init ) init_crcccitt_tab(); tmp = (crc >> 8) ^ short_c; printf("tmp es %i:",tmp); crc = (crc << 8) ^ crc_tabccitt[tmp]; printf("y crc es %i:\n",crc); return crc; } char *ptr, *dest, hex_val, prev_byte; unsigned short crc; char tmp[10]; ptr = calcula; dest = calcula; while( *ptr && *ptr != '\r' && *ptr != '\n' ) { if ( *ptr >= '0' && *ptr <= '9' ) *dest++ = (char) ( (*ptr) - '0' ); if ( *ptr >= 'A' && *ptr <= 'F' ) *dest++ = (char) ( (*ptr) - 'A' + 10 ); if ( *ptr >= 'a' && *ptr <= 'f' ) *dest++ = (char) ( (*ptr) - 'a' + 10 ); ptr++; } * dest = '\x80'; *(dest+1) = '\x80'; crc = 0xffff; prev_byte = 0; ptr = calcula; while ( *ptr != -128 ) { hex_val = (char) ( ( * ptr & '\x0f' ) << 4 ); hex_val = hex_val | (char) ( ( *(ptr+1) & '\x0f' ) ); printf("crc vale %i y hexval es %i",crc,hex_val); crc = update_crc_ccitt( crc, hex_val ); prev_byte = hex_val; ptr += 2; } sprintf(tmp, "%X", ~crc); 1. The translate of init_crcccitt_tab function is Func init_crcccitt_tab($Poly = 0x1021) Local $c, $crc, $i, $j For $i = 0 To 255 $crc = 0 $c = BitRotate($i,8) For $j = 0 To 7 If BitAND( BitXOR($crc, $c), 0x8000) Then $crc = BitRotate($crc,1) $crc = BitXOR($crc, $Poly) Else $crc = BitRotate($crc,1) EndIf $c = BitRotate($c,1) Next $crc_tabccitt[$i] = $crc Next $crc_tabccitt_init = True EndFunc ;==>crcInit It gives me only the first 15(of 256) element of the table with the correct value. The other are a little wrong. Ok, to resolve this I put in AutoIt the table directly with correct values from C program. Like this: Global $crc_tabccitt[256]=[0,4129,8258.......... It is solved. 2. But the other functions are not working like in C. Here is the translate to AutoIt: Func update_crc_ccitt($crc, $c ) Dim $tmp, $short_c $short_c = BitAND(0x00ff, $c) $tmp = BitXOR(BitRotate($crc, -8), $short_c) $crc = BitRotate($crc, 8) $crc = BitXOR($crc , $crc_tabccitt[$tmp] ) return $crc EndFunc Dim $ptr[10], $dest[10], $hex_val, $prev_byte Dim $crc,$tmp[10],$k=0 $ptr = $calcula $dest = $calcula While( Asc($ptr[$k]) AND Asc($ptr[$k]) <> '\r' AND Asc($ptr[$k]) <> '\n' ) If ( Asc($ptr[$k]) >= '0' AND Asc($ptr[$k]) <= '9' ) Then $dest[$k+1] = ( ($ptr[$k]) - '0' ) EndIf If ( Asc($ptr[$k]) >= 'A' AND Asc($ptr[$k]) <= 'F' ) Then $dest[$k+1] = ( ($ptr[$k]) - 'A' + 10 ) EndIf If ( Asc($ptr[$k]) >= 'a' AND Asc($ptr[$k]) <= 'f' ) Then $dest[$k+1] = ( $ptr[$k] - 'a' + 10 ) EndIf $k=$k+1 WEnd $dest[$k] = -128 ; I founf that '\x80' in C is equal to -128 $k=$k+1 $dest[$k] = -128 $crc = 0xffff $prev_byte = 0 $ptr = $calcula $k=0 While ( $ptr[$k] <> -128 ) $hex_val = BitRotate(BitAND($ptr[$k],15),4) $hex_val = BitOR($hex_val, BitAND($ptr[$k+1],15)) $crc = update_crc_ccitt( $crc, $hex_val) $prev_byte = $hex_val $k = $k + 2 WEnd $crc = StringRight(Hex($crc-2*$crc), 4) ; It is to have the 2Complement MsgBox(0,"kk","CRC must be FA40. The result is :" & $crc) Please could somebody take a look and see what in the translate is wrong. Thanks all !