07-26-2024 09:00 AM - edited 07-26-2024 09:02 AM
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.
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.
07-26-2024 10:04 AM
Oh that looks cool, could you save it in 2016 version and resend it. Thank you.
07-26-2024 11:59 AM - edited 07-26-2024 12:06 PM
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)
07-29-2024 03:57 AM
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.
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.
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.
07-29-2024 10:05 AM
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.
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.
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.
07-29-2024 12:16 PM
@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.
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.
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.
07-30-2024 02:24 PM
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!