Вы находитесь на странице: 1из 23

API Calling Quick Start

SAAT-800 Series Reader

Version: V2.0.0
Dear Customers:

Thanks for your trust and support! We try best to provide you comprehensive service and technical
support.

This manual will introduce How to use API of SAAT-800 series Reader, so that your integrated software
can communicate, configure reader parameter, control the command of reader reading tags, and
information of tags returned. Please consult our technical support if you have problems of using products.
Welcome to contact us for any feedback and suggestion.
This manual is suitable for the following readers:

SAAT-800 Series Reader

The manual is supposed that the user already owns basic RFID and computer knowledge, so that related
terms such as RFID, RF and Ethernet is not described in details, the users can search and inquire
reference, or consult our technical department.

There are some signs with the following definitions:

Warning

If violate the signed operation method or usage environment, which will do damage to health or
devices.

Advice

It will come to better effect according to the signed method.


Table of Contents

Part I The Methods of Calling API ........................................................ 1

1 User Environmental Requirements........................................................................ 1

2 Files........................................................................................................................ 1

3 API Calling Methods .............................................................................................. 1

Part II Connect Reader .......................................................................... 2

1 Using Ethernet to Connect .................................................................................... 2

1.1 Initial Ethernet(TCP) Connection:................................................................................... 2

1.2 Open Reader:................................................................................................................. 2

2 Connecting via COM Port ...................................................................................... 3

2.1 Initial COM Port Connection: .......................................................................................... 3

2.2 Open Reader:................................................................................................................. 3

Part III 6C Tag Operation ....................................................................... 5

1 Read EPC code ..................................................................................................... 5

1.1 Send "Read EPC Code" Command: .............................................................................. 5

1.2 Receive EPC code in Circle ........................................................................................... 5

2 Write EPC Code..................................................................................................... 7

3 Read 6C Tag User Bank ........................................................................................ 8

4 Write 6C Tag User Data ......................................................................................... 9

5 Read TID Code .................................................................................................... 11

5.1 Send the Read TID Code Command: .......................................................................... 11

5.2 Receiving TID Code in Turn ......................................................................................... 12

Part IV 6B Tag Operation .................................................................... 14

1 Read UID Code.................................................................................................... 14

I
1.1 Send "Read UID Code" Command: ............................................................................. 14

1.2 Receive UID code in loop ............................................................................................. 14

Part V Stop Reading ............................................................................ 16

1 Stop the Reading Command ............................................................................... 16

Part VI Disconnect Reader ................................................................. 17

Part VII Get Error Message ................................................................. 18

II
Part I
The Methods of Calling API

1 User Environmental Requirements


User has to provide the following environments to call API functions:

Computer Configuration: PIII 600MHz,128M Memory,Windows XP/2003 Operation Systems, etc.

2 Files
API Functions including the following files:

 RFIDAPI.dll

 RFIDAPI.lib

 RFIDAPIEXPORT.h

3 API Calling Methods


Add the API function files which are mentioned in 2 to project and add #include "RFIDAPIEXPORT.h" to
source codes; then user can call the functions in it directly.

1
Part II
Connect Reader

1 Using Ethernet to Connect


Before operating on reader, user has to connect reader first.

1.1 Initial Ethernet(TCP) Connection:


//1.1 TCP Parameter Initialization

//Function: upload through parameter, this function is used for the ethernet app. configuration of computer and

initialling a SOCKET, to prepare for the connection based on Ethernet port.

//Parameter:

// pHandle the preservation of opening ports handle

// pHostName Reader IP address, available only under Ethernet communication mode

// nsocketPort Internet SOCKET port, default as 7086

//Return Value: true operation succeeded; false operation failed;

bool SAAT_TCPInit (void** pHandle,char *pHostName,int nsocketPort)

For example, the IP of reader is 192.168.0.238, port is 7086, call the function as below:

HANDLE hp;

if(!SAAT_TCPInit(&hp,”192.168.0.238”,7086) )

printf("Failed to initial reader!\n");

return false;

1.2 Open Reader:


//1.4 Open Reader

//Function: create connection based on COM Port, USB or Ethernet, or any other expansion port.

