PDA

View Full Version : Passing byte array variable with function in VBA



aptp
05-14-2015, 02:24 PM
Dear users,

I have problem with RFID device SDK.
DLL contains function which can write EPC memory with HEX WORD value.


Function is declared as it is in VB demo and looks like:

Private Declare Function WriteEPC_G2 Lib "C:\VC\ZK_RFID105.dll" (ByRef ConAddr As Byte, ByRef Password() As Byte, ByRef WriteEPC() As Byte, ByRef WriteEPClen As Byte, ByRef errorcode As Long, ByVal PortHandle As Long) As Integer

I want to write "1234" to EPC memory using this function in VBA.

ConAddr it is for sure 0
Password is default "00000000" in HEX
WriteEPClen it is amount of bytes I want to write "1234" means 2 bytes.
Errorcode is output error number
PortHandle is 3 because I have opened COM3 with RFID device

I want to run function x=WriteEPC_G2 (0,??,??,2,3)

what should I type as Password and WriteECP? :banghead:

In VB example it is byte array and looks like: fCmdRet = StaticClassReaderB.WriteEPC_G2(fComAdr, fPassWord, EPC, WriteEPClen, ferrorcode, frmcomportindex)
fComAdr=0
fPassWord = HexStringToByteArray("00000000")
EPC = HexStringToByteArray("1234")
WriteEPClen = Convert.ToByte(Edit_WriteEPC.Text.Length=1234.len=4 / 2)=2
frmcomportindex=3 'I have RFID device on com3

Function in VB:
Private Function HexStringToByteArray(ByVal s As String) As Byte()
s = s.Replace(" ", "")
Dim buffer(s.Length / 2 - 1) As Byte
Dim i As Integer
For i = 0 To s.Length - 2 Step 2
buffer(i / 2) = Convert.ToByte(s.Substring(i, 2), 16)
Next
Return buffer
End Function


Function description:
Function description:
The function is used to write several words in a Tag’s Reserved, EPC, TID, or User memory.
Usage:
Long WINAPI WriteCard_G2 (unsigned char *ComAdr, unsigned char * EPC, unsigned char Mem, unsigned char WordPtr, unsigned char Writedatalen, unsigned char * Writedata, unsigned char * Password, long WrittenDataNum, unsigned char EPClength, long * errorcode, long FrmHandle);
Parameter:
ComAdr: Input. Pointed to the address of the reader.
EPC: Input, Pointed to the array of tag’s EPC value. It is the EPC number of tag.
Mem: Input, Pointed to select the memory area to read.
0x00: Password area
0x01: EPC memory area
0x02: TID memory area
0x03: User’s memory area
Other value when error occurred.
WordPtr: Input, Pointed to the starting address of tag data to write (Word/Hex).If write in the EPC area, it will ignore the start address, and start to write at the address 0x02.
Writedatalen: Input, Pointed to the number of bytes to be written. It must be even and greater than 0. The number of bytes is equal toThe actual number of data to be written. Otherwise, return the parameter error information.
Writedata: Input, Pointed to the array of the word to be written. For example, WordPtr equal 0x02, then the first word in Data write in the address 0x02 of designated Mem, the second word write in 0x03, and so on.
Password: Input, Pointed to the 8 bytes of tag’s accesspassword value. From left to right it is the former high-word, low word in the accesspassword.
maskadr: Input, EPC masking starting address of byte.
maskLen: Input, Masking bytes.
maskFlag: Input,EPC masking Flag.
0x00:disabled;
0x01:enabled;
WrittenDataNum: Output, the number of the word has been written.in word units.
EPClength: Input, Pointed to the byte length of EPC.
Errorcode: Output, Pointed to an explanation byte when the function return value equals 0xFC.
FrmHandle: Handle of the corresponding communication port the reader is connected. The handle value is got when calling function AutoOpenComPort or OpenComPort.
Returns:
Zero value when successfully, non-zero value when error occurred.