LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get CAN Bus Ports

When using the NI-CAN Frame, or Channel API, you must configure the port calling the port "CAN0" through "CAN63", with a couple virtual ports.  What I want to know, is how can I determine, which ports are valid?  Meaning which ports have hardware plugged in and assigned to them?  Please don't have your answer mention XNet, we are only talking about NI-CAN.

 

In MAX you can see which ports are available, and so one option (but ugly) could be to create a MAX report programatically, then read the report and find which ports are valid.  I've tried using the MAX System Configuration palette, and this does find the hardware, but not the interface.  Any help is appreciated thanks.

0 Kudos
Message 1 of 6
(3,144 Views)

Hello Hooovahh,

 

One potential method that you may use to establish which ports have hardware connected is to call all available ports, "CAN0" - "CAN63," and those that do not have hardware connected will send back a timeout error. If this is a process that you will not need to run frequently, calling all available ports may be a possible solution.

Wes W
Application Engineering
National Instruments
www.ni.com/support
0 Kudos
Message 2 of 6
(3,113 Views)

Yeah I did think of this as well.  I ended up using the MAX report to determine what ports are available to the system.  This method takes about 4 seconds on my system which is kind of anoying, but I will just have a refresh option, and only use it (or call it) on start of the application.  Attached is my method saved in 2011.

0 Kudos
Message 3 of 6
(3,100 Views)

Hello Hooovahh, 

 

Thank you for including the work around you have created. I'm sure this will help future customers who are facing the same issue. 

Wes W
Application Engineering
National Instruments
www.ni.com/support
0 Kudos
Message 4 of 6
(3,086 Views)

So another 4 years later, is there any better working solution for this?  I ask because I have a system now that shows available CAN hardware, and allows to open a specific port with various settings.  This software works with many CAN hardware and not just NI-CAN devices, and needs to allow the user to perform a refresh where they can see all the devices available and pick one to use.  Keep in mind they may already have N other sessions open and doing things.

 

This eliminates the possiblity of just opening each CAN0 through CAN63 one at a time, because the hardware maybe valid, but trying to open a session that is already open will return an error, but it is a valid port number and should be shown.  Using the MAX report option I posted earlier works, but takes 20 seconds or so to do a refresh, and if MAX is open then an error may occur for other non-NI hardware (like an embedded webcam) which has nothing to do with this, except for the fact that MAX will have a popup error waiting to be confimred before generating the report.  And the user of my software won't know why the refresh is taking so long.

0 Kudos
Message 5 of 6
(2,852 Views)

So I feel a little silly.  I remember trying to use the Hardware Info function and not being able to get it to work.  Well now that I play around with it some more I figured it out.

 

Example_VI_BD.png

Message 6 of 6
(2,841 Views)