//Parameter:

// pHandle initialled port handle

// Return Value: true operation succeeded; false operation failed;

bool SAAT_Open(void* pHandle)

Using method as below:

2
if(!SAAT_Open(hp))

printf("Failed to open reader!\n");

return false;

2 Connecting via COM Port

2.1 Initial COM Port Connection:


//1.2 COM parameter initialization

//Function: upload through parameter and initial COM, preparing to connection

//Parameter:

// pHandle the preservation of opening ports handle

// nBusAddr Bus address, default as 0x00

// pComNum COM1-COM4, only available under COM communication mode

// nBaud COM port(USB)communication speed, default as 19200

//Return Value: true operation succeeded; false operation failed;

bool SAAT_COMInit(void** pHandle,unsigned char nBusAddr,char *pComNum, int nBaud )

For example, using COM1 to connect reader, call functions as below:

HANDLE hp;

if(!SAAT_COMInit (&hp,0,”COM1”,7086) )

printf("Failed to initial reader!\n");

return false;

2.2 Open Reader:


//SAAT_Open open reader

//Function: create ethernet connection

//Parameter:

//pHandle the preservation of opening port handle

//Return Value: true operation succeeded; false operation failed;

bool SAAT_Open(void* pHandle)

3
Calling method as below:

if(!SAAT_Open(hp))

printf("Failed to open reader!\n");

return false;

4
Part III
6C Tag Operation

1 Read EPC code

1.1 Send "Read EPC Code" Command:


//3.2 send reader EPC code command

//Function: it is used to send "read EPC code" command

//Parameter:

// pHandle: the preservation of opening port handle

// nAntenna: the operating antenna code(0 antenna loop, 1 antenna1, 2 antenna2, 3 antenna3, 4 antenna4)

// nType: operation mode

// 00:for the tag EPC code, reader sends only once to host and requests host "return confirmation data".

// 01":reader uploads all the collected EPC code to host and doesn't request host to "return confirmation

data"; till host sends "close function" command the reader will stop reading EPC code; this operation mode is

commonly used.

// nTagCount: estimated simultaneous reading quantity; predict the required max. tag quantity in working

environment, designed as 250pcs while the real reading quantity is more than 500pcs.

//Return Value: true operation succeeded; false operation failed;

bool SAAT_6CReadEPCCode ( void *pHandle,unsigned char nAntenna, unsigned char nType, unsigned char

nTagCount)

Using antenna loop to reader EPC code:

unsigned char antenna = 0x00;

if(!SAAT_6CReadEPCCode(hp,antenna,0x01,1))

printf("Failed to send Read Tag command!\n");

return false;

1.2 Receive EPC code in Circle

5
//3.3 Receive EPC code command

//Function: this function is used for receiving the EPC code returned from reader; there may be multiple EPC codes

are returned.

//Parameter:

// pHandle the opening port handle

// nAntenna the antenna port no. which has got EPC code

// pEPCData returned EPC code data from reader

// nEPCLen incoming, it's length of pEPCData; outgoing, it's length of EPC data, usually is 12.

//Return Value: 1: Operation Succeed; 0: Operation Failed; 2: reader returned HR package

int SAAT_6CRevEPCMsg (void *pHandle, unsigned char* nAntenna, unsigned char* pEPCData, unsigned char*

nEPCLen)

Calling method as below:

unsigned char pEPCData[200];//receiving buffer area

unsigned char pEPCLength = 200; //length of receiving buffer area

while(true)//receiving tag ID in loop

ZeroMemory(pEPCData,200);

int readEPCSucceed=SAAT_6CRevEPCMsg(hp,&antenna,pEPCData,&pEPCLength);

printf("read tag and return:%d,length:%d\n",readEPCSucceed,pEPCLength);

if(1 == readEPCSucceed)

printf("reader EPC code: \n");

for( int i = 0 ; i < pEPCLength ;i ++)

printf("%02x",pEPCData[i]);

printf("\n");

Notice:

To receive tag please use thread to call, to avoid blocking host interface.

