Click here to Skip to main content
15,895,084 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Delegates & Pointers Pin
Synth_Boy16-Jan-14 4:20
Synth_Boy16-Jan-14 4:20 
AnswerRe: Delegates & Pointers Pin
Dave Kreskowiak16-Jan-14 3:31
mveDave Kreskowiak16-Jan-14 3:31 
GeneralRe: Delegates & Pointers Pin
Synth_Boy16-Jan-14 4:24
Synth_Boy16-Jan-14 4:24 
GeneralRe: Delegates & Pointers Pin
Ron Beyer16-Jan-14 4:50
professionalRon Beyer16-Jan-14 4:50 
GeneralRe: Delegates & Pointers Pin
Synth_Boy16-Jan-14 5:15
Synth_Boy16-Jan-14 5:15 
GeneralRe: Delegates & Pointers Pin
Ron Beyer16-Jan-14 5:17
professionalRon Beyer16-Jan-14 5:17 
GeneralRe: Delegates & Pointers Pin
Synth_Boy16-Jan-14 6:03
Synth_Boy16-Jan-14 6:03 
AnswerRe: Delegates & Pointers Pin
Synth_Boy30-Jan-14 22:02
Synth_Boy30-Jan-14 22:02 
Just in case someone comes across this post looking for answers themselves, i solved the main problem by actually turning the PCB board on with a software command Poke tongue | ;-P

But to try and answer the pointers delegate question here are my thoughts; First of all it can be confusing when you first look at it - well for me at least. If you look at converting C++ to VB there is always talk about Delegates as VB doesn't really have pointers, ... or does it? I knew already (from previous project) that pointers work and i had used them and delegates and 'addressof method' and various other stuff to interact with hardware and a DLL, which at the time seemed complicated to me but it worked, so why should i worry. Also why should it be different this time? This is one reason i ruled out the passing of 'String' instead of 'IntPtr' in the Function. And as it turned out relying on the 'string' being a 'kind of pointer' was not the way to a solution. To be honest using VB to access hardware etc is not the norm i know, but i am VB orientated not C++ Wink | ;)

In the current project the hardware and DLL interact to respond to a command and send back info to an address in ASCII format. So in the end i just had to be simple;
Declare Function
Create send Pointer and allocate some memory
Convert Code to ASCII
Copy the ASCII command to the Pointer
Create receive pointer (sRx) and allocate some memory
Call Function
Finally Decode the returned ASCII, which requires copying the "unmanaged data" to "managed data" and then converting.

VB
Public Declare Function RFIDP1_TagComms Lib "myCom.dll" Alias "RFIDP1_TagComms" (ByVal sTx As IntPtr, ByVal sRx As IntPtr, ByVal sRxSize As Integer, ByVal timeout As Integer) As Integer

VB
tagRead = "SRD" 'various codes
Dim code() As Byte = System.Text.Encoding.ASCII.GetBytes(tagRead)
Dim codeLen As Integer = code.Length
'turn on rfid module!!!
result = PwrCtrl(1, True) 'targets separate PDA DLL
Threading.Thread.Sleep(500) 'allow power to stabilse
txtBxOutput.Text = "Module On"

Dim pointer As IntPtr = Marshal.AllocHGlobal(codeLen)
Marshal.Copy(code, 0, pointer, codeLen)
Dim sRx As IntPtr = Marshal.AllocHGlobal(127)
result = RFIDP1_TagComms(pointer, sRx, 127, 500)
If result = 0 Then
    lbltagResult.Text = "Tag Read"
Else
    lbltagResult.Text = result
End If
deCode(sRx)

VB
Public Sub deCode(ByVal addr As IntPtr)
        'deCode the ascii code at the pointer
        Dim managedArray2(127) As Byte
        Marshal.Copy(addr, managedArray2, 0, 127)
        Dim enc As New System.Text.ASCIIEncoding() 'convert chars
        txtBxTN.Text = enc.GetString(managedArray2, 0, 18) 'to letters 
 End Sub


So overall 'easy when you know how' Big Grin | :-D
QuestionVb script Pin
Member 1052588115-Jan-14 4:25
Member 1052588115-Jan-14 4:25 
AnswerRe: Vb script Pin
Dave Kreskowiak15-Jan-14 4:38
mveDave Kreskowiak15-Jan-14 4:38 
AnswerRe: Vb script Pin
Ron Beyer15-Jan-14 5:00
professionalRon Beyer15-Jan-14 5:00 
Questionexe file Pin
Member 1052323315-Jan-14 2:23
Member 1052323315-Jan-14 2:23 
AnswerRe: exe file Pin
thatraja15-Jan-14 2:31
professionalthatraja15-Jan-14 2:31 
Questionvb 6.0 birthday reminder form code Pin
akcworld14-Jan-14 18:00
akcworld14-Jan-14 18:00 
AnswerRe: vb 6.0 birthday reminder form code Pin
Dave Kreskowiak14-Jan-14 18:13
mveDave Kreskowiak14-Jan-14 18:13 
Generalvisual basic 2010 homework Pin
Member 1052356014-Jan-14 5:10
Member 1052356014-Jan-14 5:10 
GeneralRe: visual basic 2010 homework Pin
Ron Beyer14-Jan-14 5:15
professionalRon Beyer14-Jan-14 5:15 
GeneralRe: visual basic 2010 homework Pin
Member 1052356014-Jan-14 5:21
Member 1052356014-Jan-14 5:21 
GeneralRe: visual basic 2010 homework Pin
Tim Carmichael14-Jan-14 5:44
Tim Carmichael14-Jan-14 5:44 
GeneralRe: visual basic 2010 homework Pin
Member 1052356014-Jan-14 5:47
Member 1052356014-Jan-14 5:47 
GeneralRe: visual basic 2010 homework Pin
Pete O'Hanlon14-Jan-14 6:17
mvePete O'Hanlon14-Jan-14 6:17 
GeneralRe: visual basic 2010 homework Pin
Member 1052356014-Jan-14 14:10
Member 1052356014-Jan-14 14:10 
GeneralRe: visual basic 2010 homework Pin
Pete O'Hanlon14-Jan-14 19:01
mvePete O'Hanlon14-Jan-14 19:01 
QuestionInteracting with Excel: version problem or distribution problem Pin
Steven St. John9-Jan-14 5:14
Steven St. John9-Jan-14 5:14 
AnswerRe: Interacting with Excel: version problem or distribution problem Pin
TnTinMn9-Jan-14 16:07
TnTinMn9-Jan-14 16:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.