To download NI software, including the products shown below, visit ni.com/downloads.
Vector provides an API for performing low level control of their hardware. The code posted here is primarily wrappers around their XL Driver APIs. These functions come in the form of the vxlapi.dll, and vxlapi64.dll.
Vector has some very nice products for testing vehicle communication buses such as CAN, LIN, MOST and FlexRay.
They sell some very expensive software and some reasonably priced hardware to go along with it.
You can buy just the unlicenced hardware and use the freely available driver that comes along with it in your own custom applications.
Vector XL series hardware or VN series hardware and drivers installed. This includes the older CANCase and newer VN16xx USB devices.
Windows Device Driver for the Vector hardware. Check if your device is recognized in Windows Device Manager.
LabVIEW 2020 or later for version 4.
The required DLLs are included in the version 4 zip. For those that don't the instructions below are for acquiring these drivers.
To get the dll and driver go to the Vector download page and download it. Just be sure to choose the right options when finding the XL Driver Library containing the dll.
IGNORE THE LABVIEW DRIVER! It is quite restrictive, and requires a rather expensive license.
From the download page select: XL Driver Library > Drivers & Firmware > All
Now click the button that says "Show Results...". You should now have a list of drivers available. Again, ignore the LabVIEW one. Download the XL Driver Library X.X.
Unfortunately the header file supplied with the driver dll doesn't readily import into LabVIEW. We had to make some significant modifications to it before it worked. Then I had to go through and make quite a number of corrections once it was done.
If you're curious the modified header file is called vxlapi3.h.
Here I just provide wrappers and an example or two to get you started. Below is one simple example of transmitting a CAN frame.
Hooovahh has made several changes based on user feedback, and released it as Version 4. The two main improvements to this version is to support CAN-FD reading and writing, and to support 64-bit LabVIEW as well. A more clean example also allows for simple reading and writing of frames, along with reading analog and digital values on hardware that supports it.
The "Basic LIN test.vi" assumes you are using the LIN channel to monitor a running LIN connection. It works as a silent slave node on the network.
To actually receive any LIN frames there must already be a LIN master communicating with another LIN slave.
VI in attached zip file.
"Simulate LIN network.vi" will transmit from one LIN channel set up as a Master node to other LIN channels set up to respond as Slave nodes.
There is now also a "Simulate LIN network -master transmit.vi" which allows you to transmit data from a Master to Slaves. (Remember that a master node MUST HAVE A PULL-UP!)
CAN Receive example added due to popular demand (updated with documentation and code tidy):
All example VIs and dependencies should now be contained in this latest zip file.
If you find any bugs or updates needed feel free to send me a message.
If you have a support request please post it in the LabVIEW Forum, NOT HERE. I will get a notification and reply in the forum if you add vxlapi as a tag.
Description-Separate-2
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
This API should not be designed in a way that combines reading and writing. The DAQmx Read Analog doesn't also have the ability to Write Analog in the same VI. The way this API was written it looks like it mirrors the standard functions that others have used for interfacing with hardware. Combining these two may seem to fit your use case but others would prefer it conforms to the stardards commonly used.
You are of course welcome to make a subVI that calls both the read and write and you can then call that one subVI.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
Thank you for your answer.
The problem is, that i have not so much experience in LabView. For practice it would be great
if i can use a ready vi with this functionality.
Hello,
Tomorrow I will send to you what I start to build, you can send and receive in the same vi, but receive part must be reworked for better viewer of the signal.
Hello,
thx a lot. I think this will help the development of my CAN - Transceiver.
Do you post your .vi?
Best regards!
Mike
yes, but tomorrow.
Absolutely great!!!
In this .vi you can send and receive full parallel?
Thx, until tomorrow, then.
I have to say to not expect at something great, because I don't know to much about CAN communication, I work with CAn only for few months. What I want to achieve with this vi is to communicate via CAN and to send and receive data in the same interface, I don't know what full parallel mean, so only tomorrow you will see if my vi we help you or not.Tel me what version of Labview do you have.
Hi, my LabView is Version 13.0
Hi chirtab, this looks like very nice.
My email: mi(dot)elec(ät)web(dot)de
I have sent by email this vi. Please tell me if it is useful for you.
How to transmit a LIN message(ID and 8 bytes data) via Vector interface to the ECU?
The "Simulate LIN network.vi" is included in the zip file. It contains an example of how to transmit an ID for the slave to fill in the response.
As far as I know (I haven't done it yet) you can get your master to fill the data in for an ID by using xlLinSwitchSlave(), xlLinSetChecksum(), xlLinSetSlave() and xlLinSetDLC(). Then also use the the master node to transmit the header using xlLinSendRequest() and it will fill in the data itself. Any slave nodes attached to the bus will be able to capture the data transmitted.
This question has already been asked and answered earlier in the comments section here: https://decibel.ni.com/content/docs/DOC-30180#comment-35626
No response from the asker though so I don't know if it worked. Asking questions works so much better in the LabVIEW forum rather than the comments on a document.
Hello, does anyone know if it possible to run Labview Code on the VN8970 in a sort of standalone mode?
It would be nice to use it as Labview Hardware Target, and then "Transfer" the programmed software to it.. selfcontaining
Using the VN8970 Hardware with Labview together looks more like a nightmare than anything usefull to me, even if you own CANoe the documentation is uncomplete/outdatet and misleading at best.
I spent some quality time, immitating their FDX-Server like example and it doesn't work nicely and is buggy as hell....
i would strongly not recommend any vector hardware because of the time effort involved with it
After I spend also my self few days to make it work (CANcase and Labview) I think that is not worth it. It is more easy to learn CANoe. If you don't have a license for CANoe it is another story, but other way I recomand to use CANoe. Mixing LabView and CANcase is like you whant to mix yogurt and watermelon for breakfast, for sure is possible, but it taste good ?
Good luck!
Hi there!
Just wanted to share a positive experience with LabVIEW and CANCase. As surprising as it might seem, they do work together ok!
18 months ago, I re-wrote a CANCase driver based on TroyK's Vector XL Driver - Wrapper VIs. The biggest challenge with making it work was reading (and re-reading) the XL Driver Library API Description document (downloadable from www.vector.com) to understand what the CANCase was capable of. Once I had got my head around the Vector XL Driver DLL, and how it functioned, it was very easy to take TroyK's VIs and create several applications.
In a previous version, we weren't using TroyK's VIs, and it was buggy and horrible. Using TroyK's VIs now means we are using the full suite of functions available in the DLL, and it works - very well!
Our application incorporated other NI tools such as the ADCS, of which I changed so that it could use TroyK's DLL at the lower level. It also incorporated the NI CAN Frame to Channel Conversion library so that we could work with the messages from the NI CAN DB, rather than just sending raw CAN bytes!
It might not be immediately intuitive, but if you give yourself 2-3 days to really work through the aforementioned document, you will figure out how the application needs to work, and will make a success of it!
Keep trying!
As far as I can tell the VN8970 has either an ATOM processor or a core-i7 on board and runs something Vector calls CANoeRT.
From the VN89xx manual:
"The VN8900 interface family offers a stand-alone mode which allows a measurement without any additional user PC.
For this purpose a measurement application can be configured in CANoe, which is then written into the permanent memory of the VN8900. After a restart, the configura-tion is loaded and the measurement autonomously started."
CANoe uses a programming language they call CAPL. My understanding is that CAPL code is downloaded onto the VN89xx series devices and executes directly on the device without the need for it to be connected to a PC.
In other words, I don't think there is any way to get LabVIEW code to run on a VN8970.
The vxlapi.dll that is being used here is meant to be used on a Windows operating system. You can use it to control the VN8970 similar to other Vector hardware, but not in stand-alone mode. I don't know what OS is running on the VN89xx hardware but I very much doubt you'd be able to install a LabVIEW runtime onto it.
I think your only option to run a VN8970 in stand-alone mode is to buy a CANoe license that lets you do it and learn to write CAPL.
[PS. Thanks Chris )
So, when I open the Transmit Example and run it with the defaults it goes through with no errors but when I change the ID to 14FF0021 I get the following driver error 101 wrong parameter.I get this error regardless of whether I use extended or standard...
The error occurs through the xl Can Transmit vi if that helps...
Other settings are CANcase XL, 0 for index and channel, and 125k baud...
Super new to CAN and would really appreciate any help!
@lbounds The answer to your question was mentioned earlier in the comments section of this document here.
Also in the LabVIEW forum here. And I just answered it again in response to your post in the forum here.
Hello,
I try to send a CAN message with the Vector VN1610 using the "Transmit Example.vi". With the default id "98FED980" I get no error message. But if I use the id "18DA03F1", I get the error message
"Transmit Example.vi<ERR>
vector xl driver error 101 XL_ERR_WRONG_PARAMETER
<b>Complete call chain:</b>
Transmit Example.vi"
generated by the "xl Can Transmit.vi". I use the extended id range. Pleas help me.
Thank You
Basti
Peate, in the comment right above yours TroyK linked to where the answer can be found...it was the same question I had.
To save him some time I can give you the quick explanation...Vector hardware uses the 32nd bit in the ID to designate whether it is extended or standard. To send a proper extended ID, OR the ID you wish to send with 0x80000000. So for your example, send 98DA03F1.
Hi Troyk
I tried ur VI,s and i installed xl driver the way u explained above ..but it showing error dll not found ..vxlapi.dll..pls give me the solution..i have vector VIN 1611 LIN/CAN interface
thank you
sandeep naik
9901943951
Where is your vxlapi.dll?
You need to put a copy of it next to the vxlapi.lvproj file.
The VI LIN parity checksum.vi in Vector XL LV2011 v2.zip contains a bug! With certain byte combinations it calculates the wrong CRC. The bug is in the "byte addition with carry", ID parity calculation is ok.
See http://forums.ni.com/t5/LabVIEW/VXLAPI-CRC-calculation-bug/td-p/3274433
Cool, thanks Tom, nice catch. I'll get round to updating the library at some point in the future. I'm crazy busy at the moment.
Hello, I'm using a VN1630A and I'd like to send a digital signal through CH5-IO but i don't know if it is possible or not...can you help me? (I tried to use xlDAIOSetAnalogOutput but it return 6113 error, i don't know if it is possible set channels or not in the VN1630A)
thanks!
Hi, It should be possible although I've never done it. If you get it going I'd love to see some example code. Did you have a look at xlDAIOexample.c that gets installed with the driver library. It may give you a clue as to how to get it going.
It installs to: C:\Users\Public\Documents\Vector XL Driver Library\samples\xlDAIOexample
Hi, I am writing a driver for vector xl Hardware interfaces, the h/w type is XL_HWTYPE_VN1630. I have got succesful status for these interfaces.
xlOpenDriver();xlGetDriverConfig();xlGetApplConfig;xlSetApplConfig;xlGetChannelIndex.
But when I tried to open port using xlOpenPort interface, I always getting porthandle as a invalid port.below is my code:
XLstatus xlStatus = XL_ERROR;
XLaccess m_xlChannelMask_both;
XLaccess xlPermissionMask;
char tmp[100];
m_xlChannelMask_both = m_xlChannelMask[MASTER] | m_xlChannelMask[SLAVE];
xlPermissionMask = m_xlChannelMask_both;
xlStatus = xlOpenPort(&m_xlPortHandle, "LIN", m_xlChannelMask_both, &xlPermissionMask, 256, XL_INTERFACE_VERSION, XL_BUS_TYPE_LIN);
if (m_xlPortHandle == XL_INVALID_PORTHANDLE)
{
qDebug()<<"m_xlPortHandle"<<m_xlPortHandle;
return XL_ERROR;
}
Please suggest where I have to look for the these error.It will be great help.
Thanks in advance
I got it, where is the problem. and have fixed.
Thanks
What I don't get is
But nevermind, I am glad you solved your problem.
Hi, I am using VN1611 Lin .In Recieving side After 2 minutes XL_Level out will become 0. and not recieving any data.it stops the recieve data ..Pls let me know why??
Hi TroyK;
I am using vector lin device with Labview Wrappers .its working fine.how to change Synch and break field of Lin header..is there any way to change that bit values and verify protocol level testing?
Thanks
Sandeep Naik
9901943951
Hi Sandeep,
Did you check the XL Driver Library API documentation? If it isn't in the documentation then you probably can't do it with the hardware you're using or at least Vector hasn't exposed that function in the vxlapi.dll documentation.
Looks like some hardware can do it but Vector obviously wants you to pay for those advanced features.
https://vector.com/kbp/entry/38/
So I've looked through the documentation and I don't think it is possible, but is there a way to read how many frames are sitting in the write queue to be written? If you have no device connected and write a few thousand frames, then the XL_ERR_QUEUE_IS_FULL error will be returned. What I'd like to do is detect what this queue or buffer count is up to and if it is increasing to assume no device is on the bus reading these messages and to stop transmitting. The best I can do so far, is to transmit my frame, and if I get that error, then to run the Flush Transmit Queue. I'd rather just not write the messages in the first place if no hardware is listening. Any suggestions? Thanks.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
Hi Brian,
I have tried to use transmit receipts in the past to confirm that frames were transmitted properly. It mostly worked but I had 3 different modules all accessing the same port simultaneously (with their own port handles) so it complicated it a bit.
Use xl Can Set Channel Mode.vi with tx set to "generate receipts". Then you will get a receipt every time a message successfully gets out on the bus.
You could increment a counter every time you attempt to transmit and decrement for every receipt.
Thanks for the receipts suggestion works great. I had to look at Data 4 on the Flattened Event to see if the frame was from an echo'ed transmit.
Also do you have an example of using the WaitForSingleObject? The VI seems to be missing a "get win32 error code.vi", but also it doesn't seem to work for me unless I'm using it incorrectly. Giving it the handle from the OpenPort it just returns immediately even with a 1000 timeout. Thanks.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
>Thanks for the receipts suggestion works great. You're welcome.
>I had to look at Data 4 on the Flattened Event to see if the frame was from an echo'ed transmit. If you're using VXLAPI-Convert_Data_To-s_xl_can_msg.vi flags = TX_COMPLETED
>Also do you have an example of using the WaitForSingleObject? Yes, needs work though. Need me to add it as an example?
>The VI seems to be missing a "get win32 error code.vi", but also it doesn't seem to work for me unless I'm using it incorrectly. Oops, sorry, added now.
>Giving it the handle from the OpenPort it just returns immediately even with a 1000 timeout. Use xlSetNotification function (xl Set Notification.vi) to get a windows event handle to feed into WaitForSingleObject.
Awesome thanks, that's all I needed. I've cleaned up your code a bit and wrapped it in a library. This was an attempt at making an API that mimics XNet a bit with a Number of Frames to read, along with the Timeout on the read function, and the returned data type is an array of frames, using the same cluster style as XNet. I also re-did some of the pEvents conversion in an attempt to be faster, and somewhere along the way I lost the information some of the flags like TX Complete.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
Mr. Troy I am a mega big fan of this apps of yours, thanx by the way, I am not a labview genius like most of you but I'm there learning.
So I have a question, is there a way to extract the specific data of a certain ID in real time to feed to a mathscript of mine?
For example if I know that somewhere in the filled table I have the ID x9F and I want the corresponding value to it in the data column. How can it be extracted to be used, once you specify the ID.
Best Regards
I solved the previous problem; yet I have a new problem when using can recieve as a SUB VI I don't get outputs
How can I configure it to have valid outputs?
@Troy
>> I have tried to use transmit receipts in the past to confirm that frames were transmitted properly. It mostly worked but I had 3 different modules all accessing the same port simultaneously (with their own port handles) so it complicated it a bit.
Yeah actually I'm seeing this a bit myself. So I have two CAN devices, one transmits the other receives. When I write a frame in increment a counter, and with the transmit receipt every frame read with the echo will decrement the counter. The problem I see is over time not every frame I write comes back with a receipt. This causes my counter to increment slowly. If there is a bug with the DLL or hardware I don't see this technique working to keep track of the number of frames in the write buffer. But in my case I really just wanted to know if the bus is idle and to stop transmitting if there is no node reading the frames. So for me it isn't important that I know the counter value, I only need to see that some frames have a transmit receipt, meaning the frames are being read. Trying to come up with a minimized setup that reproduces this issue is resulting in it working...
Edit: Actually I found a bug where I wasn't always updating the decrement. Seems good now.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
@LP_C It looks to me like you're trying to do too much in your single "SUB VI".
The problem is that you're constantly opening and closing the port/channel. It's only open for a very short period of time before it's closed again so your missing all the messages. You need to keep the channel activated so the messages get stored in the receive queue, then you can read them out in the next loop iteration. Have a look where the while loop is in my receive example. You have to do something like that or make an "Action engine" style VI that stores the active port handle and state inside it etc.
Hello again Mr. Troy.
You are really wise when it comes to Vector Can-case labview communications; Like the transmit only VI, isn't there a recieve Vi where you specify the ID you want to recieve and you recieve it in an array and all cool?
Regards
There are a couple options. The easiest in my mind is to use software to filter out the IDs you don't want. You can still read all IDs so maybe logging all of them, but only acting on a specific range is possible. Or the Add Acceptance Range, and CAN Set Channel Acceptance which tells the hardware to only return specific IDs in the receive.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
Hey TroyK I hope you don't mind but I took your Vector source, and cleaned it up a bit, making the palette look more like NI CAN APIs like XNet, and packaged it up along with some Kvaser, and Intrepid drivers, along with a few other tools. I posted it in one of my blog posts on CAN. I plan on making a community post on NI.com eventually and not just a blog post. It clearly focuses on the CAN part of the DLL wrapper.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
@Hooovahh That's awesome. Sounds very useful. I've just recently been forced to use Intrepid hardware and their API is atrocious compared to Vectors. I wish I had your "Hooovahh CAN package" earlier, it would have saved me a lot of frustration I'm sure.
I'm happy you were able to use my wrappers as a starting point for the Vector side of things.
You don't mind if I add a link here to your VI Package community post once you upload it do you?
Sure thing. The Intrepid stuff I don't think I cleaned up that much. I did improve the performance of things like a read, because they were converting to and from a couple of different data types. I also don't think they were breaking out the Network Type which is important because most devices like the NeoFire have multiple buses, and previously you would perform a read and get a bunch of frames back but not know which frames belong to which bus. I also broke out the high voltage wake up for single wire CAN.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
HI,
good work.
The vi's work until "xl Can Transmit.vi".
Here i get always the error "101 XL_ERR_WRONG_PARAMETER".
I try different settings in the "hwindex", "hwChannel" parameters but without success.
I use the VN1610.
The first channel of them.
The sample "CAN Receive Example.vi" works with the same settings fine.
hwIndex = 0;
hwChannel = 0;
hwType = VN1610 = 55d
If i make a break befor the vi "xl Can Transmit.vi". will start i see in the Vector HW config the user "user" has access to the channel 1 an is online.
Have you a idea that i make wrong?
Regards
wolf4124
What ID, DLC and Data are you trying to send? One possible cause is trying to send an EXT ID message on a bus defined as STD.
I am trying to use VN89xx and it has pin assignments as in the Picture attached. Is it possible to Change the Pin assignment after activating the channel?
I want to change the number of Inputs based on user Input or from the loaded model and i dont want to Keep it static. Is there a possibility?
The XL Driver tells that we can only configure ports once.