The receive tag thread should not occupy CPU; it's better that tag ID would be stored in buffer area first,
to avoid interfering reading efficiency.

6
2 Write EPC Code

Before writing EPC code, please connect reader first, using the following function:

//3.6 write EPC code

//Function: it's used for writing EPC code

//Parameter:

// pHandle the open port handle

// nAntenna the operating antenna port 1~4

// nType operation mode, default as 0x00

// pAccessPWD the access password for operating tag, default password is 4bytes 0

// pWriteData the data which is written in tag EPC code

// nLen length of the written tag EPC code

//Return Value: true operation succeeded; false operation failed;

bool SAAT_6CWriteEPCCode ( void* pHandle, unsigned char nAntenna, unsigned char nType, unsigned char

*pAccessPWD, unsigned char *pWriteData, unsigned char nLen )

For example, the written tag ID is 112233445566778899001122, using antenna1 to write and calling as

below:

CString m_szEpcData = "112233445566778899001122";

unsigned char btEpcCode[12];

int i = 0;int j = 0;

for (i=0,j=0;i<m_szEpcData.GetLength();i+=2,j++)//change the string array into byte array

CString szTmp = m_szEpcData.Mid(i,2);

sscanf_s(szTmp.GetBufferSetLength(2),"%02x",btEpcCode+j);

unsigned char btPsw[4]={0x00,0x00,0x00,0x00};

bRet = SAAT_6CWriteEPCCode ( hp, //the open reader link

0x01,//antenna port is 1

0x00,//operating mode default to write 0

btPsw, //default password is 4 bytes 0

btEpcCode,//the written byte arrays

m_szEpcData.GetLength()/2);//write in 12 bytes

if (bRet)

printf("Succeeded in writing");

7
}

else

printf("Failed to write");

3 Read 6C Tag User Bank

Before read 6C tag user bank, please connect the reader first; using the function:

//3.7 Read user bank

//Function: the function is used for reading ISO18000-6C tag user bank

//Parameter:

// pHandle the open port handle

// nAntenna the operating antenna port 1~4

// StartAddr start address of reading tag data bank

// nToReadLen the length of reading tag data bank, double word read/write, length is the read bytes,

and so on.

// nWaitTime read data time-out period (measured as ms, i.e. 1s=1000ms)

// UserData the read data bank data

// nDataLen incoming: length of UserData; outgoing: length of the read data bank

//Return Value: true operation succeeded; false operation failed;

bool SAAT_6CReadUserData ( void* pHandle,

unsigned char nAntenna,

unsigned int StartAddr,

unsigned int nToReadLen,

unsigned int nWaitTime ,

unsigned char * UserData,

unsigned char* pDataLen)

If using antenna1, start address 0 and read 2 double words data, read data time-out period 1s, then call

as below:

unsigned char btAntennaNum = 1;//use antenna1 to read

int nAddr = 0x00;//start from 0 to read

unsigned int nReadLen = 2;//data length of tag data bank, double words read/write, length is 1 and read 2 bytes, length

is 2 and read 4 bytes, and so on.

8
unsigned int nWaitTime = 1000;//read data time-out period(measured as ms, i.e. 1s=1000ms)

unsigned char UserData[9000] = {0};//the read data band data

unsigned int nRealRealLen = 9000;//incoming: length of UserData, outgoing: length of the read data bank

bool bRet = SAAT_6CReadUserData ( hp,

btAntennaNum,

nAddr,

nReadLen,

nWaitTime,

UserData,

&nRealRealLen);

if( bRet )

printf("Read succeeded, the read data is:");

for( unsigned int i = 0 ; i < nRealRealLen*2 ;i ++)

printf("%02x ",UserData[i]);

printf("\r\n");

else

CHAR szMsg[200] = {0};

SAAT_GetErrorMessage(hp,szMsg,200);//acquire error message

printf(szMsg);

4 Write 6C Tag User Data

Before writing 6C tag user data, please connect reader first; using the functions below:

//////////////////////////////////////////////////////////////////

//3.8 Write user data

//Function: use this function to write ISO18000-6C tag USER Bank Data

//Parameter:

// pHandle the open port handle

