MR6100 SDK (C#)
MR6100 SDK (C#)
1.Function
TcpConnectReader
MessageBox("success");
Else
MessageBox("fail");
OpenCommPort
baudrate parameter
MessageBox("success");
Else
MessageBox("fail");
TcpCloseConnect
N/A
Parameter
MessageBox("success");
Else
MessageBox("fail");
CloseCommPort
N/A
Parameter
N/A
Response
SetBaudRate
If(SetBaudRate(255, 115200)==2001)
Example
MessageBox("success");
Else
MessageBox("fail");
ResetReader
If(ResetReader(255)==2001)
Example
MessageBox("success");
Else
MessageBox("fail");
ResetParameter
If(ResetParameter (255)==2001)
Example
MessageBox("success");
Else
MessageBox("fail");
GetFirmwareVersion
SetRf
Function Describe public int SetRf(int readerAddr, int power1, int power2, int
MessageBox("success");
Else
MessageBox("fail");
GetRf
MessageBox("success");
Else
MessageBox("fail");
SetAnt
MessageBox("success");
Else
MessageBox("fail");
GetAnt
Function Describe public int GetAnt(int ReaderAddr, ref byte workAnt, ref byte
antState)
Get reader current available open antenna number and antenna
Function
connection status
Paramter Parameter signficance, scope
Parameter
ReaderAddr Reader address , for fixed reader compose
RS485 network use,default 0XFF(handheld
reader and module not applicable)
workAnt The opening of the antenna current state, show
by Mask
antState The current actual antenna available
,1 means able to use,0 means antenna not
connect or not match
Response value:2001 success
Response
MessageBox("success");
Else
MessageBox("fail");
SetFrequency
Function Describe public int SetFrequency (int ReaderAddr, int freqNum, int[]
points)
0:China
1:America
2:Europe
MessageBox("success");
Else
MessageBox("fail");
GetFrequency
0:China
1:America
2:Europe
2001)
MessageBox("success");
Else
MessageBox("fail");
GetFastTagMode
Function Describe public int GetFastTagMode (int ReaderAddr, ref int mode)
Function Get reader Fast Tag Mode
MessageBox("success");
Else
MessageBox("fail");
SetFastTagMode
MessageBox("success");
Else
MessageBox("fail");
SetTestMode
02 is antenna calibration,An
antenna calibration in four completely
disconnected use
Response value:2001 success
Response
MessageBox("success");
Else
MessageBox("fail");
QueryIDCount
tagCount)
MessageBox("success");
Else
MessageBox("fail");
SetOutPort
byte level)
If(SetOutPort(255,0,1)==2001)
Example
MessageBox("success");
Else
MessageBox("fail");
BuzzerLEDON
Buzzer/LED ON
Function
If(BuzzerLEDON (255)==2001)
Example
MessageBox("success");
Else
MessageBox("fail");
BuzzerLEDOFF
BUZZER/LED OFF
Function
If(BuzzerLEDOFF (255)==2001)
Example
MessageBox("success");
Else
MessageBox("fail");
GetBuzzerLED
If(GetBuzzerLED(255,state)==2001)
Example
MessageBox("success");
Else
MessageBox("fail");
GetTcpParameter
nTcpPort)
nTcpPort)==2001)
MessageBox(“success”);
Else
MessageBox(“fail”);
SetTcpParameter
MessageBox("success");
else
MessageBox("fail");
SetMacAddress
Example If(SetMacAddress(255,strMacAddr)==2001)
MessageBox("success");
else
MessageBox("fail");
GetMacAddress
strMacAddr)
MessageBox("succes");
else
MessageBox("fail");
SetSerialNo
If(SetSerialNo (255,strSerialNo)==2001)
Example
MessageBox("success");
else
MessageBox("fail");
GetSerialNo
IsoMultiTagIdentify
IsoMultiTagRead
getCount)==2001)
MessagBox(“success”);
else
MessagBox(“fail”);
IsoReadWithID
byAntenna)
byAntenna)==2001)
MessagBox(“success”);
else
MessagBox(“fail”);
}
IsoWriteWithID
IsoLockWithID
byte byAddress)
MessageBox(“success”);
else
MessageBox(“fail”);
IsoRead
Function Describe public int IsoRead(int readerAddr,byte addr, ref byte[] value)
MessageBox(“success”);
else
MessageBox(“fail”);
IsoWrite
MessageBox(“success”);
else
MessageBox(“fail”);
IsoLock
MessageBox(“success”);
else
MessageBox(“fail”);
IsoQueryLock
Function Describe public int IsoQueryLock(int ReaderAddr, byte addr, ref byte
lstate)
MessageBox(“success”);
else
MessageBox(“fail”);
IsoQueryLockWithUID
MessageBox(“success”);
else
MessageBox(“fail”);
EpcMultiTagIdentify
tag_flag)==2001) MessagBox(“success”);
else
MessagBox(“fail”);
EpcRead
MessageBox(“success”);
else
MessageBox(“fail”);
EpcWrite
MessageBox(“success”);
else
MessageBox(“fail”);
Gen2MultiTagWrite
writeCount)
MessageBox(“success”);
else
MessageBox(“fail”);
Gen2MultiTagRead
MessageBox(“success”);
else
MessageBox(“fail”);
Gen2SecLock
Functions
public int Gen2SecLock(int ReaderAddr, uint AccPassWord, byte
describtion
Functions EPC GEN2 lock tag,Make EPC tag can be safe write with
right password
value
EpcLockTag
Functions
public int EpcLockTag(int readerAddr,byte MemBank)
discribtion
Function EPC GEN2 lock tag,Make EPC tag can be safe write with right
password
value
MessageBox(“succeed”);
else
MessageBox(“fail”);
EpcInitEpc
Functions
public int EpcInitEpc(int readerAddr,byte bit_cnt)
description
Init EPC length,default init is96 bit(6 word)
,and voluation completely is 0
Function
value
MessageBox(“succeed”);
else
MessageBox(“fail”);
Gen2SecWrite
Functions
public int Gen2SecWrite(int ReaderAddr, uint AccPassWord, byte
description
value
Gen2SecRead
Functions
public int Gen2SecRead(int ReaderAddr, uint AccPassWord, byte
describtion
value
MessageBox(“succeed”);
else
MessageBox(“fail”);
Gen2SelectConfig
Functions
public int Gen2SelectConfig(int ReaderAddr, int Action, int Membank,
describtion
value
words)==2001)
MessageBox(“succeed”);
else
MessageBox(“fail”);
Gen2SetAccPwd
Functions
public int Gen2SetAccPwd(uint AccPassWord)
description
value
Example if(Gen2SecRead(AccPassWord)==2001)
MessageBox(“secceed”);
else
MessageBox(“fail”);
Gen2KillTag
Functions
public int Gen2KillTag(int ReaderAddr, uint AccPassWord)
description
value
MessageBox(“succeed”);
else
MessageBox(“fail”);
value
if(ClearIdBuf (255)==2001)
Example
MessageBox(“succeed”);
else
MessageBox(“fail”);
Call OpenCommPort () or
TcpConnectReader
()method
Whether reader
connecting succeed? N
Call GetFirmwareVersion
parameter
Call CloseCommPort ()
or TcpCloseConnect
method close
connecting
Exit program
setting
Call IsoMultiTagIdentify()
tag? Y
N
Call IsoWriteWithID
oint ID
Call CloseCommPort ()
or Tcp CloseConnect
方法关闭连接
Exit program
Call
EpcMultiTagIdentify ()
tag? Y
N
Call EpcWrite
to tag succeed? N
Y
Call CloseCommPort ()
or TcpCloseConnect
Exit program
int status;
byte v1 = 0;
byte v2 = 0;
string s = "";
status =
Api.OpenCommPort(cCommPort.SelectedItem.ToString(),Convert.ToInt32(cBaudrate.Text));
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Open Comm Port Failed! ");
return;
}
status = Api.GetFirmwareVersion(ref v1,ref v2);
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Can not connect with the reader! ");
Api.CloseCommPort();
return;
}
lInfo.Items.Add("Connect the reader success! ");
s = string.Format("The reader's firmware version is:V{0:d2}.{1:d2}", v1, v2);
s = s + " ";
lInfo.Items.Add(s);
byte pwr = 0;
byte freq = 0;
int status;
pwr = (byte)(tRfPwr.Value);
freq = (byte)(cRfFreq.SelectedIndex);
status = Api.SetRf(pwr, freq);
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Set Rf settings failed! ");
return;
}
lInfo.Items.Add("Set Rf settings success! ");
byte ant_sel = 0;
byte antH = 0;
int status;
if (ant1.Checked)
ant_sel |= 0x01;
if (ant2.Checked)
ant_sel |= 0x02;
if (ant3.Checked)
ant_sel |= 0x04;
if (ant4.Checked)
ant_sel |= 0x08;
status = Api.SetAnt(ant_sel, antH);
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Set ant failed! ");
return;
}
lInfo.Items.Add("Set ant success! ");
int status=0;
string strIp="";
string strMark = "";
string strGate = "";
int nTcpPort =0;
try {
strIp = txtNetIP.Text;
strMark = txtSubNet.Text;
strGate = txtDefaultGate.Text;
nTcpPort = int.Parse(txtTcpPort.Text);
}
catch (Exception)
{
lInfo.Items.Add("Please input all the parameter ! ");
return;
}
status=Api.SetTcpParameter(strIp,strMark, strGate, nTcpPort);
if (status != RfidApi.SUCCESS_RETURN) {
lInfo.Items.Add("Setting the TcpParameter Fail,please try again. ");
return;
}
lInfo.Items.Add("Setting the TcpParameter successful. ");
int status;
int i,j;
byte[,] IsoBuf = new byte[100,14];
byte tag_cnt = 0;
string s = "";
string s1 = "";
}
}
(6). Call IsoReadWithID() read data from the tag which was appoint ID unmber.
int addr;
int len;
int i = 0;
int status = 0;
byte byAntenna = 0;
byte[] TagID = new byte[16];
byte[] value = new byte[32];
string s = "The data is:";
string s1 = "";
try
{
addr = int.Parse(tIsoAddr.Text);
len = int.Parse(tIsoCnt.Text);
}
catch (Exception)
{
lInfo.Items.Add("Please input ByteAddr and ByteCnt ");
return;
}
string hexValues = txtTagID.Text;
string[] hexValuesSplit = hexValues.Split(' ');
try
{
foreach (String hex in hexValuesSplit)
{
int x = Convert.ToInt32(hex, 16);
TagID[i++] = (byte)x;
}
}
catch (Exception)
{
lInfo.Items.Add("Please input Tag ID needed ");
return;
}
if (i != 8)
{
lInfo.Items.Add("Please input Tag ID needed ");
return;
}
(7). IsoWriteWithID () write data to the tag which was appoint ID unmber。
int addr;
int len;
int i = 0;
int status = 0;
byte byAntenna = 0;
byte[] TagID = new byte[16];
byte[] value = new byte[32];
string s = "The data is:";
string s1 = "";
try
{
addr = int.Parse(tIsoAddr.Text);
len = int.Parse(tIsoCnt.Text);
}
catch (Exception)
{
lInfo.Items.Add("Please input ByteAddr and ByteCnt ");
return;
}
string hexID = txtTagID.Text;
string[] hexIDSplit = hexID.Split(' ');
try
{
foreach (String hex in hexIDSplit)
{
int x = Convert.ToInt32(hex, 16);
TagID[i++] = (byte)x;
}
}
catch (Exception)
{
lInfo.Items.Add("Please input Tag ID needed ");
return;
}
string hexValues = tIsoData.Text;
string[] hexValuesSplit = hexValues.Split(' ');
try
{
i = 0;
foreach (String hex in hexValuesSplit)
{
if (hex != "")
{
int x = Convert.ToInt32(hex, 16);
value[i++] = (byte)x;
}
}
}
catch (Exception)
{
lInfo.Items.Add("Please input data needed ");
return;
}
if (i != len)
{
lInfo.Items.Add("Please input data needed ");
return;
}
for (i = 0; i < len; i++)
{
status = Api.IsoWriteWithID(TagID,(byte)(addr + i), value[i]);
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Write failed! ");
return;
}
}
lInfo.Items.Add("Write success! ");
int status;
int i, j;
byte[,] IsoBuf = new byte[100, 14];
byte tag_cnt = 0;
string s = "";
string s1 = "";
byte tag_flag = 0;
if (!isNetConnect)
return;
try
{
status = Api.EpcMultiTagIdentify(ref IsoBuf, ref tag_cnt, ref tag_flag);
if (status == 2009)
{
isNetConnect = false;
return;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
isNetConnect = false;
return;
}
if (tag_flag == 1)
this.BackColor = Color.MediumBlue;
else
this.BackColor = Color.MidnightBlue;
if (tag_cnt >= 100)
return;
if (tag_cnt > 0)
{
try
{
for (i = 0; i < tag_cnt; i++)
{
s1 = string.Format("NO.{0:D}: ", TagCnt);
s1 += string.Format("[ANT{0:D}]", IsoBuf[i, 1]+1);
for (j = 2; j < 14; j++) {
s = string.Format("{0:X2} ", IsoBuf[i, j]);
s1 += s;
}
if (lInfo.Items.Count >= 1000)
lInfo.Items.Clear();
}
}
catch
{
}
}
(9). Call EpcRead () read data from the tag which was appoint address and length。
int membank;
int wordptr;
int wordcnt;
int status = 0;
byte[] value = new byte[16];
string s = "The data is: ";
string s1 = "";
membank = cEpcMembank.SelectedIndex;
wordptr = cEpcWordptr.SelectedIndex;
wordcnt = cEpcWordcnt.SelectedIndex + 1;
status = Api.EpcRead((byte)membank, (byte)wordptr, (byte)wordcnt, ref value);
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Read failed! ");
return;
}
else
{
for (int i = 0; i < wordcnt * 2; i++)
{
s1 = string.Format("{0:X2}", value[i]);
s += s1;
}
lInfo.Items.Add("Read success! ");
s += " ";
lInfo.Items.Add(s);
}
membank = (byte)(cEpcMembank.SelectedIndex);
wordptr = (byte)(cEpcWordptr.SelectedIndex);
wordcnt = (byte)(cEpcWordcnt.SelectedIndex+1);
hexValues = tEpcData.Text;
string[] hexValuesSplit = hexValues.Split(' ');
{
foreach (String hex in hexValuesSplit)
{
if (hex != "")
{
int x = Convert.ToInt32(hex, 16);
value[i++] = (ushort)x;
}
}
}
if (i != wordcnt)
{
lInfo.Items.Add("Please input data needed ");
return;
}
for(byte j = 0; j < wordcnt; j++)
{
status = Api.EpcWrite(membank,(byte)(wordptr+j),value[j]);
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Write failed! ");
return;
}
}
lInfo.Items.Add("Write success! ");
(11). Call Gen2SecLock () method to lock EPC GEN2 tag,make EPC tag can be
byte membank;
byte pwdLevel;
int status = 0;
byte[] value = new byte[16];
string s = "";
if (tEpcAccess.TextLength != 8)
{
lInfo.Items.Add("Access Password length not enough ");
return;
}
uint unAccPwd;
switch(cEpcMembank.SelectedIndex)
{
case 0:
membank=3;
break;
case 1:
membank=2;
break;
case 2:
membank=1;
break;
case 3:
membank=0;
break;
default:
membank=2;
break;
}
pwdLevel = (byte)(cmbLevel.SelectedIndex);
(12). Call Gen2SecWrite() method to safe write data in EPC GEN2 tag。
membank = (byte)(cEpcMembank.SelectedIndex);
wordptr = (byte)(cEpcWordptr.SelectedIndex);
wordcnt = (byte)(cEpcWordcnt.SelectedIndex + 1);
if (tEpcAccess.TextLength != 8)
{
lInfo.Items.Add("Access Password length not enough ");
return;
}
uint unAccPwd;
unAccPwd = Convert.ToUInt32(tEpcAccess.Text, 16);
hexValues = tEpcData.Text;
string[] hexValuesSplit = hexValues.Split(' ');
foreach (String hex in hexValuesSplit)
{
// Convert the number expressed in base-16 to an integer.
if (hex != "")
{
int x = Convert.ToInt32(hex, 16);
value[i++] = (ushort)x;
}
}
if (i != wordcnt)
{
lInfo.Items.Add("Please input data needed ");
return;
}
for (byte j = 0; j < wordcnt; j++)
{
status = Api.Gen2SecWrite(unAccPwd,membank, (byte)(wordptr + j), value[j]);
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Write failed! ");
return;
}
}
lInfo.Items.Add("Write success! ");
int status = 0;
byte[] value = new byte[16];
string s = "";
if (tEpcAccess.TextLength != 8)
{
lInfo.Items.Add("Access Password length not enough ");
return;
}
uint unAccPwd;
unAccPwd = Convert.ToUInt32(tEpcAccess.Text, 16);
status = Api.Gen2KillTag(unAccPwd);
if (status != RfidApi.SUCCESS_RETURN)
{
lInfo.Items.Add("Set Password failed! ");
return;
}
else
{
lInfo.Items.Add("Set Password success! ");
lInfo.Items.Add(s);
}