Skip to main content
duncan
Associate II
Sep 4, 2013 9:55 AM UTC
Solved

Issues with Programming CR95HF/M24LR in VB.net

Posted on September 04, 2013 at 11:55

Hi there, I am using a CR95HF board from a M24LR discovery kit to read data from a device. If I use the dual-interface EEPROM software from the ST website, select Reader Application and select M24LR64A, then click Read, or alternatively, 'show RF file transfer tools' and then save EEProm into a file' it does what I want, however I want to be able to include this functionality into my own software.

I have not programmed a hardware unit like this before, so am just getting used to it. I have constructed a small simple VB.net application based on the downloadable code examples, however there are some issues:

[code]

Public Declare Ansi Function CR95HFDll_Echo Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_Idn Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_Select Lib ''CR95HF.dll'' (ByVal mycmdstring As String, ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_SendReceive Lib ''CR95HF.dll'' (ByVal mycmdstring As String, ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_STCmd Lib ''CR95HF.dll'' (ByVal mycmdstring As String, ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_FieldOff Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_GetDLLrev Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_ResetSPI Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_SendIRQPulse Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    Public Declare Function CR95HFDLL_getMCUrev Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    'added in Dll revision 0.4

    Public Declare Function CR95HFDLL_getInterfacePinState Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    'added in Dll revision 0.5

    Public Declare Function CR95HFDLL_USBconnect Lib ''CR95HF.dll'' () As Long

    Public Declare Function CR95HFDll_Polling_Reading Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    Public Declare Function CR95HFDll_SendNSSPulse Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    'added in DLL revision 0.6

    Public Declare Function CR95HFDLL_USBhandlecheck Lib ''CR95HF.dll'' () As Long

    'added in DLL revision 0.9

    Public Declare Function CR95HFDLL_getHardwareVersion Lib ''CR95HF.dll'' (ByVal mystring As String) As Long

    Public Const CR95HF_STM32_error = &H1

    Public Const CR95HF_empty_argument_error = &H2

    Public Const CR95HF_cmd_parameter_error = &H3

    Public Const CR95HF_communication_error = &H4

    Public Const CR95HF_USB_communication_error = &H5

    Public Const CR95HF_ERRORCODE_DEFAULT = &HFE

    Public Const CR95HF_ERRORCODE_TIMEOUT = &HFD

[/code]

[code]

Dim lngStatus As Long = 5

        Dim lngStatus2 As Long = 6

        Dim strAnswer As New String('' ''c, 256)

        Dim strTagResponse As New String('' ''c, 256)

        lngStatus = CR95HFDLL_USBconnect()

        If (lngStatus = 0) Then

            lngStatus2 = CR95HFDll_Select(''010D'', strAnswer)

            CR95HFDll_SendReceive(''260100'', strTagResponse)

            MsgBox(''RFID Code is: '' & strTagResponse)

        Else

            MsgBox(''Warning : DEMO-CR95HF-A not connected'')

        End If

        Dim strAnswer2 As New String('' ''c, 256)

        lngStatus = CR95HFDll_STCmd(''010202010D'', strAnswer2)

[/code]

Firstly I do not know how to get the data from the code blocks as the EEPROM software does. I have looked through the manuals/documentation and just simply cannot figure it out. Also there are some issues with the return values. for the CR95HFDLL_USBconnect function it correctly returns 0 or 1, but for all the others, it just seems to return gibberish, and I do not know why. It could be to do with the string I am sending it, as vb.net cannot cope with the command ''As String*256''

any help would be appreciated!

#cr95hf #m24lr-discovery #cr95hf #vbnet #vbnet #vbnet #m24lr-discovery
This topic has been closed for replies.
duncan
duncanBest answer
Associate II
Sep 23, 2013 3:34 PM UTC
Posted on September 23, 2013 at 17:34

Hi,

this is just to let you know I have solved the problem. The issue is in the declaration for the DLLs and also the lngstatus numbers.  I would guess the dll has been compiled using a 32bit compiler, whereas the vb.net that I have installed uses a 64 bit compiler, so a 'long' is actually a 64bit number as far as my compiler is concerned. all the lead bits of the return are junk - whatever is in the memory at the time I guess. The problem is remedied by replacing long with uint32, so for example:  

Public Declare Function CR95HFDll_SendReceive Lib ''CR95HF.dll'' (ByVal mycmdstring As String, ByVal mystring As String) As System.UInt32

Dim lngstatus As Uint32

lngstatus = CR95HFDll_SendReceive(command, strTagResponse)

returns the correct error codes.

6 replies

Anais GALLIGANI
Visitor II
Sep 6, 2013 11:04 AM UTC
Posted on September 06, 2013 at 13:04

Hello,

Please find here below a peace of code we could get. This can be usefull to set variables and environement on VB.NET.

DLL FUNCTIONS DECLARATION :

declaration

   

Public

Declare

Function

CR95HFDLL_USBconnect

Lib

''CR95HF.dll''

()

As

Integer

   

Public

Declare

Function

CR95HFDll_Echo

Lib

''CR95HF.dll''

(

ByVal

mystring

As

String

)

As

Integer

   

Public

Declare

Function

CR95HFDLL_getMCUrev

Lib

''CR95HF.dll''

(

ByVal

mystring

As

String

)

As

Integer

   

Public

Declare

Function

CR95HFDll_Select

Lib

''CR95HF.dll''

(

ByVal

mycmdstring

As

String

,

ByVal

mystring

As

String

)

As

Integer

   

Public

Declare

Function

CR95HFDll_SendReceive

Lib

''CR95HF.dll''

(

ByVal

mycmdstring

As

String

,

ByVal

mystring

As

String

)

As

Integer

   

Public

Declare

Function

CR95HFDll_STCmd

Lib

''CR95HF.dll''

(

ByVal

mycmdstring

As

String

,

ByVal

mystring

As

String

)

As

Long

INVENTORY COMMAND - FUNCTION EXAMPLE :

           

Dim

strTagReponseCons0 =

New

String

(

CChar

(

''''

), 256)

           

Dim

lngStatusCons0

As

Long

            

lngStatusCons0 = CR95HFDll_SendReceive(“260100�?, strTagReponseCons0)

            

I think that the declaration of Tag answer need to be changed in “

New

String

(

CChar

(

''''

), 256)

“

Might you tell us if this solve your issue?

Thanks a lot,

ST NFC/RFID dynamic tag support

duncan
duncanAuthor
Associate II
Sep 9, 2013 10:23 AM UTC
Posted on September 09, 2013 at 12:23

Thanks for the reply. I have tried this and it is putting the correct thing in the return string, however the 'long' status is still nonsense. For the first command, CR95HFDLL_USBconnect() it returns 0, however for subsequent commands it returns numbers like 65497649968578560, meaning I cannot use it as a status check.

Also I was hoping you could let me know of a command that allows me to access the on board memory. As I mentioned before, If I use the dual-interface EEPROM software from the ST website, select Reader Application and select M24LR64A, then click Read, or alternatively, 'show RF file transfer tools' and then save EEProm into a file' it does what I want, however I want to be able to include this functionality into my own software.

Thanks for the help!

Duncan

duncan
duncanAuthor
Associate II
Sep 10, 2013 9:48 AM UTC
Posted on September 10, 2013 at 11:48

I've managed to get it to do most of what I want, however the return codes are still giving values like 340187712222920704

Anais GALLIGANI
Visitor II
Sep 11, 2013 8:14 AM UTC
Posted on September 11, 2013 at 10:14

Hello Hill,

As w

e don’t have VB.NET application based here, it is not easy to help deeper on programmation syntax.

How have you solve the previous issue?

duncan
duncanAuthor
Associate II
Sep 23, 2013 2:27 PM UTC
Posted on September 23, 2013 at 16:27

I did as you suggested - the code is returning meaningful values in the string, but as I mentioned, the dll is still not returning anything sensible in the lngstatus values.

duncan
duncanAuthorBest answer
Associate II
Sep 23, 2013 3:34 PM UTC
Posted on September 23, 2013 at 17:34

Hi,

this is just to let you know I have solved the problem. The issue is in the declaration for the DLLs and also the lngstatus numbers.  I would guess the dll has been compiled using a 32bit compiler, whereas the vb.net that I have installed uses a 64 bit compiler, so a 'long' is actually a 64bit number as far as my compiler is concerned. all the lead bits of the return are junk - whatever is in the memory at the time I guess. The problem is remedied by replacing long with uint32, so for example:  

Public Declare Function CR95HFDll_SendReceive Lib ''CR95HF.dll'' (ByVal mycmdstring As String, ByVal mystring As String) As System.UInt32

Dim lngstatus As Uint32

lngstatus = CR95HFDll_SendReceive(command, strTagResponse)

returns the correct error codes.