// nAntenna the operating antenna port 1~4

9
// nType operation type, it is 0

// pAccessPWD the access password for operating on tag, default password is 4-byte 0

// nStartAddr the start address of written data

// inWaitTime write data time-out period(measured as ms, i.e. 1s=1000ms)

// pWriteData the data which is written in tag user bank

// pToWriteLen incoming: length of user data which is written in tag; outgoing: real length of user data

which is written in tag, measured by word(double byte)

//Return Value: true operation succeeded; false operation failed;

bool SAAT_6CWriteUserData (void* pHandle,

unsigned char nAntenna,

unsigned char nType,

unsigned char *pAccessPWD,

unsigned int nStartAddr,

int nWaitTime,

unsigned char *pWriteData,

unsigned int *pToWriteLen)

If use antenna1, on start address 0 writing two double bytes data, time-out period for writing is 3s, call

functions as below:

unsigned char btAntennaNum = 1;//use antenna to write

unsigned char nType = 0; //operation type, here is 0

unsigned char nAddr = 0x00;//start from 0 address to write

unsigned char btTagPwd[4]={0x00};//default password is 4-byte 0

unsigned char nStartAddr = 0x00;//here is start address of written data

unsigned int nWaitTime =3000;//time when writing data(measured by ms, i.e. 1s=1000ms)

unsigned char pWriteData[4] ={0x22,0x22,0x22,0x22};//data which is written in user data

unsigned int pToWriteLen = 4;//incoming: length of the available for writing user data; outgoing: length of the real

written user data; measured by 'word' (double byte)

bool bRet = SAAT_6CWriteUserData(hp,

btAntennaNum,

nType,

btTagPwd,

nAddr,

3000,

pWriteData,

&pToWriteLen);

if (!bRet)

