Пример #1
0
static PyObject *
Reader_write(Reader *self, PyObject *args, PyObject *kwds)
{
    char* epc_data;
    char* epc_target;
    TMR_Status ret;
    TMR_TagData data;
    TMR_TagData target;
    TMR_TagFilter filter;
    // Read call arguments.
    static char *kwlist[] = {"epc_target", "epc_code", NULL};
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss", kwlist, &epc_target, &epc_data))
        return NULL;
    /* build target tag to search */
    target.epcByteCount = strlen(epc_target) * sizeof(char) / 2;
    TMR_hexToBytes(epc_target, target.epc, target.epcByteCount, NULL);
    /* build data tag to be writen */
    data.epcByteCount = strlen(epc_data) * sizeof(char) / 2;
    TMR_hexToBytes(epc_data, data.epc, data.epcByteCount, NULL);
    // Build filter target tag to be replaced.
    TMR_TF_init_tag(&filter, &target);
    // Write data tag on target tag.
    ret = TMR_writeTag(&self->reader, &filter, &data);
    // In case of not target tag found.
    if (ret == TMR_ERROR_NO_TAGS_FOUND)
        Py_RETURN_FALSE;
    Py_RETURN_TRUE;
}
Пример #2
0
 /*
  * First version, based on api samples. Safer one
  * 
  * 
  **/
int writeTagOLD(int readerId, uint8_t newEpcData[], uint8_t epcBytes)
{
    int error;
    uint8_t epcData[] = {
      0x01, 0x23, 0x45, 0x67, 0x89, 0xAB,
      0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67,
      };
    TMR_TagData epc;
    TMR_TagOp tagop;

	error=checkError(TMR_stopReading(readers[readerId]), "Stopping reader before tag writting");


	/* Set the tag EPC to a known value*/
    epc.epcByteCount = sizeof(epcData) / sizeof(epcData[0]);
    memcpy(epc.epc, epcData, epc.epcByteCount * sizeof(uint8_t));

    error=checkError(TMR_TagOp_init_GEN2_WriteTag(&tagop, &epc), "initializing GEN2_WriteTag");
    error=checkError(TMR_executeTagOp(readers[readerId], &tagop, NULL, NULL), "executing GEN2_WriteTag");

	if (!error)
    {
			printf("Tag has now a known value................................................................\n");
	} else
	{
		printf("CANNOT set tag to known value\n");
		return error;		
	}
	
    int i;
	printf("New tag id to write is: [");
	for (i=0;i<12;i++)
	{
		printf("0x%02X",newEpcData[i]);
		if (i<11) printf(", ");
	}
    printf("]\n");

    if (!error)
    {  /* Write Tag EPC with a select filter*/	  
	  TMR_TagFilter filter;
	  TMR_TagData newEpc;
	  TMR_TagOp newtagop;

	  // This should work... but it does not
	  //newEpc.epcByteCount = sizeof(newEpcData) / sizeof(newEpcData[0]);
	  newEpc.epcByteCount = epcBytes;
      memcpy(newEpc.epc, newEpcData, newEpc.epcByteCount * sizeof(uint8_t));
	  
	  printf("We are about to write %d bytes \n",newEpc.epcByteCount);
	  printf("Size of newEpcData %lu\n",sizeof(newEpcData) );
	  printf("Size of newEpcData[0] %lu\n", sizeof(newEpcData[0]));
	  
	  
	  /* Initialize the new tagop to write the new epc*/	   
	  error=checkError(TMR_TagOp_init_GEN2_WriteTag(&newtagop, &newEpc), "initializing GEN2_WriteTag");

          /* Initialize the filter with the original epc of the tag which is set earlier*/
	  error=checkError(TMR_TF_init_tag(&filter, &epc), "initializing TMR_TagFilter");

	  /* Execute the tag operation Gen2 writeTag with select filter applied*/
	  error=checkError(TMR_executeTagOp(readers[readerId], &newtagop, &filter, NULL), "executing GEN2_WriteTag");
	  
	  error=checkError(TMR_startReading(readers[readerId]), "Starting reader");

	}
	return error;
  }