Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use the ni-can using visual basic

I'm having some troubles using the channel API in visual basic. I want to getnames (using nctgetnames) but the .bas module in VB has the channelList as a byte, but in the channel API documentations says that it should be a string. So can you tell how can I get the channels names from a vector database?
0 Kudos
Message 1 of 6
(4,255 Views)
That sounds like a bug in the header file.
Normaly it should be: ByRef ChannelList As String,_
You can modify that manualy in the header file.
That should work.
0 Kudos
Message 2 of 6
(4,254 Views)
Hi,
I already try your idea an it doen't work!
Any other idea?
The software crash after the nctGetnames function runs.
0 Kudos
Message 3 of 6
(4,254 Views)
Catalina,

After doing some digging it looks like this might actually be a small bug. There appears to be a problem with the wrapper code. In the coming days either myself or another will try and post a workaround solution.

Craig H.
NI Applications Engineering
0 Kudos
Message 4 of 6
(4,254 Views)
It is not a bug in the function definition, but there is a wrapper function missing. Use the following code to read the names from NI-CAN instead.

Function nct_GetNames(ByVal FilePath As String, ByVal Mode As Long, ByVal MessageName As String, ByVal BufferSize As Long, ByRef List As String)
' This function wraps nctGetNames function and makes the names from NI-CAN available for the
' user in string format
Dim str() As Byte
Dim i As Integer
Dim Status As Long

ReDim str(BufferSize + 1)

i = 1
nct_GetNames = nctGetNames(FilePath, Mode, MessageName, BufferSize, str(0))
List = Chr(str(0))

While ((i < BufferSize) And (Chr(str(i)) <> "\0"))
List = List + Chr(str(i))
i = i + 1
Wend
End Function


Call this function instead of nctGetNames directly.
Message 5 of 6
(4,256 Views)
Ni has fixed the .bas file to use the nctgetnames function with VB
replace the .bas file with this one you can find attached.
Message 6 of 6
(4,239 Views)