Discussion:
NI-CAN for .NET yet?
(too old to reply)
rteder
2007-07-23 16:10:10 UTC
Permalink
Is there now an API for Visual Basic .NET yet?  Perhaps one out in Beta?  I understand I can derive one with the upgrade wizard, but would prefer the more robust solution of a NI-supplied API.
 
 
 
rteder
2007-07-24 15:40:10 UTC
Permalink
Having delved into this for a few days, I now understand why NI has not yet produced an API for .NET.  Microsoft broke much backward compatibility with Visual Studio 2005.  It is extremely difficult to get even a few of the API functions working on an as-needed basis.  This is not a simple job at all, and I suspect that is why NI has not yet done so.
But, I have little choice, as VB6 is not supported anymore.  So, please NI:
"Please make a Visual Studio object that encapsulates the LIN and CAN interfaces.  All of the functionality should be through regular properties and methods-- similar to, for example, the Visual Studio Serial Port object."
 
Best Regards,
Rein TederOpto-Electronics Engineer
 
 
 
 
 
rteder
2007-07-24 20:10:09 UTC
Permalink
Just for the benefit of anyone else that is searching the NI site with the same problem:
 
I just gotten my NI USB-8476 LIN interface to work successfully read some LIN data in my .NET application.  This was difficult, because many pointers passed to/from the DLL's are of type "As Any", no longer allowed in VB.NET.  
 
VB will not allow you to just call this "As Object".  If you tell VB to return a pointer to structure of type NCTYPE_CAN_STRUCT, it should work, because that is in fact what it is pointing to.  But, alas, it does not.  VB gives you protected memory errors.  Now, perhaps a better programmer than I can come up with a cleaner solution, but this is how I got it to work:
 
ncRead woulds still allow me to get the data out as an array of bytes.    I did so, and parsed the ones I needed into the structure.  Code:
 
Status = ncRead(LINRx, AllottedDataSize, ByteBuffer(0))

If Status <> 0 Then GoTo RecError
'Public Structure NCTYPE_CAN_STRUCT
' Dim Timestamp As NCTYPE_UINT64 (Bytes 0 - 7)
' Dim ArbitrationId As Integer (4 Bytes, so Bytes 8, 9, 10, 11)
' Dim FrameType As Byte (Byte 12)
' Dim DataLength As Byte (Byte 13)
' <VBFixedArray(7)> Dim Data() As Byte (Bytes 14, 15, 16, 17, 18 19, 20, 21)
'End Structure
Dim ReceiveStruct As NCTYPE_CAN_STRUCT
ReceiveStruct.Initialize()
ReceiveStruct.ArbitrationId = ByteBuffer(8) + ByteBuffer(9) * 256 _
+ ByteBuffer(10) * 65536 + ByteBuffer(11) * 256 * 65536
ReceiveStruct.FrameType = ByteBuffer(12)
ReceiveStruct.DataLength = ByteBuffer(13)
For i = 0 To 7
ReceiveStruct.Data(i) = ByteBuffer(14 + i)
Next
 
 
rteder
2007-08-01 21:10:13 UTC
Permalink
The above-referenced CAN to USB converter looks just great-- I'll check it out when I need to develop a CAN system. (A need which is likely to arrise soon.)  But, there are relatively few tools out there for the LIN bus, my current need.  (I tried a product called Baby LIN but found the documentation incomprehensible.)
Just confirming, I was able to get my project working using .NET and variations of the above snippet of code.  Essentially, with .NET you can no longer use type "Any" pointers, and the only thing I found that worked with the NI API was to pass to/from arrays of bytes.  The .NET upgrade wizard will NOT get you working code.  It is apparent to me why NI has not yet released a .NET package; if it was easy they would have done it.  I hope they do, as the NI product itself is very good.
 
Rein TederOpto-Electronics Engineer
 
 
 
 

Continue reading on narkive:
Loading...