LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CAN question

I am assuming the next question will be about a LabVIEW wrapper...

I made my own wrapper that works with the CAN USB HW. It is missing a lot of stuff and there is lots of room for improvement.

 

Frozen_0-1722002058689.png

 

There was LOTS of trial and error to get it to the condition it is in. (Did I mention there is lots of room for improvement?)

IMPORTANT: You will need to put the "PCANBasic.dll" into the top folder.

 

Hopefully it will save you a bit of time.

Good luck.

 

---------------------------------------------
Certified LabVIEW Developer (CLD)
0 Kudos
Message 11 of 17
(285 Views)

Oh that looks cool, could you save it in 2016 version and resend it. Thank you.

0 Kudos
Message 12 of 17
(274 Views)

Saved in LV2016 (I hope)

 

Since there is no readme in the zip, here are some notes:

- put the PCANBasic.dll (x64 or x86) into the top folder so LV can find it. (download the PCAN basic SW package)

- the "PCANBasic.h" is not required for LV but it helps greatly in understanding the parameters to pass.

- Requires the PCAN drivers as well. (IE download and install the drivers)

---------------------------------------------
Certified LabVIEW Developer (CLD)
Message 13 of 17
(264 Views)

Just came back to work after the weekend and tried the 2016. And there is a problem. Did you try this with a ethernet adapter or PCAN USB? Because the VIs are not detecting the hardware. 

govindsankar_0-1722242510448.png

I am assuming since this is not a USB, I have to select the first one. And I get this error which says the PCAN channel is invalid. Regarding the drivers I need to install, I have installed all the PEAK drivers.

govindsankar_3-1722243444618.png

 

Thats how I was able to communicate using PCAN View with the ethernet adapter. Or is there some special driver I need to install for LabVIEW to detect. Thank you. 

0 Kudos
Message 14 of 17
(239 Views)

So, ignore my message above. Because there is a chance I cant use APIs, instead use raw TCP/IP. So finally I figured out the CAN frame to send via TCP/IP.

govindsankar_0-1722264703493.png

The thing that was holding me back mainly was the CRC check. I was able to calculate CRC from a labview program i downloaded from NI forum. I have uploaded the program here called correct CRC32 for PCAN. Then I write a program where I send in the entire CAN frame as a hex value using TCP write and then read out using TCP read. It is writing successfully without any error. But no value is coming for reading. There is no error also from TCP read, just there is no output.  So I have uploaded the program here as well, it is called PCAN_TCP. So the CAN Frame I am writing in is

2800810000000000000000000000000000000000080000000002097A000000000000005A202A8B.

Can DLC is 08

Out of which CAN ID is 0209

Can Data is 7A00000000000000

Checksum calculated with other program then written in little endian will be 5A202A8B. The format I used to create the CAN frame is this.

govindsankar_1-1722265351017.png

 

 

govindsankar_2-1722265471733.png

 

This is the program as a picture. I am assuming this is correct. Can anyone help me in pointing me in the right direction as to where I am going wrong here. Thank you.

 

 

Download All
0 Kudos
Message 15 of 17
(208 Views)
@Frozen wrote:

Saved in LV2016 (I hope)

 

Since there is no readme in the zip, here are some notes:

- put the PCANBasic.dll (x64 or x86) into the top folder so LV can find it. (download the PCAN basic SW package)

- the "PCANBasic.h" is not required for LV but it helps greatly in understanding the parameters to pass.

- Requires the PCAN drivers as well. (IE download and install the drivers)


 

Actually, if you select the PCAN Basic API while installing the driver then the DLL will be present in System32 and SysWOW64 and LabVIEW will find them there just fine. I prefer this over packaging the DLL with my application because it handles the bitness for you and you ensure the DLL matches the driver version installed.

 

 

 


@govindsankar wrote:

Just came back to work after the weekend and tried the 2016. And there is a problem. Did you try this with a ethernet adapter or PCAN USB? Because the VIs are not detecting the hardware. 

govindsankar_0-1722242510448.png

I am assuming since this is not a USB, I have to select the first one. And I get this error which says the PCAN channel is invalid. Regarding the drivers I need to install, I have installed all the PEAK drivers.

govindsankar_3-1722243444618.png

 

Thats how I was able to communicate using PCAN View with the ethernet adapter. Or is there some special driver I need to install for LabVIEW to detect. Thank you. 


LabVIEW knows absolutely nothing about this hardware and is not detecting anything. If you want to know that then you will need to use the API to query attached channels and then enumerate the results yourself. In the simpler use case where you only support a single instance of a specific hardware type, you should be able to hardcode, for example, PCAN_LANBUS1.

 

And that's your next problem. They did not include all possible defined PCAN channels in their channels enum. PCAN_NONEBUS (0x00) is only used for API functions that do not apply to a specific channel. If you're using Ethernet, then you want one of these for initialization, to get/set the IP address, etc.:

 

 

#define PCAN_LANBUS1                  0x801U  // PCAN-LAN interface, channel 1
#define PCAN_LANBUS2                  0x802U  // PCAN-LAN interface, channel 2
#define PCAN_LANBUS3                  0x803U  // PCAN-LAN interface, channel 3
#define PCAN_LANBUS4                  0x804U  // PCAN-LAN interface, channel 4
#define PCAN_LANBUS5                  0x805U  // PCAN-LAN interface, channel 5
#define PCAN_LANBUS6                  0x806U  // PCAN-LAN interface, channel 6
#define PCAN_LANBUS7                  0x807U  // PCAN-LAN interface, channel 7
#define PCAN_LANBUS8                  0x808U  // PCAN-LAN interface, channel 8
#define PCAN_LANBUS9                  0x809U  // PCAN-LAN interface, channel 9
#define PCAN_LANBUS10                 0x80AU  // PCAN-LAN interface, channel 10
#define PCAN_LANBUS11                 0x80BU  // PCAN-LAN interface, channel 11
#define PCAN_LANBUS12                 0x80CU  // PCAN-LAN interface, channel 12
#define PCAN_LANBUS13                 0x80DU  // PCAN-LAN interface, channel 13
#define PCAN_LANBUS14                 0x80EU  // PCAN-LAN interface, channel 14
#define PCAN_LANBUS15                 0x80FU  // PCAN-LAN interface, channel 15
#define PCAN_LANBUS16                 0x810U  // PCAN-LAN interface, channel 16

You can find the others in PCANBasic.h, but unfortunately the list of defined values is not contiguous. This is another case where I wish LabVIEW supported sparse enums.

 

0 Kudos
Message 16 of 17
(202 Views)

You might have missed the part where I said " It is missing a lot of stuff "

Please feel free to expand on what I have provided.

 

Good luck!

---------------------------------------------
Certified LabVIEW Developer (CLD)
0 Kudos
Message 17 of 17
(175 Views)