10
{

CHAR szMsg[200] = {0};

SAAT_GetErrorMessage(hp,szMsg,200);//acquire error message

printf(szMsg);

else

printf("write in succeeded\r\n");

5 Read TID Code

5.1 Send the Read TID Code Command:


//3.4 Read TID Code Command

//Function: used for reading TID code

// Parameter:

// pHandle the open port handle

// nAntenna the operating antenna no. (0 antenna loop, 1 antenna1, 2 antenna2, 3 antenna3, 4 antenna4)

// nType operating mode

// operating mode:

// 00:the reader uploads the same TID code to host only once, and requires host to "return confirmation

data"

// 01:the reader uploads all the read tag TID code to host without requiring host to "return confirmation

data", until host release "close amplifier" command the reader stops reading TID code.

//Return Value: true operation succeeded; false operation failed;

// nTagCount: estimated simultaneous reading quantity; predict the required max. tag quantity in

working environment, designed as 250pcs while the real reading quantity is more than 500pcs

bool SAAT_6CReadTIDCode ( void *pHandle,unsigned char nAntenna, unsigned char nType, unsigned char

nTagCount)

For example, read TID code by antenna loop:

unsigned char antenna = 0x00;

if(!SAAT_6CReadTIDCode(hp,antenna,0x01,1))

printf("Failed to send Reading Command!\n");

11
return false;

5.2 Receiving TID Code in Turn


//////////////////////////////////////////////////////////////////

//3.5 "Receive TID Code" Command

//Function: used to receive TID code

//Parameter:

// pHandle the open port handle

// nAntenna the antenna no. which reading TID code

// pTIDData the returned TID data from reader

// nTIDLen Incoming: length of pTIDData, outgoing: length of TID data

//Return Value: true operation succeeded; false operation failed;

int SAAT_6CRevTIDMsg (void *pHandle, unsigned char* nAntenna, unsigned char* pEPCData, unsigned char*

nEPCLen)

Calling method as below:

unsigned char pTIDData[200];//receiving buffer area

unsigned char pTIDLength = 200; //length of receiving buffer area

while(true)//receiving tag ID in turn

ZeroMemory(pTIDData,200);

int readTIDSucceed=SAAT_6CRevTIDMsg(hp,&antenna,pTIDData,&pTIDLength);

printf("read & return: %d,length:%d\n",readTIDSucceed,pTIDLength);

if(1 == readTIDSucceed)

printf("Read TID code is:\n");

for( int i = 0 ; i < pTIDLength ;i ++)

printf("%02x",pTIDData[i]);

printf("\n");

Notice:

12
To receive tag please use thread to call, to avoid blocking host interface.

The receive tag thread should not occupy CPU; it's better that tag ID would be stored in buffer area first,
to avoid interfering reading efficiency.

13
Part IV
6B Tag Operation

1 Read UID Code

1.1 Send "Read UID Code" Command:


//2.5 Read UID code command

//Function: send "Read UID code" command

//Parameter:

// pHandle the open port handle

// nAntenna antenna no. (0 antenna loop, 1 antenna1, 2 antenna2, 3 antenna3, 4 antenna4)

// nType Operation mode

// Operation mode:

// 00:for the tag UID code, reader sends only once of the same code to host and requests host "return

confirmation data".

// 01:reader uploads all the collected UID code to host and doesn't request host to "return confirmation

data"; till host sends "close function" command the reader will stop reading EPC code; this operation mode is

commonly used.

//Return Value: true operation succeeded; false operation failed;

bool SAAT_6BReadUIDCode (void *pHandle,unsigned char nAntenna,unsigned char nType)

For example, read UID code by antenna loop:

unsigned char antenna = 0x00;

if(!SAAT_6BReadUIDCode (hp,antenna,0x01))

printf("Failed to send "read tag" command!\n");

return false;

1.2 Receive UID code in loop


//////////////////////////////////////////////////////////////////

//2.6 Receive tag UID code

14
//Function: this function will start the operation to receive tag UID code returned from reader.

//Parameter:

// pHandle the open port handle

// nAntenna the antenna no. which reading UID code

// pUIDData the collected UID data

// nUIDLen incoming: length of pUIDData, outgoing: length of UID data

//Return Value: 1 operation succeeded; 0 operation failed; 2 the HR package which reader returns

int SAAT_6BRevUIDMsg (void *pHandle, unsigned char* nAntenna, unsigned char* pUIDData, unsigned char*

nUIDLen)

Calling as below:

unsigned char pUIDData[200];//receiving buffer area

unsigned char pUIDLength = 200; //length of receiving buffer area

while(true)//receiving tag ID in loop

ZeroMemory(pUIDData,200);

int readUIDSucceed=SAAT_6BRevUIDMsg(hp,&antenna,pUIDData,&pUIDLength);

printf("read and return:%d,length:%d\n",readUIDSucceed,pUIDLength);

if(1 == readUIDSucceed)

printf("read UID code is:\n");

for( int i = 0 ; i < pUIDLength ;i ++)

printf("%02x",pUIDData[i]);

printf("\n");

Notice:

To receive tag please use thread to call, to avoid blocking host interface.

The receive tag thread should not occupy CPU; it's better that tag ID would be stored in buffer area first,
to avoid interfering reading efficiency.

15
Part V
Stop Reading

1 Stop the Reading Command

Under reading status, if it is required to stop reading, call the following function:

//1.26 Stop Reading Command

//Function: this function is used to notify reader stop executing current running command.

//Parameter:

// pHandle the open port handle

//Return Value: true operation succeeded; false operation failed;

bool SAAT_PowerOff(void *pHandle);

16
Part VI Disconnect Reader
When it is required to disconnect reader, call the following function:

//1.5 Disconnect Reader

//Function: close connection with reader

//Parameter:

// pHandle the open port handle

//Return Value: true operation succeeded; false operation failed;

bool SAAT_Close(void *pHandle)

17
Part VII
Get Error Message
Use this function to acquire the error message which reader returns:

//1.27 get error message

//function: get error message

//parameter:

// pHandle the opening port handle

// szMsg return error message

// nLen szMsg length of buffer bank

//Return value: true operation succeeded; false operation failed;

bool SAAT_GetErrorMessage(void *pHandle,char *szMsg, int nLen);

Calling as following:

CHAR szMsg[200] = {0};

SAAT_GetErrorMessage(hp,szMsg,200);//get error message

18

Вам также может понравиться