├── .github └── FUNDING.yml ├── Binaries ├── Intel_x86_64 │ ├── COPYRIGHT │ ├── LICENSE │ ├── PCBUSB.c │ ├── PCBUSB.h │ ├── README │ ├── install.sh │ ├── install.txt │ ├── libPCBUSB.0.1.dylib │ ├── libPCBUSB.0.10.1.dylib │ ├── libPCBUSB.0.10.dylib │ ├── libPCBUSB.0.11.1.dylib │ ├── libPCBUSB.0.11.2.dylib │ ├── libPCBUSB.0.11.dylib │ ├── libPCBUSB.0.12.1.dylib │ ├── libPCBUSB.0.12.2.dylib │ ├── libPCBUSB.0.12.dylib │ ├── libPCBUSB.0.13.dylib │ ├── libPCBUSB.0.2.dylib │ ├── libPCBUSB.0.3.dylib │ ├── libPCBUSB.0.4.dylib │ ├── libPCBUSB.0.5.dylib │ ├── libPCBUSB.0.6.dylib │ ├── libPCBUSB.0.7.dylib │ ├── libPCBUSB.0.8.1.dylib │ ├── libPCBUSB.0.8.dylib │ └── libPCBUSB.0.9.dylib └── Universal_64 │ ├── COPYRIGHT │ ├── LICENSE │ ├── PCBUSB.c │ ├── PCBUSB.h │ ├── README │ ├── install.sh │ ├── install.txt │ ├── libPCBUSB.0.10.1.dylib │ ├── libPCBUSB.0.11.1.dylib │ ├── libPCBUSB.0.11.2.dylib │ ├── libPCBUSB.0.11.dylib │ ├── libPCBUSB.0.12.1.dylib │ ├── libPCBUSB.0.12.2.dylib │ ├── libPCBUSB.0.12.dylib │ ├── libPCBUSB.0.13.dylib │ └── libPCBUSB.a ├── Examples ├── C++ │ ├── Makefile │ └── src │ │ ├── pcbusb_recv.cpp │ │ └── pcbusb_send.cpp ├── Makefile └── Python │ ├── Makefile │ ├── PCANBasic.py │ └── pcbusb_recv.py ├── LICENSE └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: mac-can # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013-2023 by UV Software, Berlin, Germany. 2 | 3 | All rights reserved. / Alle Rechte vorbehalten. 4 | 5 | 6 | Contact: / Anschrift: 7 | 8 | Uwe Vogt 9 | UV Software 10 | 11 | Chausseestrasse 33 A 12 | 10115 Berlin, Germany 13 | 14 | E-Mail: mailto:info@mac-can.com 15 | Internet: http://www.mac-can.com -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/LICENSE: -------------------------------------------------------------------------------- 1 | macOS Library for PCAN-USB Interfaces - Copyright (C) 2013-2024 by UV Software 2 | All rights reserved. 3 | 4 | 5 | END-USER LICENSE AGREEMENT FOR THIS SOFTWARE 6 | Important - read carefully! 7 | 8 | This End-User License Agreement ("EULA") is a legal agreement between 9 | you ("Licensee") and UV Software ("Licensor") for the software product 10 | identified above, which includes computer software and may include 11 | associated media, printed materials, and "online" or electronic 12 | documentation ("SOFTWARE PRODUCT"). By installing, copying, or otherwise 13 | using the SOFTWARE PRODUCT, you agree to be bound by the terms of this 14 | EULA. If you do not agree to the terms of this EULA, do not install or 15 | use the SOFTWARE PRODUCT. 16 | 17 | 18 | SOFTWARE PRODUCT LICENSE 19 | 20 | The SOFTWARE PRODUCT is licensed, not sold. 21 | 22 | The definition of SOFTWARE PRODUCT includes any files generated by the 23 | SOFTWARE PRODUCT. 24 | 25 | 26 | 1. GRANT OF LICENSE 27 | 28 | This EULA grants you the following rights: 29 | 30 | Installation and Use: You may install and use an unlimited number of 31 | copies of the SOFTWARE PRODUCT. 32 | 33 | Reproduction and Distribution: You may reproduce and distribute an 34 | unlimited number of copies of the SOFTWARE PRODUCT; provided that each 35 | copy shall be a true and complete copy, including all copyright and 36 | trademark notices, and shall be accompanied by a copy of this EULA. 37 | Copies of the SOFTWARE PRODUCT may be distributed as a standalone 38 | product or included with your own product. 39 | 40 | 41 | 2. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS 42 | 43 | Limitations on Reverse Engineering, Decompilation, and Disassembly: You 44 | may not reverse engineer, decompile or disassemble the SOFTWARE PRODUCT 45 | in any circumstances. 46 | 47 | Support Services: UV Software will not provide you with support services 48 | ("SUPPORT SERVICES") related to the SOFTWARE PRODUCT. 49 | 50 | Termination: Without prejudice to any other rights of UV Software, your 51 | rights under this EULA will terminate automatically without notice from 52 | UV Software if you fail to comply with any term(s) of this EULA. In such 53 | event you must destroy all copies of the SOFTWARE PRODUCT and any 54 | related materials. 55 | 56 | 57 | 3. LIMITED WARRANTY AND DISCLAIMER OF WARRANTY 58 | 59 | NO WARRANTIES: You expressly acknowledge and agree that use of the 60 | SOFTWARE PRODUCT is at your sole risk. The SOFTWARE PRODUCT is provided 61 | "AS IS" and without warranty of any kind. UV Software hereby EXPRESSLY 62 | DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED, 63 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF 64 | MERCHANTABILITY, NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. 65 | You are solely responsible for determining the appropriateness of using 66 | this SOFTWARE PRODUCT and assume all risks associated with the use of 67 | this SOFTWARE PRODUCT, including but not limited to the risks of program 68 | errors, damage to or loss of data, programs or equipment, and 69 | unavailability or interruption of operations. 70 | 71 | NO LIABILITY FOR DAMAGES: UNDER NO CIRCUMSTANCES, INCLUDING NEGLIGENCE, 72 | SHALL UV Software BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 73 | CONSEQUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS 74 | OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, 75 | OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF OR RELATING TO THIS LICENSE, 76 | EVEN IF UV Software HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 77 | In no event shall UV Software's total liability to you for all damages 78 | exceed the amount paid for this license to the SOFTWARE PRODUCT. The 79 | entire risk arising out of use or performance of the SOFTWARE PRODUCT 80 | remains with you. 81 | 82 | 83 | 4. COPYRIGHT 84 | 85 | All title and copyrights in and to the SOFTWARE PRODUCT (including but 86 | not limited to any images, photographs, animations, video, audio, music, 87 | text, and "applets" incorporated into the SOFTWARE PRODUCT), the 88 | accompanying printed materials, and any copies of the SOFTWARE PRODUCT 89 | are owned by UV Software. The SOFTWARE PRODUCT is protected by copyright 90 | laws and international treaty provisions. Therefore, you must treat the 91 | SOFTWARE PRODUCT like any other copyrighted material. 92 | 93 | 94 | 5. TRADEMARKS 95 | 96 | All product and company names mentioned in the SOFTWARE PRODUCT may be 97 | trademarks and/or service marks of their respective owners. 98 | 99 | 100 | 6. GOVERNING LAW 101 | 102 | This agreement shall be governed by the laws of Germany. 103 | 104 | 105 | 7. MISCELLANEOUS 106 | 107 | If for any reason a court of competent jurisdiction finds any provision, 108 | or portion of this EULA, to be unenforceable, the remainder of this EULA 109 | shall continue in full force and effect. This EULA constitutes the entire 110 | agreement between the parties with respect to the use of the SOFTWARE 111 | PRODUCT and supersedes all prior or contemporaneous understandings 112 | regarding such subject matter. No amendment to or modification of this 113 | EULA will be binding unless in writing and signed by UV Software. 114 | 115 | 116 | 117 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 118 | Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany 119 | Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 120 | E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/PCBUSB.c: -------------------------------------------------------------------------------- 1 | // 2 | // PCBUSB.c 3 | // MacCAN Monitor 4 | // Wrapper for libPCBUSB 5 | // 6 | // Created by Uwe Vogt on 18.08.13. 7 | // Copyright (c) 2013-2024 UV Software. All rights reserved. 8 | // 9 | // This software is freeware without any warranty or support! 10 | // 11 | // NO WARRANTIES: You expressly acknowledge and agree that use of the 12 | // SOFTWARE PRODUCT is at your sole risk. The SOFTWARE PRODUCT is provided 13 | // "AS IS" and without warranty of any kind. UV Software hereby EXPRESSLY 14 | // DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF 16 | // MERCHANTABILITY, NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. 17 | // You are solely responsible for determining the appropriateness of using 18 | // this SOFTWARE PRODUCT and assume all risks associated with the use of 19 | // this SOFTWARE PRODUCT, including but not limited to the risks of program 20 | // errors, damage to or loss of data, programs or equipment, and 21 | // unavailability or interruption of operations. 22 | // 23 | // NO LIABILITY FOR DAMAGES: UNDER NO CIRCUMSTANCES, INCLUDING NEGLIGENCE, 24 | // SHALL UV Software BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 25 | // CONSEQUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS 26 | // OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, 27 | // OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF OR RELATING TO THIS LICENSE, 28 | // EVEN IF UV Software HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 29 | // In no event shall UV Software's total liability to you for all damages 30 | // exceed the amount paid for this license to the SOFTWARE PRODUCT. The 31 | // entire risk arising out of use or performance of the SOFTWARE PRODUCT 32 | // remains with you. 33 | // 34 | #if defined(__APPLE__) 35 | #include "PCBUSB.h" 36 | #define CAN_LIBRARY "libPCBUSB.dylib" 37 | #else 38 | #include "PCANBasic.h" 39 | #define CAN_LIBRARY "libpcanbasic.so" 40 | #endif 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | typedef TPCANStatus (*CAN_Initialize_t)(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt); 47 | typedef TPCANStatus (*CAN_Uninitialize_t)(TPCANHandle Channel); 48 | typedef TPCANStatus (*CAN_Reset_t)(TPCANHandle Channel); 49 | typedef TPCANStatus (*CAN_GetStatus_t)(TPCANHandle Channel); 50 | typedef TPCANStatus (*CAN_Read_t)(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer); 51 | typedef TPCANStatus (*CAN_Write_t)(TPCANHandle Channel, TPCANMsg* MessageBuffer); 52 | typedef TPCANStatus (*CAN_FilterMessages_t)(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode); 53 | typedef TPCANStatus (*CAN_GetValue_t)(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); 54 | typedef TPCANStatus (*CAN_SetValue_t)(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); 55 | typedef TPCANStatus (*CAN_GetErrorText_t)(TPCANStatus Error, WORD Language, char* Buffer); 56 | typedef TPCANStatus (*CAN_InitializeFD_t)(TPCANHandle Channel, TPCANBitrateFD BitrateFD); 57 | typedef TPCANStatus (*CAN_ReadFD_t)(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer); 58 | typedef TPCANStatus (*CAN_WriteFD_t)(TPCANHandle Channel, TPCANMsgFD* MessageBuffer); 59 | typedef TPCANStatus (*CAN_LookUpChannel_t)(LPSTR Parameters, TPCANHandle* FoundChannel); 60 | 61 | static CAN_Initialize_t fpCAN_Initialize = NULL; 62 | static CAN_Uninitialize_t fpCAN_Uninitialize = NULL; 63 | static CAN_Reset_t fpCAN_Reset = NULL; 64 | static CAN_GetStatus_t fpCAN_GetStatus = NULL; 65 | static CAN_Read_t fpCAN_Read = NULL; 66 | static CAN_Write_t fpCAN_Write = NULL; 67 | static CAN_FilterMessages_t fpCAN_FilterMessages = NULL; 68 | static CAN_GetValue_t fpCAN_GetValue = NULL; 69 | static CAN_SetValue_t fpCAN_SetValue = NULL; 70 | static CAN_GetErrorText_t fpCAN_GetErrorText = NULL; 71 | static CAN_InitializeFD_t fpCAN_InitializeFD = NULL; 72 | static CAN_ReadFD_t fpCAN_ReadFD = NULL; 73 | static CAN_WriteFD_t fpCAN_WriteFD = NULL; 74 | static CAN_LookUpChannel_t fpCAN_LookUpChannel = NULL; 75 | 76 | static void *hLibrary = NULL; 77 | 78 | static int LoadLibrary(void) { 79 | if (!hLibrary) { 80 | errno = 0; 81 | hLibrary = dlopen(CAN_LIBRARY, RTLD_LAZY); 82 | if (!hLibrary) 83 | return -1; 84 | if ((fpCAN_Initialize = (CAN_Initialize_t)dlsym(hLibrary, "CAN_Initialize")) == NULL) 85 | goto err; 86 | if ((fpCAN_Uninitialize = (CAN_Uninitialize_t)dlsym(hLibrary, "CAN_Uninitialize")) == NULL) 87 | goto err; 88 | if ((fpCAN_Reset = (CAN_Reset_t)dlsym(hLibrary, "CAN_Reset")) == NULL) 89 | goto err; 90 | if ((fpCAN_GetStatus = (CAN_GetStatus_t)dlsym(hLibrary, "CAN_GetStatus")) == NULL) 91 | goto err; 92 | if ((fpCAN_Read = (CAN_Read_t)dlsym(hLibrary, "CAN_Read")) == NULL) 93 | goto err; 94 | if ((fpCAN_Write = (CAN_Write_t)dlsym(hLibrary, "CAN_Write")) == NULL) 95 | goto err; 96 | if ((fpCAN_FilterMessages = (CAN_FilterMessages_t)dlsym(hLibrary, "CAN_FilterMessages")) == NULL) 97 | goto err; 98 | if ((fpCAN_GetValue = (CAN_GetValue_t)dlsym(hLibrary, "CAN_GetValue")) == NULL) 99 | goto err; 100 | if ((fpCAN_SetValue = (CAN_SetValue_t)dlsym(hLibrary, "CAN_SetValue")) == NULL) 101 | goto err; 102 | if ((fpCAN_GetErrorText = (CAN_GetErrorText_t)dlsym(hLibrary, "CAN_GetErrorText")) == NULL) 103 | goto err; 104 | if ((fpCAN_InitializeFD = (CAN_InitializeFD_t)dlsym(hLibrary, "CAN_InitializeFD")) == NULL) 105 | goto err; 106 | if ((fpCAN_ReadFD = (CAN_ReadFD_t)dlsym(hLibrary, "CAN_ReadFD")) == NULL) 107 | goto err; 108 | if ((fpCAN_WriteFD = (CAN_WriteFD_t)dlsym(hLibrary, "CAN_WriteFD")) == NULL) 109 | goto err; 110 | if ((fpCAN_LookUpChannel = (CAN_LookUpChannel_t)dlsym(hLibrary, "CAN_LookUpChannel")) == NULL) 111 | fpCAN_LookUpChannel = NULL; // New function w/o implementation: accept the NULL pointer! 112 | } 113 | return 0; 114 | err: 115 | fpCAN_Initialize = NULL; 116 | fpCAN_Uninitialize = NULL; 117 | fpCAN_Reset = NULL; 118 | fpCAN_GetStatus = NULL; 119 | fpCAN_Read = NULL; 120 | fpCAN_Write = NULL; 121 | fpCAN_FilterMessages = NULL; 122 | fpCAN_GetValue = NULL; 123 | fpCAN_SetValue = NULL; 124 | fpCAN_GetErrorText = NULL; 125 | #ifndef CAN_2_0_ONLY 126 | fpCAN_InitializeFD = NULL; 127 | fpCAN_ReadFD = NULL; 128 | fpCAN_WriteFD = NULL; 129 | #endif 130 | fpCAN_LookUpChannel = NULL; 131 | dlclose(hLibrary); 132 | hLibrary = NULL; 133 | return -1; 134 | } 135 | 136 | TPCANStatus CAN_Initialize(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt) { 137 | if (LoadLibrary() != 0) 138 | return PCAN_ERROR_NODRIVER; 139 | if (fpCAN_Initialize) 140 | return fpCAN_Initialize(Channel, Btr0Btr1, HwType, IOPort, Interrupt); 141 | else 142 | return PCAN_ERROR_UNKNOWN; 143 | } 144 | 145 | TPCANStatus CAN_Uninitialize(TPCANHandle Channel) { 146 | //if (LoadLibrary() != 0) 147 | // return PCAN_ERROR_NODRIVER; 148 | if (fpCAN_Uninitialize) 149 | return fpCAN_Uninitialize(Channel); 150 | else 151 | return PCAN_ERROR_UNKNOWN; 152 | } 153 | 154 | TPCANStatus CAN_Reset(TPCANHandle Channel) { 155 | if (LoadLibrary() != 0) 156 | return PCAN_ERROR_NODRIVER; 157 | if (fpCAN_Reset) 158 | return fpCAN_Reset(Channel); 159 | else 160 | return PCAN_ERROR_UNKNOWN; 161 | } 162 | 163 | TPCANStatus CAN_GetStatus(TPCANHandle Channel) { 164 | if (LoadLibrary() != 0) 165 | return PCAN_ERROR_NODRIVER; 166 | if (fpCAN_GetStatus) 167 | return fpCAN_GetStatus(Channel); 168 | else 169 | return PCAN_ERROR_UNKNOWN; 170 | } 171 | 172 | TPCANStatus CAN_Read(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer) { 173 | if (LoadLibrary() != 0) 174 | return PCAN_ERROR_NODRIVER; 175 | if (fpCAN_Read) 176 | return fpCAN_Read(Channel, MessageBuffer, TimestampBuffer); 177 | else 178 | return PCAN_ERROR_UNKNOWN; 179 | } 180 | 181 | TPCANStatus CAN_Write(TPCANHandle Channel, TPCANMsg* MessageBuffer) { 182 | if (LoadLibrary() != 0) 183 | return PCAN_ERROR_NODRIVER; 184 | if (fpCAN_Write) 185 | return fpCAN_Write(Channel, MessageBuffer); 186 | else 187 | return PCAN_ERROR_UNKNOWN; 188 | } 189 | 190 | TPCANStatus CAN_FilterMessages(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode) { 191 | if (LoadLibrary() != 0) 192 | return PCAN_ERROR_NODRIVER; 193 | if (fpCAN_FilterMessages) 194 | return fpCAN_FilterMessages(Channel, FromID, ToID, Mode); 195 | else 196 | return PCAN_ERROR_UNKNOWN; 197 | } 198 | 199 | TPCANStatus CAN_GetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength) { 200 | if (LoadLibrary() != 0) 201 | return PCAN_ERROR_NODRIVER; 202 | if (fpCAN_GetValue) 203 | return fpCAN_GetValue(Channel, Parameter, Buffer, BufferLength); 204 | else 205 | return PCAN_ERROR_UNKNOWN; 206 | } 207 | 208 | TPCANStatus CAN_SetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength) { 209 | if (LoadLibrary() != 0) 210 | return PCAN_ERROR_NODRIVER; 211 | if (fpCAN_SetValue) 212 | return fpCAN_SetValue(Channel, Parameter, Buffer, BufferLength); 213 | else 214 | return PCAN_ERROR_UNKNOWN; 215 | } 216 | 217 | TPCANStatus CAN_GetErrorText(TPCANStatus Error, WORD Language, char* Buffer) { 218 | if (LoadLibrary() != 0) { 219 | if (Buffer) 220 | strcpy(Buffer, "PCBUSB library could not be loaded"); 221 | return PCAN_ERROR_NODRIVER; 222 | } 223 | if (fpCAN_GetErrorText) 224 | return fpCAN_GetErrorText(Error, Language, Buffer); 225 | else 226 | return PCAN_ERROR_UNKNOWN; 227 | } 228 | 229 | TPCANStatus CAN_InitializeFD(TPCANHandle Channel, TPCANBitrateFD BitrateFD) { 230 | if (LoadLibrary() != 0) 231 | return PCAN_ERROR_NODRIVER; 232 | if (fpCAN_InitializeFD) 233 | return fpCAN_InitializeFD(Channel, BitrateFD); 234 | else 235 | return PCAN_ERROR_UNKNOWN; 236 | } 237 | 238 | TPCANStatus CAN_ReadFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer) { 239 | if (LoadLibrary() != 0) 240 | return PCAN_ERROR_NODRIVER; 241 | if (fpCAN_ReadFD) 242 | return fpCAN_ReadFD(Channel, MessageBuffer, TimestampBuffer); 243 | else 244 | return PCAN_ERROR_UNKNOWN; 245 | } 246 | 247 | TPCANStatus CAN_WriteFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer) { 248 | if (LoadLibrary() != 0) 249 | return PCAN_ERROR_NODRIVER; 250 | if (fpCAN_WriteFD) 251 | return fpCAN_WriteFD(Channel, MessageBuffer); 252 | else 253 | return PCAN_ERROR_UNKNOWN; 254 | } 255 | 256 | TPCANStatus CAN_LookUpChannel(LPSTR Parameters, TPCANHandle* FoundChannel) { 257 | if (LoadLibrary() != 0) 258 | return PCAN_ERROR_NODRIVER; 259 | if (fpCAN_LookUpChannel) 260 | return fpCAN_LookUpChannel(Parameters, FoundChannel); 261 | else 262 | return PCAN_ERROR_UNKNOWN; 263 | } 264 | -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/PCBUSB.h: -------------------------------------------------------------------------------- 1 | /* -- $HeadURL: https://uv-software.net/MacCAN/PCANUSB/Library/trunk/drv/pcan_api.h $ -- 2 | * 3 | * project : CAN - Controller Area Network 4 | * 5 | * purpose : PCAN Application Programming Interface 6 | * 7 | * copyright : (C) 2012-2024 by UV Software, Berlin 8 | * 9 | * compiler : Apple clang version 15.0.0 (clang-1500.3.9.4) 10 | * 11 | * export : TPCANStatus CAN_Initialize(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt); 12 | * TPCANStatus CAN_Uninitialize(TPCANHandle Channel); 13 | * TPCANStatus CAN_Reset(TPCANHandle Channel); 14 | * TPCANStatus CAN_GetStatus(TPCANHandle Channel); 15 | * TPCANStatus CAN_Read(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer); 16 | * TPCANStatus CAN_Write(TPCANHandle Channel, TPCANMsg* MessageBuffer); 17 | * TPCANStatus CAN_FilterMessages(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode); 18 | * TPCANStatus CAN_GetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); 19 | * TPCANStatus CAN_SetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); 20 | * TPCANStatus CAN_GetErrorText(TPCANStatus Error, WORD Language, LPSTR Buffer); 21 | * *** CAN FD capable devices *** 22 | * TPCANStatus CAN_InitializeFD(TPCANHandle Channel, TPCANBitrateFD BitrateFD); 23 | * TPCANStatus CAN_ReadFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer); 24 | * TPCANStatus CAN_WriteFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer); 25 | * 26 | * includes : (none) 27 | * 28 | * author : Uwe Vogt, UV Software 29 | * 30 | * e-mail : uwe.vogt@uv-software.de 31 | * 32 | * 33 | * ----------- description -------------------------------------------- 34 | * 35 | * PCAN API - PEAK CAN Application Programming Interface 36 | * 37 | * This Application Programming Interface (API) is an almost compatible 38 | * implementation of the PEAK PCANBasic DLL on macOS (x86_64 and arm64). 39 | * 40 | * Supported CAN Interfaces: 41 | * - PCAN-USB (item no. IPEH-002021/002022) 42 | * - PCAN-USB FD (item no. IPEH-004022) 43 | * Up to 8 channel handles are supported. 44 | * 45 | * Version of PCAN API: 46 | * - Based on PEAK's version of 2024-01-26 47 | */ 48 | 49 | #ifndef PCAN_API_H_INCLUDED 50 | #define PCAN_API_H_INCLUDED 51 | 52 | /* ----------- includes ----------------------------------------------- 53 | */ 54 | 55 | #ifdef __APPLE__ 56 | #include // To map Windows integer types 57 | #endif 58 | 59 | /* ----------- defines ------------------------------------------------ 60 | */ 61 | 62 | #ifdef __APPLE__ 63 | #ifndef BYTE 64 | #define BYTE UInt8 65 | #endif 66 | #ifndef WORD 67 | #define WORD UInt16 68 | #endif 69 | #ifndef DWORD 70 | #define DWORD UInt32 71 | #endif 72 | #ifndef UINT64 73 | #define UINT64 UInt64 74 | #endif 75 | #ifndef LPSTR 76 | #define LPSTR char* 77 | #endif 78 | #define __T(s) s 79 | #endif 80 | 81 | /* Currently defined and supported PCAN channels 82 | */ 83 | #define PCAN_NONEBUS 0x00U //!< Undefined/default value for a PCAN bus 84 | 85 | #define PCAN_USBBUS1 0x51U //!< PCAN-USB interface, channel 1 86 | #define PCAN_USBBUS2 0x52U //!< PCAN-USB interface, channel 2 87 | #define PCAN_USBBUS3 0x53U //!< PCAN-USB interface, channel 3 88 | #define PCAN_USBBUS4 0x54U //!< PCAN-USB interface, channel 4 89 | #define PCAN_USBBUS5 0x55U //!< PCAN-USB interface, channel 5 90 | #define PCAN_USBBUS6 0x56U //!< PCAN-USB interface, channel 6 91 | #define PCAN_USBBUS7 0x57U //!< PCAN-USB interface, channel 7 92 | #define PCAN_USBBUS8 0x58U //!< PCAN-USB interface, channel 8 93 | #ifndef __APPLE__ 94 | #define PCAN_USBBUS9 0x509U //!< PCAN-USB interface, channel 9 95 | #define PCAN_USBBUS10 0x50AU //!< PCAN-USB interface, channel 10 96 | #define PCAN_USBBUS11 0x50BU //!< PCAN-USB interface, channel 11 97 | #define PCAN_USBBUS12 0x50CU //!< PCAN-USB interface, channel 12 98 | #define PCAN_USBBUS13 0x50DU //!< PCAN-USB interface, channel 13 99 | #define PCAN_USBBUS14 0x50EU //!< PCAN-USB interface, channel 14 100 | #define PCAN_USBBUS15 0x50FU //!< PCAN-USB interface, channel 15 101 | #define PCAN_USBBUS16 0x510U //!< PCAN-USB interface, channel 16 102 | #endif 103 | 104 | 105 | /* Represent the PCAN error and status codes 106 | */ 107 | #define PCAN_ERROR_OK 0x00000U //!< No error 108 | #define PCAN_ERROR_XMTFULL 0x00001U //!< Transmit buffer in CAN controller is full 109 | #define PCAN_ERROR_OVERRUN 0x00002U //!< CAN controller was read too late 110 | #define PCAN_ERROR_BUSLIGHT 0x00004U //!< Bus error: an error counter reached the 'light' limit 111 | #define PCAN_ERROR_BUSHEAVY 0x00008U //!< Bus error: an error counter reached the 'heavy' limit 112 | #define PCAN_ERROR_BUSWARNING PCAN_ERROR_BUSHEAVY //!< Bus error: an error counter reached the 'warning' limit 113 | #define PCAN_ERROR_BUSPASSIVE 0x40000U //!< Bus error: the CAN controller is error passive 114 | #define PCAN_ERROR_BUSOFF 0x00010U //!< Bus error: the CAN controller is in bus-off state 115 | #define PCAN_ERROR_ANYBUSERR (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE) //!< Mask for all bus errors 116 | #define PCAN_ERROR_QRCVEMPTY 0x00020U //!< Receive queue is empty 117 | #define PCAN_ERROR_QOVERRUN 0x00040U //!< Receive queue was read too late 118 | #define PCAN_ERROR_QXMTFULL 0x00080U //!< Transmit queue is full 119 | #define PCAN_ERROR_REGTEST 0x00100U //!< Test of the CAN controller hardware registers failed (no hardware found) 120 | #define PCAN_ERROR_NODRIVER 0x00200U //!< Driver not loaded 121 | #define PCAN_ERROR_HWINUSE 0x00400U //!< Hardware already in use by a Net 122 | #define PCAN_ERROR_NETINUSE 0x00800U //!< A Client is already connected to the Net 123 | #define PCAN_ERROR_ILLHW 0x01400U //!< Hardware handle is invalid 124 | #define PCAN_ERROR_ILLNET 0x01800U //!< Net handle is invalid 125 | #define PCAN_ERROR_ILLCLIENT 0x01C00U //!< Client handle is invalid 126 | #define PCAN_ERROR_ILLHANDLE (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) //!< Mask for all handle errors 127 | #define PCAN_ERROR_RESOURCE 0x02000U //!< Resource (FIFO, Client, timeout) cannot be created 128 | #define PCAN_ERROR_ILLPARAMTYPE 0x04000U //!< Invalid parameter 129 | #define PCAN_ERROR_ILLPARAMVAL 0x08000U //!< Invalid parameter value 130 | #define PCAN_ERROR_UNKNOWN 0x10000U //!< Unknown error 131 | #define PCAN_ERROR_ILLDATA 0x20000U //!< Invalid data, function, or action 132 | #define PCAN_ERROR_ILLMODE 0x80000U //!< Driver object state is wrong for the attempted operation 133 | #define PCAN_ERROR_CAUTION 0x2000000U //!< An operation was successfully carried out, however, irregularities were registered 134 | #define PCAN_ERROR_INITIALIZE 0x4000000U //!< Channel is not initialized [Value was changed from 0x40000 to 0x4000000] 135 | #define PCAN_ERROR_ILLOPERATION 0x8000000U //!< Invalid operation [Value was changed from 0x80000 to 0x8000000] 136 | 137 | /* PCAN devices 138 | */ 139 | #define PCAN_NONE 0x00U //!< Undefined, unknown or not selected PCAN device value 140 | #define PCAN_PEAKCAN 0x01U //!< PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API 141 | #define PCAN_ISA 0x02U //!< PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus 142 | #define PCAN_DNG 0x03U //!< PCAN-Dongle 143 | #define PCAN_PCI 0x04U //!< PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express 144 | #define PCAN_USB 0x05U //!< PCAN-USB and PCAN-USB Pro 145 | #define PCAN_PCC 0x06U //!< PCAN-PC Card 146 | #define PCAN_VIRTUAL 0x07U //!< PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API 147 | #define PCAN_LAN 0x08U //!< PCAN Gateway devices 148 | 149 | /* PCAN parameters 150 | */ 151 | #define PCAN_DEVICE_ID 0x01U //!< Device identifier parameter 152 | #define PCAN_5VOLTS_POWER 0x02U //!< 5-Volt power parameter 153 | #define PCAN_RECEIVE_EVENT 0x03U //!< PCAN receive event handler parameter 154 | #define PCAN_MESSAGE_FILTER 0x04U //!< PCAN message filter parameter 155 | #define PCAN_API_VERSION 0x05U //!< PCAN-Basic API version parameter 156 | #define PCAN_CHANNEL_VERSION 0x06U //!< PCAN device channel version parameter 157 | #define PCAN_BUSOFF_AUTORESET 0x07U //!< PCAN Reset-On-Busoff parameter 158 | #define PCAN_LISTEN_ONLY 0x08U //!< PCAN Listen-Only parameter 159 | #define PCAN_LOG_LOCATION 0x09U //!< Directory path for log files 160 | #define PCAN_LOG_STATUS 0x0AU //!< Debug-Log activation status 161 | #define PCAN_LOG_CONFIGURE 0x0BU //!< Configuration of the debugged information (LOG_FUNCTION_***) 162 | #define PCAN_LOG_TEXT 0x0CU //!< Custom insertion of text into the log file 163 | #define PCAN_CHANNEL_CONDITION 0x0DU //!< Availability status of a PCAN-Channel 164 | #define PCAN_HARDWARE_NAME 0x0EU //!< PCAN hardware name parameter 165 | #define PCAN_RECEIVE_STATUS 0x0FU //!< Message reception status of a PCAN-Channel 166 | #define PCAN_CONTROLLER_NUMBER 0x10U //!< CAN-Controller number of a PCAN-Channel 167 | #define PCAN_TRACE_LOCATION 0x11U //!< Directory path for PCAN trace files 168 | #define PCAN_TRACE_STATUS 0x12U //!< CAN tracing activation status 169 | #define PCAN_TRACE_SIZE 0x13U //!< Configuration of the maximum file size of a CAN trace 170 | #define PCAN_TRACE_CONFIGURE 0x14U //!< Configuration of the trace file storing mode (TRACE_FILE_***) 171 | #define PCAN_CHANNEL_IDENTIFYING 0x15U //!< Physical identification of a USB based PCAN-Channel by blinking its associated LED 172 | #define PCAN_CHANNEL_FEATURES 0x16U //!< Capabilities of a PCAN device (FEATURE_***) 173 | #define PCAN_BITRATE_ADAPTING 0x17U //!< Using of an existing bit rate (PCAN-View connected to a channel) 174 | #define PCAN_BITRATE_INFO 0x18U //!< Configured bit rate as Btr0Btr1 value 175 | #define PCAN_BITRATE_INFO_FD 0x19U //!< Configured bit rate as TPCANBitrateFD string 176 | #define PCAN_BUSSPEED_NOMINAL 0x1AU //!< Configured nominal CAN Bus speed as Bits per seconds 177 | #define PCAN_BUSSPEED_DATA 0x1BU //!< Configured CAN data speed as Bits per seconds 178 | #define PCAN_IP_ADDRESS 0x1CU //!< Remote address of a LAN channel as string in IPv4 format 179 | #define PCAN_LAN_SERVICE_STATUS 0x1DU //!< Status of the Virtual PCAN-Gateway Service 180 | #define PCAN_ALLOW_STATUS_FRAMES 0x1EU //!< Status messages reception status within a PCAN-Channel 181 | #define PCAN_ALLOW_RTR_FRAMES 0x1FU //!< RTR messages reception status within a PCAN-Channel 182 | #define PCAN_ALLOW_ERROR_FRAMES 0x20U //!< Error messages reception status within a PCAN-Channel 183 | #define PCAN_INTERFRAME_DELAY 0x21U //!< Delay, in microseconds, between sending frames 184 | #define PCAN_ACCEPTANCE_FILTER_11BIT 0x22U //!< Filter over code and mask patterns for 11-Bit messages 185 | #define PCAN_ACCEPTANCE_FILTER_29BIT 0x23U //!< Filter over code and mask patterns for 29-Bit messages 186 | #define PCAN_IO_DIGITAL_CONFIGURATION 0x24U //!< Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive 187 | #define PCAN_IO_DIGITAL_VALUE 0x25U //!< Value assigned to a 32 digital I/O pins of a PCAN-USB Chip 188 | #define PCAN_IO_DIGITAL_SET 0x26U //!< Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High 189 | #define PCAN_IO_DIGITAL_CLEAR 0x27U //!< Clear multiple digital I/O pins to 0 190 | #define PCAN_IO_ANALOG_VALUE 0x28U //!< Get value of a single analog input pin 191 | #define PCAN_FIRMWARE_VERSION 0x29U //!< Get the version of the firmware used by the device associated with a PCAN-Channel 192 | #define PCAN_ATTACHED_CHANNELS_COUNT 0x2AU //!< Get the amount of PCAN channels attached to a system 193 | #define PCAN_ATTACHED_CHANNELS 0x2BU //!< Get information about PCAN channels attached to a system 194 | #define PCAN_ALLOW_ECHO_FRAMES 0x2CU //!< Echo messages reception status within a PCAN-Channel 195 | #define PCAN_DEVICE_PART_NUMBER 0x2DU //!< Get the part number associated to a device 196 | #define PCAN_HARD_RESET_STATUS 0x2EU //!< Activation status of hard reset processing via CAN_Reset calls 197 | #define PCAN_LAN_CHANNEL_DIRECTION 0x2FU //!< Communication direction of a PCAN-Channel representing a PCAN-LAN interface 198 | #define PCAN_EXT_BTR0BTR1 0x80U //!< UVS: bit-timing register 199 | #define PCAN_EXT_TX_COUNTER 0x81U //!< UVS: number of transmitted frames 200 | #define PCAN_EXT_RX_COUNTER 0x82U //!< UVS: number of received frames 201 | #define PCAN_EXT_ERR_COUNTER 0x83U //!< UVS: number of error frames 202 | #define PCAN_EXT_RX_QUE_OVERRUN 0x84U //!< UVS: receive queue overrun counter 203 | #define PCAN_EXT_HARDWARE_VERSION 0x85U //!< UVS: version number of the interface firmware 204 | #define PCAN_EXT_SOFTWARE_VERSION 0x86U //!< UVS: version number of the driver respectively library 205 | #define PCAN_EXT_RECEIVE_CALLBACK 0x87U //!< UVS: callback function called on the reception of an URB 206 | #define PCAN_EXT_LOG_USB 0x8FU //!< UVS: Log USB communication (URB buffer <==> CAN messages) 207 | 208 | /* DEPRECATED parameters 209 | */ 210 | #define PCAN_DEVICE_NUMBER PCAN_DEVICE_ID //!< Deprecated parameter. Use PCAN_DEVICE_ID instead 211 | 212 | /* PCAN parameter values 213 | */ 214 | #define PCAN_PARAMETER_OFF 0x00U //!< The PCAN parameter is not set (inactive) 215 | #define PCAN_PARAMETER_ON 0x01U //!< The PCAN parameter is set (active) 216 | #define PCAN_FILTER_CLOSE 0x00U //!< The PCAN filter is closed. No messages will be received 217 | #define PCAN_FILTER_OPEN 0x01U //!< The PCAN filter is fully opened. All messages will be received 218 | #define PCAN_FILTER_CUSTOM 0x02U //!< The PCAN filter is custom configured. Only registered messages will be received 219 | #define PCAN_CHANNEL_UNAVAILABLE 0x00U //!< The PCAN-Channel handle is illegal, or its associated hardware is not available 220 | #define PCAN_CHANNEL_AVAILABLE 0x01U //!< The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in) 221 | #define PCAN_CHANNEL_OCCUPIED 0x02U //!< The PCAN-Channel handle is valid, and is already being used 222 | #define PCAN_CHANNEL_PCANVIEW (PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED) //!< The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect 223 | 224 | #define LOG_FUNCTION_DEFAULT 0x00U //!< Logs system exceptions / errors 225 | #define LOG_FUNCTION_ENTRY 0x01U //!< Logs the entries to the PCAN-Basic API functions 226 | #define LOG_FUNCTION_PARAMETERS 0x02U //!< Logs the parameters passed to the PCAN-Basic API functions 227 | #define LOG_FUNCTION_LEAVE 0x04U //!< Logs the exits from the PCAN-Basic API functions 228 | #define LOG_FUNCTION_WRITE 0x08U //!< Logs the CAN messages passed to the CAN_Write function 229 | #define LOG_FUNCTION_READ 0x10U //!< Logs the CAN messages received within the CAN_Read function 230 | #define LOG_FUNCTION_ALL 0xFFFFU //!< Logs all possible information within the PCAN-Basic API functions 231 | 232 | #define TRACE_FILE_SINGLE 0x00U //!< A single file is written until it size reaches PAN_TRACE_SIZE 233 | #define TRACE_FILE_SEGMENTED 0x01U //!< Traced data is distributed in several files with size PAN_TRACE_SIZE 234 | #define TRACE_FILE_DATE 0x02U //!< Includes the date into the name of the trace file 235 | #define TRACE_FILE_TIME 0x04U //!< Includes the start time into the name of the trace file 236 | #define TRACE_FILE_OVERWRITE 0x80U //!< Causes the overwriting of available traces (same name) 237 | #define TRACE_FILE_DATA_LENGTH 0x100U //!< Causes using the data length column ('l') instead of the DLC column ('L') in the trace file 238 | 239 | #define FEATURE_FD_CAPABLE 0x01U //!< Device supports flexible data-rate (CAN-FD) 240 | #define FEATURE_DELAY_CAPABLE 0x02U //!< Device supports a delay between sending frames (FPGA based USB devices) 241 | #define FEATURE_IO_CAPABLE 0x04U //!< Device supports I/O functionality for electronic circuits (USB-Chip devices) 242 | 243 | #define SERVICE_STATUS_STOPPED 0x01U //!< The service is not running 244 | #define SERVICE_STATUS_RUNNING 0x04U //!< The service is running 245 | 246 | #define LAN_DIRECTION_READ 0x01U //!< The PCAN-Channel is limited to incoming communication only 247 | #define LAN_DIRECTION_WRITE 0x02U //!< The PCAN-Channel is limited to outgoing communication only 248 | #define LAN_DIRECTION_READ_WRITE (LAN_DIRECTION_READ | LAN_DIRECTION_WRITE) // The PCAN-Channel communication is bidirectional 249 | 250 | /* Other constants 251 | */ 252 | #define MAX_LENGTH_HARDWARE_NAME 33 //!< Maximum length of the name of a device: 32 characters + terminator 253 | #define MAX_LENGTH_VERSION_STRING 256 //!< Maximum length of a version string: 255 characters + terminator 254 | 255 | /* PCAN message types 256 | */ 257 | #define PCAN_MESSAGE_STANDARD 0x00U //!< The PCAN message is a CAN Standard Frame (11-bit identifier) 258 | #define PCAN_MESSAGE_RTR 0x01U //!< The PCAN message is a CAN Remote-Transfer-Request Frame 259 | #define PCAN_MESSAGE_EXTENDED 0x02U //!< The PCAN message is a CAN Extended Frame (29-bit identifier) 260 | #define PCAN_MESSAGE_FD 0x04U //!< The PCAN message represents a FD frame in terms of CiA Specs 261 | #define PCAN_MESSAGE_BRS 0x08U //!< The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate) 262 | #define PCAN_MESSAGE_ESI 0x10U //!< The PCAN message represents a FD error state indicator(CAN FD transmitter was error active) 263 | #define PCAN_MESSAGE_ECHO 0x20U //!< The PCAN message represents an echo CAN Frame 264 | #define PCAN_MESSAGE_ERRFRAME 0x40U //!< The PCAN message represents an error frame 265 | #define PCAN_MESSAGE_STATUS 0x80U //!< The PCAN message represents a PCAN status message 266 | 267 | /* LookUp Parameters 268 | */ 269 | #define LOOKUP_DEVICE_TYPE __T("devicetype") //!< Lookup channel by Device type (see PCAN devices e.g. PCAN_USB) 270 | #define LOOKUP_DEVICE_ID __T("deviceid") //!< Lookup channel by device id 271 | #define LOOKUP_CONTROLLER_NUMBER __T("controllernumber") //!< Lookup channel by CAN controller 0-based index 272 | #define LOOKUP_IP_ADDRESS __T("ipaddress") //!< Lookup channel by IP address (LAN channels only) 273 | 274 | /* Frame Type / Initialization Mode 275 | */ 276 | #define PCAN_MODE_STANDARD PCAN_MESSAGE_STANDARD 277 | #define PCAN_MODE_EXTENDED PCAN_MESSAGE_EXTENDED 278 | 279 | /* Baud rate codes = BTR0/BTR1 register values for the CAN controller. 280 | * You can define your own Baud rate with the BTROBTR1 register. 281 | * Take a look at www.peak-system.com for their free software "BAUDTOOL" 282 | * to calculate the BTROBTR1 register for every bit rate and sample point. 283 | */ 284 | #define PCAN_BAUD_1M 0x0014U //!< 1 MBit/s 285 | #define PCAN_BAUD_800K 0x0016U //!< 800 kBit/s 286 | #define PCAN_BAUD_500K 0x001CU //!< 500 kBit/s 287 | #define PCAN_BAUD_250K 0x011CU //!< 250 kBit/s 288 | #define PCAN_BAUD_125K 0x031CU //!< 125 kBit/s 289 | #define PCAN_BAUD_100K 0x432FU //!< 100 kBit/s 290 | #define PCAN_BAUD_95K 0xC34EU //!< 95,238 kBit/s 291 | #define PCAN_BAUD_83K 0x852BU //!< 83,333 kBit/s 292 | #define PCAN_BAUD_50K 0x472FU //!< 50 kBit/s 293 | #define PCAN_BAUD_47K 0x1414U //!< 47,619 kBit/s 294 | #define PCAN_BAUD_33K 0x8B2FU //!< 33,333 kBit/s 295 | #define PCAN_BAUD_20K 0x532FU //!< 20 kBit/s 296 | #define PCAN_BAUD_10K 0x672FU //!< 10 kBit/s 297 | #define PCAN_BAUD_5K 0x7F7FU //!< 5 kBit/s 298 | 299 | /* Represents the configuration for a CAN bit rate 300 | * Note: 301 | * * Each parameter and its value must be separated with a '='. 302 | * * Each pair of parameter/value must be separated using ','. 303 | * 304 | * Example: 305 | * f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1 306 | */ 307 | #define PCAN_BR_CLOCK __T("f_clock") 308 | #define PCAN_BR_CLOCK_MHZ __T("f_clock_mhz") 309 | #define PCAN_BR_NOM_BRP __T("nom_brp") 310 | #define PCAN_BR_NOM_TSEG1 __T("nom_tseg1") 311 | #define PCAN_BR_NOM_TSEG2 __T("nom_tseg2") 312 | #define PCAN_BR_NOM_SJW __T("nom_sjw") 313 | #define PCAN_BR_NOM_SAMPLE __T("nom_sam") 314 | #define PCAN_BR_DATA_BRP __T("data_brp") 315 | #define PCAN_BR_DATA_TSEG1 __T("data_tseg1") 316 | #define PCAN_BR_DATA_TSEG2 __T("data_tseg2") 317 | #define PCAN_BR_DATA_SJW __T("data_sjw") 318 | #define PCAN_BR_DATA_SAMPLE __T("data_ssp_offset") 319 | 320 | /* ----------- types -------------------------------------------------- 321 | */ 322 | 323 | #define TPCANHandle WORD //!< Represents a PCAN hardware channel handle 324 | #define TPCANStatus DWORD //!< Represents a PCAN status/error code (ATTENTION: changed from 64-bit to 32-bit) 325 | #define TPCANParameter BYTE //!< Represents a PCAN parameter to be read or set 326 | #define TPCANDevice BYTE //!< Represents a PCAN device 327 | #define TPCANMessageType BYTE //!< Represents the type of a PCAN message 328 | #define TPCANType BYTE //!< Represents the type of PCAN hardware to be initialized 329 | #define TPCANMode BYTE //!< Represents a PCAN filter mode 330 | #define TPCANBaudrate WORD //!< Represents a PCAN Baud rate register value 331 | #define TPCANBitrateFD LPSTR //!< Represents a PCAN-FD bit rate string 332 | #define TPCANTimestampFD UINT64//!< Represents a timestamp of a received PCAN FD message 333 | 334 | /** Represents a PCAN message 335 | */ 336 | typedef struct tagTPCANMsg 337 | { 338 | DWORD ID; //!< 11/29-bit message identifier 339 | TPCANMessageType MSGTYPE; //!< Type of the message 340 | BYTE LEN; //!< Data Length Code of the message (0..8) 341 | BYTE DATA[8]; //!< Data of the message (DATA[0]..DATA[7]) 342 | } TPCANMsg; 343 | 344 | /** Represents a timestamp of a received PCAN message 345 | * Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow 346 | */ 347 | typedef struct tagTPCANTimestamp 348 | { 349 | DWORD millis; //!< Base-value: milliseconds: 0.. 2^32-1 350 | WORD millis_overflow; //!< Roll-arounds of millis 351 | WORD micros; //!< Microseconds: 0..999 352 | } TPCANTimestamp; 353 | 354 | /** Represents a PCAN message from a FD capable hardware 355 | */ 356 | typedef struct tagTPCANMsgFD 357 | { 358 | DWORD ID; //!< 11/29-bit message identifier 359 | TPCANMessageType MSGTYPE; //!< Type of the message 360 | BYTE DLC; //!< Data Length Code of the message (0..15) 361 | BYTE DATA[64];//!< Data of the message (DATA[0]..DATA[63]) 362 | } TPCANMsgFD; 363 | 364 | /** Describes an available PCAN channel 365 | */ 366 | typedef struct tagTPCANChannelInformation 367 | { 368 | TPCANHandle channel_handle; //!< PCAN channel handle 369 | TPCANDevice device_type; //!< Kind of PCAN device 370 | BYTE controller_number; //!< CAN-Controller number 371 | DWORD device_features; //!< Device capabilities flag (see FEATURE_*) 372 | char device_name[MAX_LENGTH_HARDWARE_NAME]; //!< Device name 373 | DWORD device_id; //!< Device number 374 | DWORD channel_condition; //!< Availability status of a PCAN-Channel 375 | }TPCANChannelInformation; 376 | 377 | 378 | /* ----------- variables ---------------------------------------------- 379 | */ 380 | 381 | 382 | /* ----------- prototypes --------------------------------------------- 383 | */ 384 | 385 | #ifdef __cplusplus 386 | extern "C" { 387 | #define _DEF_ARG =0 388 | #else 389 | #define _DEF_ARG 390 | #endif 391 | 392 | /** @brief Initializes a PCAN Channel. 393 | * 394 | * @param[in] Channel The handle of a PCAN Channel. 395 | * @param[in] Btr0Btr1 The speed for the communication (BTR0BTR1 code). 396 | * @param[in] HwType (not used with PCAN USB devices) 397 | * @param[in] IOPort (not used with PCAN USB devices) 398 | * @param[in] Interrupt (not used with PCAN USB devices) 399 | * 400 | * @returns A TPCANStatus error code. 401 | */ 402 | TPCANStatus CAN_Initialize( 403 | TPCANHandle Channel, 404 | TPCANBaudrate Btr0Btr1, 405 | TPCANType HwType _DEF_ARG, 406 | DWORD IOPort _DEF_ARG, 407 | WORD Interrupt _DEF_ARG); 408 | 409 | /** @brief Initializes a FD capable PCAN Channel. 410 | * 411 | * @param[in] Channel The handle of a FD capable PCAN Channel. 412 | * @param[in] BitrateFD The speed for the communication (FD bit rate string). 413 | * 414 | * @remarks See PCAN_BR_* values 415 | *
    416 | *
  • Parameter and values must be separated by '='.
  • 417 | *
  • Couples of Parameter/value must be separated by ','.
  • 418 | *
  • Following Parameter must be filled out: f_clock, nom_brp, nom_sjw, nom_tseg1, nom_tseg2, 419 | * data_brp, data_sjw, data_tseg1, data_tseg2.
  • 420 | *
  • Following Parameters are optional (not used yet): data_ssp_offset, nom_sam.
  • 421 | *
422 | * @remarks Example: 423 | * @verbatim 424 | * f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1 425 | * @endverbatim 426 | * @returns A TPCANStatus error code. 427 | */ 428 | TPCANStatus CAN_InitializeFD( 429 | TPCANHandle Channel, 430 | TPCANBitrateFD BitrateFD); 431 | 432 | /** @brief Uninitializes one or all PCAN Channels initialized by CAN_Initialize 433 | * 434 | * @remarks Giving the TPCANHandle value "PCAN_NONEBUS", uninitializes all initialized channels. 435 | * 436 | * @param[in] Channel The handle of a PCAN Channel. 437 | * 438 | * @returns A TPCANStatus error code. 439 | */ 440 | TPCANStatus CAN_Uninitialize( 441 | TPCANHandle Channel); 442 | 443 | /** @brief Resets the receive and transmit queues of the PCAN Channel. 444 | * 445 | * @remarks A reset of the CAN controller is not performed. 446 | * 447 | * @param[in] Channel The handle of a PCAN Channel. 448 | * 449 | * @returns A TPCANStatus error code. 450 | */ 451 | TPCANStatus CAN_Reset( 452 | TPCANHandle Channel); 453 | 454 | /** @brief Gets the current status of a PCAN Channel. 455 | * 456 | * @param[in] Channel The handle of a PCAN Channel. 457 | * 458 | * @returns A TPCANStatus error code. 459 | */ 460 | TPCANStatus CAN_GetStatus( 461 | TPCANHandle Channel); 462 | 463 | /** @brief Reads a CAN message from the receive queue of a PCAN Channel. 464 | * 465 | * @param[in] Channel The handle of a PCAN Channel. 466 | * @param[out] MessageBuffer A TPCANMsg structure buffer to store the CAN message. 467 | * @param[out] TimestampBuffer A TPCANTimestamp structure buffer to get the reception time of the message. 468 | * If this value is not desired, this parameter should be passed as NULL. 469 | * 470 | * @returns A TPCANStatus error code. 471 | */ 472 | TPCANStatus CAN_Read( 473 | TPCANHandle Channel, 474 | TPCANMsg* MessageBuffer, 475 | TPCANTimestamp* TimestampBuffer); 476 | 477 | /** @brief Reads a CAN message from the receive queue of a FD capable PCAN Channel. 478 | * 479 | * @param[in] Channel The handle of a FD capable PCAN Channel. 480 | * @param[out] MessageBuffer A TPCANMsgFD structure buffer to store the CAN message. 481 | * @param[out] TimestampBuffer A TPCANTimestampFD buffer to get the reception time of the message. 482 | * If this value is not desired, this parameter should be passed as NULL. 483 | * 484 | * @returns A TPCANStatus error code. 485 | */ 486 | TPCANStatus CAN_ReadFD( 487 | TPCANHandle Channel, 488 | TPCANMsgFD* MessageBuffer, 489 | TPCANTimestampFD* TimestampBuffer); 490 | 491 | /** @brief Transmits a CAN message. 492 | * 493 | * @param[in] Channel The handle of a PCAN Channel. 494 | * @param[in] MessageBuffer A TPCANMsg buffer with the message to be sent. 495 | * 496 | * @returns A TPCANStatus error code. 497 | */ 498 | TPCANStatus CAN_Write( 499 | TPCANHandle Channel, 500 | TPCANMsg* MessageBuffer); 501 | 502 | /** @brief Transmits a CAN message over a FD capable PCAN Channel. 503 | * 504 | * @param[in] Channel The handle of a FD capable PCAN Channel. 505 | * @param[in] MessageBuffer A TPCANMsgFD buffer with the message to be sent. 506 | * 507 | * @returns A TPCANStatus error code. 508 | */ 509 | TPCANStatus CAN_WriteFD( 510 | TPCANHandle Channel, 511 | TPCANMsgFD* MessageBuffer); 512 | 513 | /** @brief Configures the reception filter. 514 | * 515 | * @remarks The message filter will be expanded with every call to this function. 516 | * If it is desired to reset the filter, please use the CAN_SetValue function. 517 | * 518 | * @param[in] Channel The handle of a PCAN Channel. 519 | * @param[in] FromID The lowest CAN ID to be received. 520 | * @param[in] ToID The highest CAN ID to be received. 521 | * @param[in] Mode Message type, Standard (11-bit identifier) or Extended (29-bit identifier). 522 | * 523 | * @returns A TPCANStatus error code. 524 | */ 525 | TPCANStatus CAN_FilterMessages( 526 | TPCANHandle Channel, 527 | DWORD FromID, 528 | DWORD ToID, 529 | TPCANMode Mode); 530 | 531 | /** @brief Retrieves a PCAN Channel value. 532 | * 533 | * @remarks Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used. 534 | * If a parameter is not available, a PCAN_ERROR_ILLPARAMTYPE error will be returned. 535 | * 536 | * @param[in] Channel The handle of a PCAN Channel. 537 | * @param[in] Parameter The TPCANParameter parameter to get. 538 | * @param[out] Buffer Buffer for the parameter value. 539 | * @param[in] BufferLength Size in bytes of the buffer. 540 | * 541 | * @returns A TPCANStatus error code. 542 | */ 543 | TPCANStatus CAN_GetValue( 544 | TPCANHandle Channel, 545 | TPCANParameter Parameter, 546 | void* Buffer, 547 | DWORD BufferLength); 548 | 549 | 550 | /** @brief Configures or sets a PCAN Channel value. 551 | * 552 | * @remarks Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used. 553 | * If a parameter is not available, a PCAN_ERROR_ILLPARAMTYPE error will be returned. 554 | * 555 | * @param[in] Channel The handle of a PCAN Channel. 556 | * @param[in] Parameter The TPCANParameter parameter to set. 557 | * @param[in] Buffer Buffer with the value to be set. 558 | * @param[in] BufferLength Size in bytes of the buffer. 559 | * 560 | * @returns A TPCANStatus error code. 561 | */ 562 | TPCANStatus CAN_SetValue( 563 | TPCANHandle Channel, 564 | TPCANParameter Parameter, 565 | void* Buffer, 566 | DWORD BufferLength); 567 | 568 | /** @brief Returns a descriptive text of a given TPCANStatus error code, in any desired language. 569 | * 570 | * @remarks The current languages available for translation are: 571 | * Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), Italian (0x10) and French (0x0C). 572 | * 573 | * @param[in] Error A TPCANStatus error code. 574 | * @param[in] Language Indicates a 'Primary language ID'. 575 | * @param[out] Buffer Buffer for a null terminated char array. 576 | * 577 | * @returns A TPCANStatus error code. 578 | */ 579 | TPCANStatus CAN_GetErrorText( 580 | TPCANStatus Error, 581 | WORD Language, 582 | LPSTR Buffer); 583 | 584 | /** @brief Finds a PCAN-Basic channel that matches with the given parameters 585 | * 586 | * @param[in] Parameters A comma separated string contained pairs of parameter-name/value 587 | * to be matched within a PCAN-Basic channel 588 | * @param[out] FoundChannel Buffer for returning the PCAN-Basic channel, when found 589 | * 590 | * @returns A TPCANStatus error code. 591 | */ 592 | TPCANStatus CAN_LookUpChannel( 593 | LPSTR Parameters, 594 | TPCANHandle* FoundChannel); 595 | 596 | #ifdef __cplusplus 597 | } 598 | #endif 599 | #endif /* PCAN_API_H_INCLUDED */ 600 | 601 | /* ---------------------------------------------------------------------- 602 | * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany 603 | * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 604 | * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ 605 | */ 606 | -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/README: -------------------------------------------------------------------------------- 1 | macOS Library for PCAN-USB Interfaces 2 | 3 | Copyright (c) 2013-2024 by UV Software, Berlin 4 | 5 | 6 | libPCBUSB 7 | ~~~~~~~~~ 8 | 9 | The PCBUSB library realizes a 'PCAN-USB Driver for macOS' using Apple´s IOUSBKit. 10 | It supports up to 8 PCAN-USB or PCAN-USB FD devices from PEAK-System Technik. 11 | See the header-file PCBUSB.h for details. 12 | 13 | PCAN is a registered trademark of PEAK-System Technik GmbH, Darmstadt, Germany. 14 | Mac and macOS are trademarks of Apple Inc., registered in the U.S. and other countries. 15 | 16 | This software is freeware without any warranty or support! 17 | 18 | Change-Log: 19 | - Version 0.13 of 07/27/2024: 20 | Synchronized PCBUSB header with PCANBasic header from PEAK's version 4.9.0 21 | Realized acceptance filtering by setting parameter: 22 | - PCAN_ACCEPTANCE_FILTER_11BIT (default = 0x00000000000007FF) 23 | - PCAN_ACCEPTANCE_FILTER_29BIT (default = 0x000000001FFFFFFF) 24 | - PCAN_MESSAGE_FILTER (default = PCAN_FILTER_OPEN) 25 | - PCAN_RECEIVE_STATUS (default = PCAN_PARAMETER_ON) 26 | Realized suppression of status frames by setting parameter: 27 | - PCAN_ALLOW_STATUS_FRAMES (default = PCAN_PARAMETER_ON) 28 | Realized suppression of remote frames by setting parameter: 29 | - PCAN_ALLOW_RTR_FRAMES (default = PCAN_PARAMETER_ON) 30 | - Version 0.12.2 of 11/01/2023: 31 | Synchronized PCBUSB header with PCANBasic header from PEAK's version 4.8.0 32 | Fixed a bug with pipe numbers for PCAN-USB FD devices (hardware version 6.0) 33 | Added missing linker option '-rpath /usr/local/lib' to the C++ examples 34 | Updated the README file (unsupported parameter PCAN_HARD_RESET_STATUS) 35 | - Version 0.12.1 of 09/23/2023: 36 | Fixed a bug with endianess of 32-bit device id. (issue #384: PCAN-USB [Pro] FD) 37 | Reworked return values of CAN_Read(), CAN_ReadFD(), CAN_Write(), CAN_WriteFD() 38 | Reset USB pipe #4 after write timed out (CAN Write stalled; macOS 11 and higher) 39 | - Version 0.12 of 01/31/2023: 40 | Realized setting of device id. for PCAN-USB FD devices 41 | Reworked status frame handling: 42 | - fixed some bugs in the driver layer (all device types) 43 | - suppressed initial CAN FD status frame in CAN 2.0 mode 44 | - corrected mapping of bus error states to PCAN status 45 | - fixed a bug with CAN id. of status messages 46 | - CAN_Read(), CAN_ReadFD(), CAN_Write(), CAN_WriteFD(): return bus error states 47 | SetValue(): Set default value if argument 'BufferLength' is equal to 0: 48 | - PCAN_LISTEN_ONLY (default = OFF) 49 | - PCAN_DEVICE_ID (default = 0) 50 | - PCAN_TRACE_LOCATION (default = cwd) 51 | - PCAN_TRACE_STATUS (default = OFF) 52 | - PCAN_TRACE_SIZE (default 0 = 100k frames!) 53 | - PCAN_TRACE_CONFIGURE (default = SINGLE_FILE) 54 | GetValue(): Implemented missing parameters: 55 | - PCAN_ALLOW_RTR_FRAMES (read-only!) 56 | - PCAN_ALLOW_STATUS_FRAMES (read-only!) 57 | - PCAN_ALLOW_ERROR_FRAMES (read-only!) 58 | - PCAN_CONTROLLER_NUMBER (read-only) 59 | - PCAN_DEVICE_PART_NUMBER (read-only) 60 | Made GetValue(PCAN_RECEIVE_EVENT) more robust if argument is greater than size of int 61 | Reading of additional bytes from firmware info packet to distinguish product variants 62 | Fixed a bug with stuck in CAN_Write when errors on bus 63 | (note: the solution only works on macOS 11.0 and newer) 64 | Fixed a bug with status frames not triggering the pipe for blocking read 65 | Fixed a bug with getting the firmware version from USB device name 66 | (note: since firmware 3.x the version is not encoded in the device name anymore) 67 | Fixed a bug with string length for bit-rate strings 68 | Fixed a bug with GetValue(BITRATE_INFO_FD) w/o BRSE 69 | Fixed a bug with size of parameter 'PCAN_TRACE_SIZE' 70 | Fixed some findings from static code analysis (Xcode and cppcheck) 71 | - Version 0.11.2 of 07/30/2022: 72 | Fixed the CAN FD URB issue ('Messages lost on high CAN FD bit-rates') 73 | Added installation instruction (after all these years) 74 | - Version 0.11.1 of 04/30/2022: 75 | Fixed the Monterey issue ('Driver not loaded') 76 | Fixed some findings from static code analysis 77 | Added `@rpath` to all build environments 78 | Improved the installation script 79 | Updated the README file 80 | - Version 0.11 of 01/31/2022: 81 | Synchronized PCBUSB header with PCANBasic header for v4.6.0. 82 | Fixed a bug with PCAN_CHANNEL_CONDITION when used by another process 83 | Fixed an omission with export declaration for CAN_LookUpChannel 84 | Implemented parameter PCAN_FIRMWARE_VERSION (read-only) 85 | Added error text for PCAN_ERROR_ILLMODE (all languages) 86 | Corrected some French error text (acc. to Peak´s changes) 87 | Return PCAN_ERROR_HWINUSE when interface is used by another process: 88 | - CAN_GetValue: PCAN_LISTEN_ONLY, PCAN_RECEIVE_STATUS, PCAN_LISTEN_ONLY 89 | Return PCAN_ERROR_ILLCLIENT if an invalid channel handle given: 90 | - CAN_GetValue: PCAN_RECEIVE_EVENT, PCAN_CHANNEL_CONDITION, PCAN_TRACE_LOCATION, 91 | PCAN_TRACE_STATUS, PCAN_TRACE_SIZE, PCAN_TRACE_CONFIGURE, 92 | PCAN_BITRATE_INFO, PCAN_BITRATE_INFO_FD, PCAN_BUSSPEED_NOMINAL, 93 | PCAN_BUSSPEED_DATA, PCAN_FIRMWARE_VERSION 94 | - CAN_SetValue: PCAN_DEVICE_ID, PCAN_TRACE_LOCATION, PCAN_TRACE_STATUS, 95 | PCAN_TRACE_SIZE, PCAN_TRACE_CONFIGURE 96 | - CAN_Reset, CAN_GetStatus , CAN_Read, CAN_ReadFD, CAN_Write, CAN_WriteFD 97 | * Peak-System harmonized its return codes in PCANBasic DLL version 4.6.0. 98 | Now the return codes matches my expectation. 99 | Added `@rpath` to the build environment (it got lost for some releases) 100 | Code signed the Universal macOS Binary (Apple Development certificate) 101 | - Version 0.10.1 of 12/05/2021: 102 | Built library as Universal macOS Binary (macOS_Library_for_PCANUSB_v0.10.1.tar.gz) 103 | Built library for x86_64 architecture (OS_X_Library_for_PCANUSB_v0.10.1.tar.gz) 104 | Parameter PCAN_CHANNEL_VERSION displays machine architecture from utsname() 105 | Fixed a bug with parameter PCAN_EXT_HARDWARE_VERSION for PCAN-USB Pro FD device 106 | - Version 0.10 of 12/22/2020: 107 | Support of PCAN-USB Pro FD devices, but only the first channel (CAN1) 108 | Set linker options -install_name, -compatibility_version, and -current_version 109 | Synchronized the API with Peak´s PCANBasic version 4.5.0.440 110 | Updated the Python example: reworked the output format 111 | - Version 0.9 of 06/25/2020: 112 | Data types from as replacement for Peak´s usage of Windows BYTE, 113 | WORD, DWORD and UINT64 (field CAN ID is now 32-bit wide) 114 | Synchronized the API with Peak´s PCANBasic version 4.4.0.288 115 | Parameter PCAN_DEVICE_ID can be read in pre-initialization state 116 | Fixed some bugs with status bit: PCAN_ERROR_QXMTFULL, PCAN_ERROR_XMTFULL, 117 | PCAN_ERROR_QOVERRUN, PCAN_ERROR_BUSLIGHT 118 | Added a delay of 1 usec in CAN_Write to run on macOS 10.15 (Catalina) 119 | - Version 0.8.1 of 09/27/2019: 120 | Adapted trace-file headers to Peak's changes in version 4.3.4.246 121 | - Version 0.8 of 09/20/2017: 122 | Support of PCAN-USB FD devices in CAN 2.0 mode (CAN classic) and CAN FD mode! 123 | Adapted the API according to Peak's changes in version 4.2.0.134 and harmonized 124 | return codes with it 125 | Fixed issue #208 'CAN_Write stuck when errors on the bus are present' 126 | Conducted an intermediate solution for issue #246 (writing into a trace file) 127 | Added run-path-relative install name to the library (using the @rpath macro) 128 | - Version 0.7 of 11/30/2016: 129 | Adapted the API according to Peak's changes in version 4.1.0.96 and harmonized 130 | return codes with it 131 | Implemented parameter PCAN_CHANNEL_FEATURE and PCAN_BITRATE_INFO 132 | - Version 0.6 of 02/20/2015: 133 | Parameter PCAN_RECEIVE_EVENT returns a file descriptor to realize 'blocking 134 | read' by select() as on the Linux implementation of the PCAN-Basic API 135 | Added two C++ examples and one Python example using the PCBUSB library 136 | - Version 0.5 of 11/23/2014: 137 | Feature 'Reading/Writing of parameter PCAN_DEVICE_NUMBER' implemented 138 | Fixed issue #104 'Hot plugging was not detected by the library/driver' 139 | Fixed issue #117 'Permission for libPCBUSB.x.y.lib wrong' (chmod 755) 140 | Return codes of API functions harmonized with PCANBasic.dll (1.3.3.61) 141 | - Version 0.4 of 02/23/2014: 142 | Time-stamps are now taken from CAN controller instead of taking them from the 143 | system clock 144 | Getting and setting of PCAN_* parameters reworked (to be almost compatible to 145 | the PCANBasic DLL, version 1.3) 146 | Resetting of RCV and XMT queue on the CAN controller realized 147 | - Version 0.3 of 11/02/2013: 148 | Fixed issue #11 'All channel initialized by the application will be closed 149 | even if they are in use' 150 | CAN_Unitialize: closing all channel initialized by the application at once 151 | implemented 152 | CAN_Read: receive queue overrun handling reworked 153 | CAN_*: wrong function return codes corrected 154 | CAN_GetErrorText: language support for English, German, French, Italian and 155 | Spanish added 156 | - Version 0.2 of 09/08/2013: 157 | Minor changes 158 | - Version 0.1 of 06/30/2013: 159 | Initial revision 160 | 161 | Limitations: 162 | - CAN_Initialize(): 163 | Only the following devices are supported: 164 | - PCAN-USB (item no. IPEH-002021 and IPEH-002022) 165 | - PCAN-USB FD (item no. IPEH-004022) 166 | - PCAN-USB Pro FD (item no. IPEH-004061), but only the first channel (CAN1) 167 | - CAN_Write(): 168 | Transmission of the given message on the CAN bus is not acknowledged by 169 | the USB interface. 170 | A transmission queue like in the Windows driver is not realized. 171 | - CAN_FilterMessages(): 172 | Filter ranges are not supported. Acceptance filtering is supported by setting 173 | parameter (PCAN_ACCEPTANCE_FILTER_11BIT or PCAN_ACCEPTANCE_FILTER_29BIT). 174 | - CAN_GetValue(): 175 | Still unsupported parameter are: PCAN_5VOLTS_POWER, 176 | PCAN_BUSOFF_AUTORESET, PCAN_LOG_LOCATION, PCAN_LOG_STATUS, PCAN_LOG_CONFIGURE, 177 | PCAN_LOG_TEXT, PCAN_CHANNEL_IDENTIFYING, PCAN_BITRATE_ADAPTING, PCAN_IP_ADDRESS, 178 | PCAN_LAN_SERVICE_STATUS, PCAN_INTERFRAME_DELAY, PCAN_ATTACHED_CHANNELS_COUNT, 179 | PCAN_ATTACHED_CHANNELS, PCAN_HARD_RESET_STATUS, PCAN_LAN_CHANNEL_DIRECTION. 180 | - CAN_SetValue(): 181 | Still unsupported parameter are: PCAN_5VOLTS_POWER, PCAN_RECEIVE_EVENT, 182 | PCAN_BUSOFF_AUTORESET, PCAN_LOG_LOCATION, PCAN_LOG_STATUS, PCAN_LOG_CONFIGURE, 183 | PCAN_LOG_TEXT, PCAN_CHANNEL_IDENTIFYING, PCAN_BITRATE_ADAPTING, 184 | PCAN_ALLOW_STATUS_FRAMES, PCAN_ALLOW_RTR_FRAMES, PCAN_ALLOW_ERROR_FRAMES, 185 | PCAN_INTERFRAME_DELAY, PCAN_ALLOW_ECHO_FRAMES, PCAN_HARD_RESET_STATUS. 186 | - CAN_LookUpChannel(): 187 | Channel searching is currently not supported. 188 | - Writing into a trace file: 189 | Only 100'000 frames can be recorded into one trace file. 190 | An existing trace file with the same file name will be overwritten. 191 | 192 | Known bugs and caveats 193 | - The LED of the PCAN-USB FD device is not turned on (green) when the device 194 | is plugged into the USB bus. This is due to the fact that there is no 'real' 195 | driver for PCAN-USB devices under macOS. So the LED of the PCAN-USB FD device 196 | cannot signal the presence of a driver. When operating the LED signals the 197 | correct operation state of the PCAN-USB FD device (blinking green, or red 198 | on error). 199 | - The same LED issue is for the PCAN-USB Pro FD device. The LED for the first 200 | channel signals its operation state only when operated by an application. 201 | - The second channel of the PCAN-USB Pro FD device is not supported by the 202 | driver. It is not listed in the device list; its LED is turned off. 203 | - When a successfully initialized PCAN-USB device is physically removed from 204 | USB any subsequent call of API functions (e.g. CAN_Read) will not succeed 205 | even when the device is plugged in again. An error code will be returned in 206 | this case. 207 | 208 | Contact 209 | ~~~~~~~ 210 | 211 | E-Mail: mailto:info@mac-can.com 212 | Internet: http://www.mac-can.com 213 | -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ProjName=PCBUSB 4 | ProjVersion=0.13 5 | BaseDir=$(dirname $0) 6 | InstallDir=/usr/local/lib 7 | IncludeDir=/usr/local/include 8 | 9 | if [ -f "$BaseDir/lib$ProjName.$ProjVersion.dylib" ] 10 | then 11 | if [ ! -d "$InstallDir" ] 12 | then 13 | mkdir "$InstallDir" 14 | fi 15 | if [ -f "$InstallDir/lib$ProjName.dylib" ] 16 | then 17 | rm -f "$InstallDir/lib$ProjName.dylib" 18 | fi 19 | if [ -f "$InstallDir/lib$ProjName.$ProjVersion.dylib" ] 20 | then 21 | rm -f "$InstallDir/lib$ProjName.$ProjVersion.dylib" 22 | fi 23 | cp "$BaseDir/lib$ProjName.$ProjVersion.dylib" "$InstallDir/lib$ProjName.$ProjVersion.dylib" 24 | ln -s "$InstallDir/lib$ProjName.$ProjVersion.dylib" "$InstallDir/lib$ProjName.dylib" 25 | chmod 755 "$InstallDir/lib$ProjName.$ProjVersion.dylib" 26 | chmod 755 "$InstallDir/lib$ProjName.dylib" 27 | else 28 | echo "error dylib" 29 | fi 30 | 31 | if [ -f "$BaseDir/$ProjName.h" ] 32 | then 33 | if [ -d "$IncludeDir" ] 34 | then 35 | cp "$BaseDir/$ProjName.h" "$IncludeDir/$ProjName.h" 36 | else 37 | mkdir "$IncludeDir"; cp "$BaseDir/$ProjName.h" "$IncludeDir/$ProjName.h" 38 | fi 39 | else 40 | echo "error header" 41 | fi 42 | -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/install.txt: -------------------------------------------------------------------------------- 1 | macOS Library for PCAN-USB Interfaces 2 | 3 | Copyright (c) 2013-2024 by UV Software, Berlin 4 | 5 | 6 | How to install the PCBUSB-Library on Mac 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | 9 | 1. Download the Library 10 | 11 | First download the library either from the MacCAN homepage at 12 | or from the GitHub repo at . 13 | 14 | Note: Archives with name prefix 'macOS_' contain the artifacts that are compiled as 15 | Universal Binary for Intel x86_64 and Apple silicon. They require macOS 11.x 16 | (Big Sur) or higher. 17 | Archives with name prefix 'OS_X_' contain the artifacts for OS X 10.x (Intel 18 | x86_64 only). 19 | 20 | 2. Install the Library 21 | 22 | Now open a terminal to extract the artifacts and to install the library. 23 | 24 | Note: In the following example I've downloaded version 0.13 from the MacCAN homepage. 25 | 'makemake' is my username, 'uv-pc014mac' the name of my Mac. 26 | 27 | 2.1 Extract the Artifacts 28 | 29 | If you have downloaded the library as a tarball, type this: 30 | 31 | makemake@uv-pc014mac ~ % tar -xvf ~/Downloads/macOS_Library_for_PCANUSB_v0.13.tar 32 | 33 | If you have downloaded a compressed archive, then run this: 34 | 35 | makemake@uv-pc014mac ~ % tar -xzvf ~/Downloads/macOS_Library_for_PCANUSB_v0.13.tar.gz 36 | 37 | 2.2 Install the dylib 38 | 39 | To install the dylib you need superuser privileges. Type this: 40 | 41 | makemake@uv-pc014mac ~ % cd PCBUSB 42 | makemake@uv-pc014mac PCBUSB % sudo /Users//PCBUSB/install.sh 43 | Password: 44 | 45 | 3. Using the library 46 | 47 | That's up to you. 48 | 49 | 50 | Contact 51 | ~~~~~~~ 52 | 53 | E-Mail: mailto:info@mac-can.com 54 | Internet: http://www.mac-can.com 55 | -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.1.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.10.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.10.1.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.10.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.10.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.11.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.11.1.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.11.2.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.11.2.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.11.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.11.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.12.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.12.1.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.12.2.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.12.2.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.12.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.12.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.13.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.13.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.2.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.2.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.3.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.3.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.4.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.4.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.5.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.5.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.6.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.6.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.7.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.7.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.8.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.8.1.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.8.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.8.dylib -------------------------------------------------------------------------------- /Binaries/Intel_x86_64/libPCBUSB.0.9.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Intel_x86_64/libPCBUSB.0.9.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013-2023 by UV Software, Berlin, Germany. 2 | 3 | All rights reserved. / Alle Rechte vorbehalten. 4 | 5 | 6 | Contact: / Anschrift: 7 | 8 | Uwe Vogt 9 | UV Software 10 | 11 | Chausseestrasse 33 A 12 | 10115 Berlin, Germany 13 | 14 | E-Mail: mailto:info@mac-can.com 15 | Internet: http://www.mac-can.com -------------------------------------------------------------------------------- /Binaries/Universal_64/LICENSE: -------------------------------------------------------------------------------- 1 | macOS Library for PCAN-USB Interfaces - Copyright (C) 2013-2024 by UV Software 2 | All rights reserved. 3 | 4 | 5 | END-USER LICENSE AGREEMENT FOR THIS SOFTWARE 6 | Important - read carefully! 7 | 8 | This End-User License Agreement ("EULA") is a legal agreement between 9 | you ("Licensee") and UV Software ("Licensor") for the software product 10 | identified above, which includes computer software and may include 11 | associated media, printed materials, and "online" or electronic 12 | documentation ("SOFTWARE PRODUCT"). By installing, copying, or otherwise 13 | using the SOFTWARE PRODUCT, you agree to be bound by the terms of this 14 | EULA. If you do not agree to the terms of this EULA, do not install or 15 | use the SOFTWARE PRODUCT. 16 | 17 | 18 | SOFTWARE PRODUCT LICENSE 19 | 20 | The SOFTWARE PRODUCT is licensed, not sold. 21 | 22 | The definition of SOFTWARE PRODUCT includes any files generated by the 23 | SOFTWARE PRODUCT. 24 | 25 | 26 | 1. GRANT OF LICENSE 27 | 28 | This EULA grants you the following rights: 29 | 30 | Installation and Use: You may install and use an unlimited number of 31 | copies of the SOFTWARE PRODUCT. 32 | 33 | Reproduction and Distribution: You may reproduce and distribute an 34 | unlimited number of copies of the SOFTWARE PRODUCT; provided that each 35 | copy shall be a true and complete copy, including all copyright and 36 | trademark notices, and shall be accompanied by a copy of this EULA. 37 | Copies of the SOFTWARE PRODUCT may be distributed as a standalone 38 | product or included with your own product. 39 | 40 | 41 | 2. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS 42 | 43 | Limitations on Reverse Engineering, Decompilation, and Disassembly: You 44 | may not reverse engineer, decompile or disassemble the SOFTWARE PRODUCT 45 | in any circumstances. 46 | 47 | Support Services: UV Software will not provide you with support services 48 | ("SUPPORT SERVICES") related to the SOFTWARE PRODUCT. 49 | 50 | Termination: Without prejudice to any other rights of UV Software, your 51 | rights under this EULA will terminate automatically without notice from 52 | UV Software if you fail to comply with any term(s) of this EULA. In such 53 | event you must destroy all copies of the SOFTWARE PRODUCT and any 54 | related materials. 55 | 56 | 57 | 3. LIMITED WARRANTY AND DISCLAIMER OF WARRANTY 58 | 59 | NO WARRANTIES: You expressly acknowledge and agree that use of the 60 | SOFTWARE PRODUCT is at your sole risk. The SOFTWARE PRODUCT is provided 61 | "AS IS" and without warranty of any kind. UV Software hereby EXPRESSLY 62 | DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED, 63 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF 64 | MERCHANTABILITY, NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. 65 | You are solely responsible for determining the appropriateness of using 66 | this SOFTWARE PRODUCT and assume all risks associated with the use of 67 | this SOFTWARE PRODUCT, including but not limited to the risks of program 68 | errors, damage to or loss of data, programs or equipment, and 69 | unavailability or interruption of operations. 70 | 71 | NO LIABILITY FOR DAMAGES: UNDER NO CIRCUMSTANCES, INCLUDING NEGLIGENCE, 72 | SHALL UV Software BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 73 | CONSEQUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS 74 | OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, 75 | OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF OR RELATING TO THIS LICENSE, 76 | EVEN IF UV Software HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 77 | In no event shall UV Software's total liability to you for all damages 78 | exceed the amount paid for this license to the SOFTWARE PRODUCT. The 79 | entire risk arising out of use or performance of the SOFTWARE PRODUCT 80 | remains with you. 81 | 82 | 83 | 4. COPYRIGHT 84 | 85 | All title and copyrights in and to the SOFTWARE PRODUCT (including but 86 | not limited to any images, photographs, animations, video, audio, music, 87 | text, and "applets" incorporated into the SOFTWARE PRODUCT), the 88 | accompanying printed materials, and any copies of the SOFTWARE PRODUCT 89 | are owned by UV Software. The SOFTWARE PRODUCT is protected by copyright 90 | laws and international treaty provisions. Therefore, you must treat the 91 | SOFTWARE PRODUCT like any other copyrighted material. 92 | 93 | 94 | 5. TRADEMARKS 95 | 96 | All product and company names mentioned in the SOFTWARE PRODUCT may be 97 | trademarks and/or service marks of their respective owners. 98 | 99 | 100 | 6. GOVERNING LAW 101 | 102 | This agreement shall be governed by the laws of Germany. 103 | 104 | 105 | 7. MISCELLANEOUS 106 | 107 | If for any reason a court of competent jurisdiction finds any provision, 108 | or portion of this EULA, to be unenforceable, the remainder of this EULA 109 | shall continue in full force and effect. This EULA constitutes the entire 110 | agreement between the parties with respect to the use of the SOFTWARE 111 | PRODUCT and supersedes all prior or contemporaneous understandings 112 | regarding such subject matter. No amendment to or modification of this 113 | EULA will be binding unless in writing and signed by UV Software. 114 | 115 | 116 | 117 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 118 | Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany 119 | Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 120 | E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ -------------------------------------------------------------------------------- /Binaries/Universal_64/PCBUSB.c: -------------------------------------------------------------------------------- 1 | // 2 | // PCBUSB.c 3 | // MacCAN Monitor 4 | // Wrapper for libPCBUSB 5 | // 6 | // Created by Uwe Vogt on 18.08.13. 7 | // Copyright (c) 2013-2024 UV Software. All rights reserved. 8 | // 9 | // This software is freeware without any warranty or support! 10 | // 11 | // NO WARRANTIES: You expressly acknowledge and agree that use of the 12 | // SOFTWARE PRODUCT is at your sole risk. The SOFTWARE PRODUCT is provided 13 | // "AS IS" and without warranty of any kind. UV Software hereby EXPRESSLY 14 | // DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED, 15 | // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF 16 | // MERCHANTABILITY, NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. 17 | // You are solely responsible for determining the appropriateness of using 18 | // this SOFTWARE PRODUCT and assume all risks associated with the use of 19 | // this SOFTWARE PRODUCT, including but not limited to the risks of program 20 | // errors, damage to or loss of data, programs or equipment, and 21 | // unavailability or interruption of operations. 22 | // 23 | // NO LIABILITY FOR DAMAGES: UNDER NO CIRCUMSTANCES, INCLUDING NEGLIGENCE, 24 | // SHALL UV Software BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 25 | // CONSEQUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS 26 | // OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, 27 | // OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF OR RELATING TO THIS LICENSE, 28 | // EVEN IF UV Software HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 29 | // In no event shall UV Software's total liability to you for all damages 30 | // exceed the amount paid for this license to the SOFTWARE PRODUCT. The 31 | // entire risk arising out of use or performance of the SOFTWARE PRODUCT 32 | // remains with you. 33 | // 34 | #if defined(__APPLE__) 35 | #include "PCBUSB.h" 36 | #define CAN_LIBRARY "libPCBUSB.dylib" 37 | #else 38 | #include "PCANBasic.h" 39 | #define CAN_LIBRARY "libpcanbasic.so" 40 | #endif 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | typedef TPCANStatus (*CAN_Initialize_t)(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt); 47 | typedef TPCANStatus (*CAN_Uninitialize_t)(TPCANHandle Channel); 48 | typedef TPCANStatus (*CAN_Reset_t)(TPCANHandle Channel); 49 | typedef TPCANStatus (*CAN_GetStatus_t)(TPCANHandle Channel); 50 | typedef TPCANStatus (*CAN_Read_t)(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer); 51 | typedef TPCANStatus (*CAN_Write_t)(TPCANHandle Channel, TPCANMsg* MessageBuffer); 52 | typedef TPCANStatus (*CAN_FilterMessages_t)(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode); 53 | typedef TPCANStatus (*CAN_GetValue_t)(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); 54 | typedef TPCANStatus (*CAN_SetValue_t)(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); 55 | typedef TPCANStatus (*CAN_GetErrorText_t)(TPCANStatus Error, WORD Language, char* Buffer); 56 | typedef TPCANStatus (*CAN_InitializeFD_t)(TPCANHandle Channel, TPCANBitrateFD BitrateFD); 57 | typedef TPCANStatus (*CAN_ReadFD_t)(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer); 58 | typedef TPCANStatus (*CAN_WriteFD_t)(TPCANHandle Channel, TPCANMsgFD* MessageBuffer); 59 | typedef TPCANStatus (*CAN_LookUpChannel_t)(LPSTR Parameters, TPCANHandle* FoundChannel); 60 | 61 | static CAN_Initialize_t fpCAN_Initialize = NULL; 62 | static CAN_Uninitialize_t fpCAN_Uninitialize = NULL; 63 | static CAN_Reset_t fpCAN_Reset = NULL; 64 | static CAN_GetStatus_t fpCAN_GetStatus = NULL; 65 | static CAN_Read_t fpCAN_Read = NULL; 66 | static CAN_Write_t fpCAN_Write = NULL; 67 | static CAN_FilterMessages_t fpCAN_FilterMessages = NULL; 68 | static CAN_GetValue_t fpCAN_GetValue = NULL; 69 | static CAN_SetValue_t fpCAN_SetValue = NULL; 70 | static CAN_GetErrorText_t fpCAN_GetErrorText = NULL; 71 | static CAN_InitializeFD_t fpCAN_InitializeFD = NULL; 72 | static CAN_ReadFD_t fpCAN_ReadFD = NULL; 73 | static CAN_WriteFD_t fpCAN_WriteFD = NULL; 74 | static CAN_LookUpChannel_t fpCAN_LookUpChannel = NULL; 75 | 76 | static void *hLibrary = NULL; 77 | 78 | static int LoadLibrary(void) { 79 | if (!hLibrary) { 80 | errno = 0; 81 | hLibrary = dlopen(CAN_LIBRARY, RTLD_LAZY); 82 | if (!hLibrary) 83 | return -1; 84 | if ((fpCAN_Initialize = (CAN_Initialize_t)dlsym(hLibrary, "CAN_Initialize")) == NULL) 85 | goto err; 86 | if ((fpCAN_Uninitialize = (CAN_Uninitialize_t)dlsym(hLibrary, "CAN_Uninitialize")) == NULL) 87 | goto err; 88 | if ((fpCAN_Reset = (CAN_Reset_t)dlsym(hLibrary, "CAN_Reset")) == NULL) 89 | goto err; 90 | if ((fpCAN_GetStatus = (CAN_GetStatus_t)dlsym(hLibrary, "CAN_GetStatus")) == NULL) 91 | goto err; 92 | if ((fpCAN_Read = (CAN_Read_t)dlsym(hLibrary, "CAN_Read")) == NULL) 93 | goto err; 94 | if ((fpCAN_Write = (CAN_Write_t)dlsym(hLibrary, "CAN_Write")) == NULL) 95 | goto err; 96 | if ((fpCAN_FilterMessages = (CAN_FilterMessages_t)dlsym(hLibrary, "CAN_FilterMessages")) == NULL) 97 | goto err; 98 | if ((fpCAN_GetValue = (CAN_GetValue_t)dlsym(hLibrary, "CAN_GetValue")) == NULL) 99 | goto err; 100 | if ((fpCAN_SetValue = (CAN_SetValue_t)dlsym(hLibrary, "CAN_SetValue")) == NULL) 101 | goto err; 102 | if ((fpCAN_GetErrorText = (CAN_GetErrorText_t)dlsym(hLibrary, "CAN_GetErrorText")) == NULL) 103 | goto err; 104 | if ((fpCAN_InitializeFD = (CAN_InitializeFD_t)dlsym(hLibrary, "CAN_InitializeFD")) == NULL) 105 | goto err; 106 | if ((fpCAN_ReadFD = (CAN_ReadFD_t)dlsym(hLibrary, "CAN_ReadFD")) == NULL) 107 | goto err; 108 | if ((fpCAN_WriteFD = (CAN_WriteFD_t)dlsym(hLibrary, "CAN_WriteFD")) == NULL) 109 | goto err; 110 | if ((fpCAN_LookUpChannel = (CAN_LookUpChannel_t)dlsym(hLibrary, "CAN_LookUpChannel")) == NULL) 111 | fpCAN_LookUpChannel = NULL; // New function w/o implementation: accept the NULL pointer! 112 | } 113 | return 0; 114 | err: 115 | fpCAN_Initialize = NULL; 116 | fpCAN_Uninitialize = NULL; 117 | fpCAN_Reset = NULL; 118 | fpCAN_GetStatus = NULL; 119 | fpCAN_Read = NULL; 120 | fpCAN_Write = NULL; 121 | fpCAN_FilterMessages = NULL; 122 | fpCAN_GetValue = NULL; 123 | fpCAN_SetValue = NULL; 124 | fpCAN_GetErrorText = NULL; 125 | #ifndef CAN_2_0_ONLY 126 | fpCAN_InitializeFD = NULL; 127 | fpCAN_ReadFD = NULL; 128 | fpCAN_WriteFD = NULL; 129 | #endif 130 | fpCAN_LookUpChannel = NULL; 131 | dlclose(hLibrary); 132 | hLibrary = NULL; 133 | return -1; 134 | } 135 | 136 | TPCANStatus CAN_Initialize(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt) { 137 | if (LoadLibrary() != 0) 138 | return PCAN_ERROR_NODRIVER; 139 | if (fpCAN_Initialize) 140 | return fpCAN_Initialize(Channel, Btr0Btr1, HwType, IOPort, Interrupt); 141 | else 142 | return PCAN_ERROR_UNKNOWN; 143 | } 144 | 145 | TPCANStatus CAN_Uninitialize(TPCANHandle Channel) { 146 | //if (LoadLibrary() != 0) 147 | // return PCAN_ERROR_NODRIVER; 148 | if (fpCAN_Uninitialize) 149 | return fpCAN_Uninitialize(Channel); 150 | else 151 | return PCAN_ERROR_UNKNOWN; 152 | } 153 | 154 | TPCANStatus CAN_Reset(TPCANHandle Channel) { 155 | if (LoadLibrary() != 0) 156 | return PCAN_ERROR_NODRIVER; 157 | if (fpCAN_Reset) 158 | return fpCAN_Reset(Channel); 159 | else 160 | return PCAN_ERROR_UNKNOWN; 161 | } 162 | 163 | TPCANStatus CAN_GetStatus(TPCANHandle Channel) { 164 | if (LoadLibrary() != 0) 165 | return PCAN_ERROR_NODRIVER; 166 | if (fpCAN_GetStatus) 167 | return fpCAN_GetStatus(Channel); 168 | else 169 | return PCAN_ERROR_UNKNOWN; 170 | } 171 | 172 | TPCANStatus CAN_Read(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer) { 173 | if (LoadLibrary() != 0) 174 | return PCAN_ERROR_NODRIVER; 175 | if (fpCAN_Read) 176 | return fpCAN_Read(Channel, MessageBuffer, TimestampBuffer); 177 | else 178 | return PCAN_ERROR_UNKNOWN; 179 | } 180 | 181 | TPCANStatus CAN_Write(TPCANHandle Channel, TPCANMsg* MessageBuffer) { 182 | if (LoadLibrary() != 0) 183 | return PCAN_ERROR_NODRIVER; 184 | if (fpCAN_Write) 185 | return fpCAN_Write(Channel, MessageBuffer); 186 | else 187 | return PCAN_ERROR_UNKNOWN; 188 | } 189 | 190 | TPCANStatus CAN_FilterMessages(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode) { 191 | if (LoadLibrary() != 0) 192 | return PCAN_ERROR_NODRIVER; 193 | if (fpCAN_FilterMessages) 194 | return fpCAN_FilterMessages(Channel, FromID, ToID, Mode); 195 | else 196 | return PCAN_ERROR_UNKNOWN; 197 | } 198 | 199 | TPCANStatus CAN_GetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength) { 200 | if (LoadLibrary() != 0) 201 | return PCAN_ERROR_NODRIVER; 202 | if (fpCAN_GetValue) 203 | return fpCAN_GetValue(Channel, Parameter, Buffer, BufferLength); 204 | else 205 | return PCAN_ERROR_UNKNOWN; 206 | } 207 | 208 | TPCANStatus CAN_SetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength) { 209 | if (LoadLibrary() != 0) 210 | return PCAN_ERROR_NODRIVER; 211 | if (fpCAN_SetValue) 212 | return fpCAN_SetValue(Channel, Parameter, Buffer, BufferLength); 213 | else 214 | return PCAN_ERROR_UNKNOWN; 215 | } 216 | 217 | TPCANStatus CAN_GetErrorText(TPCANStatus Error, WORD Language, char* Buffer) { 218 | if (LoadLibrary() != 0) { 219 | if (Buffer) 220 | strcpy(Buffer, "PCBUSB library could not be loaded"); 221 | return PCAN_ERROR_NODRIVER; 222 | } 223 | if (fpCAN_GetErrorText) 224 | return fpCAN_GetErrorText(Error, Language, Buffer); 225 | else 226 | return PCAN_ERROR_UNKNOWN; 227 | } 228 | 229 | TPCANStatus CAN_InitializeFD(TPCANHandle Channel, TPCANBitrateFD BitrateFD) { 230 | if (LoadLibrary() != 0) 231 | return PCAN_ERROR_NODRIVER; 232 | if (fpCAN_InitializeFD) 233 | return fpCAN_InitializeFD(Channel, BitrateFD); 234 | else 235 | return PCAN_ERROR_UNKNOWN; 236 | } 237 | 238 | TPCANStatus CAN_ReadFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer) { 239 | if (LoadLibrary() != 0) 240 | return PCAN_ERROR_NODRIVER; 241 | if (fpCAN_ReadFD) 242 | return fpCAN_ReadFD(Channel, MessageBuffer, TimestampBuffer); 243 | else 244 | return PCAN_ERROR_UNKNOWN; 245 | } 246 | 247 | TPCANStatus CAN_WriteFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer) { 248 | if (LoadLibrary() != 0) 249 | return PCAN_ERROR_NODRIVER; 250 | if (fpCAN_WriteFD) 251 | return fpCAN_WriteFD(Channel, MessageBuffer); 252 | else 253 | return PCAN_ERROR_UNKNOWN; 254 | } 255 | 256 | TPCANStatus CAN_LookUpChannel(LPSTR Parameters, TPCANHandle* FoundChannel) { 257 | if (LoadLibrary() != 0) 258 | return PCAN_ERROR_NODRIVER; 259 | if (fpCAN_LookUpChannel) 260 | return fpCAN_LookUpChannel(Parameters, FoundChannel); 261 | else 262 | return PCAN_ERROR_UNKNOWN; 263 | } 264 | -------------------------------------------------------------------------------- /Binaries/Universal_64/PCBUSB.h: -------------------------------------------------------------------------------- 1 | /* -- $HeadURL: https://svn.uv-software.net/MacCAN/PCANUSB/Library/trunk/drv/pcan_api.h $ -- 2 | * 3 | * project : CAN - Controller Area Network 4 | * 5 | * purpose : PCAN Application Programming Interface 6 | * 7 | * copyright : (C) 2012-2024 by UV Software, Berlin 8 | * 9 | * compiler : Apple clang version 15.0.0 (clang-1500.3.9.4) 10 | * 11 | * export : TPCANStatus CAN_Initialize(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt); 12 | * TPCANStatus CAN_Uninitialize(TPCANHandle Channel); 13 | * TPCANStatus CAN_Reset(TPCANHandle Channel); 14 | * TPCANStatus CAN_GetStatus(TPCANHandle Channel); 15 | * TPCANStatus CAN_Read(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer); 16 | * TPCANStatus CAN_Write(TPCANHandle Channel, TPCANMsg* MessageBuffer); 17 | * TPCANStatus CAN_FilterMessages(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode); 18 | * TPCANStatus CAN_GetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); 19 | * TPCANStatus CAN_SetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); 20 | * TPCANStatus CAN_GetErrorText(TPCANStatus Error, WORD Language, LPSTR Buffer); 21 | * *** CAN FD capable devices *** 22 | * TPCANStatus CAN_InitializeFD(TPCANHandle Channel, TPCANBitrateFD BitrateFD); 23 | * TPCANStatus CAN_ReadFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer); 24 | * TPCANStatus CAN_WriteFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer); 25 | * 26 | * includes : (none) 27 | * 28 | * author : Uwe Vogt, UV Software 29 | * 30 | * e-mail : uwe.vogt@uv-software.de 31 | * 32 | * 33 | * ----------- description -------------------------------------------- 34 | * 35 | * PCAN API - PEAK CAN Application Programming Interface 36 | * 37 | * This Application Programming Interface (API) is an almost compatible 38 | * implementation of the PEAK PCANBasic DLL on macOS (x86_64 and arm64). 39 | * 40 | * Supported CAN Interfaces: 41 | * - PCAN-USB (item no. IPEH-002021/002022) 42 | * - PCAN-USB FD (item no. IPEH-004022) 43 | * Up to 8 channel handles are supported. 44 | * 45 | * Version of PCAN API: 46 | * - Based on PEAK's version of 2024-01-26 47 | */ 48 | 49 | #ifndef PCAN_API_H_INCLUDED 50 | #define PCAN_API_H_INCLUDED 51 | 52 | /* ----------- includes ----------------------------------------------- 53 | */ 54 | 55 | #ifdef __APPLE__ 56 | #include // To map Windows integer types 57 | #endif 58 | 59 | /* ----------- defines ------------------------------------------------ 60 | */ 61 | 62 | #ifdef __APPLE__ 63 | #ifndef BYTE 64 | #define BYTE UInt8 65 | #endif 66 | #ifndef WORD 67 | #define WORD UInt16 68 | #endif 69 | #ifndef DWORD 70 | #define DWORD UInt32 71 | #endif 72 | #ifndef UINT64 73 | #define UINT64 UInt64 74 | #endif 75 | #ifndef LPSTR 76 | #define LPSTR char* 77 | #endif 78 | #define __T(s) s 79 | #endif 80 | 81 | /* Currently defined and supported PCAN channels 82 | */ 83 | #define PCAN_NONEBUS 0x00U //!< Undefined/default value for a PCAN bus 84 | 85 | #define PCAN_USBBUS1 0x51U //!< PCAN-USB interface, channel 1 86 | #define PCAN_USBBUS2 0x52U //!< PCAN-USB interface, channel 2 87 | #define PCAN_USBBUS3 0x53U //!< PCAN-USB interface, channel 3 88 | #define PCAN_USBBUS4 0x54U //!< PCAN-USB interface, channel 4 89 | #define PCAN_USBBUS5 0x55U //!< PCAN-USB interface, channel 5 90 | #define PCAN_USBBUS6 0x56U //!< PCAN-USB interface, channel 6 91 | #define PCAN_USBBUS7 0x57U //!< PCAN-USB interface, channel 7 92 | #define PCAN_USBBUS8 0x58U //!< PCAN-USB interface, channel 8 93 | #ifndef __APPLE__ 94 | #define PCAN_USBBUS9 0x509U //!< PCAN-USB interface, channel 9 95 | #define PCAN_USBBUS10 0x50AU //!< PCAN-USB interface, channel 10 96 | #define PCAN_USBBUS11 0x50BU //!< PCAN-USB interface, channel 11 97 | #define PCAN_USBBUS12 0x50CU //!< PCAN-USB interface, channel 12 98 | #define PCAN_USBBUS13 0x50DU //!< PCAN-USB interface, channel 13 99 | #define PCAN_USBBUS14 0x50EU //!< PCAN-USB interface, channel 14 100 | #define PCAN_USBBUS15 0x50FU //!< PCAN-USB interface, channel 15 101 | #define PCAN_USBBUS16 0x510U //!< PCAN-USB interface, channel 16 102 | #endif 103 | 104 | 105 | /* Represent the PCAN error and status codes 106 | */ 107 | #define PCAN_ERROR_OK 0x00000U //!< No error 108 | #define PCAN_ERROR_XMTFULL 0x00001U //!< Transmit buffer in CAN controller is full 109 | #define PCAN_ERROR_OVERRUN 0x00002U //!< CAN controller was read too late 110 | #define PCAN_ERROR_BUSLIGHT 0x00004U //!< Bus error: an error counter reached the 'light' limit 111 | #define PCAN_ERROR_BUSHEAVY 0x00008U //!< Bus error: an error counter reached the 'heavy' limit 112 | #define PCAN_ERROR_BUSWARNING PCAN_ERROR_BUSHEAVY //!< Bus error: an error counter reached the 'warning' limit 113 | #define PCAN_ERROR_BUSPASSIVE 0x40000U //!< Bus error: the CAN controller is error passive 114 | #define PCAN_ERROR_BUSOFF 0x00010U //!< Bus error: the CAN controller is in bus-off state 115 | #define PCAN_ERROR_ANYBUSERR (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE) //!< Mask for all bus errors 116 | #define PCAN_ERROR_QRCVEMPTY 0x00020U //!< Receive queue is empty 117 | #define PCAN_ERROR_QOVERRUN 0x00040U //!< Receive queue was read too late 118 | #define PCAN_ERROR_QXMTFULL 0x00080U //!< Transmit queue is full 119 | #define PCAN_ERROR_REGTEST 0x00100U //!< Test of the CAN controller hardware registers failed (no hardware found) 120 | #define PCAN_ERROR_NODRIVER 0x00200U //!< Driver not loaded 121 | #define PCAN_ERROR_HWINUSE 0x00400U //!< Hardware already in use by a Net 122 | #define PCAN_ERROR_NETINUSE 0x00800U //!< A Client is already connected to the Net 123 | #define PCAN_ERROR_ILLHW 0x01400U //!< Hardware handle is invalid 124 | #define PCAN_ERROR_ILLNET 0x01800U //!< Net handle is invalid 125 | #define PCAN_ERROR_ILLCLIENT 0x01C00U //!< Client handle is invalid 126 | #define PCAN_ERROR_ILLHANDLE (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) //!< Mask for all handle errors 127 | #define PCAN_ERROR_RESOURCE 0x02000U //!< Resource (FIFO, Client, timeout) cannot be created 128 | #define PCAN_ERROR_ILLPARAMTYPE 0x04000U //!< Invalid parameter 129 | #define PCAN_ERROR_ILLPARAMVAL 0x08000U //!< Invalid parameter value 130 | #define PCAN_ERROR_UNKNOWN 0x10000U //!< Unknown error 131 | #define PCAN_ERROR_ILLDATA 0x20000U //!< Invalid data, function, or action 132 | #define PCAN_ERROR_ILLMODE 0x80000U //!< Driver object state is wrong for the attempted operation 133 | #define PCAN_ERROR_CAUTION 0x2000000U //!< An operation was successfully carried out, however, irregularities were registered 134 | #define PCAN_ERROR_INITIALIZE 0x4000000U //!< Channel is not initialized [Value was changed from 0x40000 to 0x4000000] 135 | #define PCAN_ERROR_ILLOPERATION 0x8000000U //!< Invalid operation [Value was changed from 0x80000 to 0x8000000] 136 | 137 | /* PCAN devices 138 | */ 139 | #define PCAN_NONE 0x00U //!< Undefined, unknown or not selected PCAN device value 140 | #define PCAN_PEAKCAN 0x01U //!< PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API 141 | #define PCAN_ISA 0x02U //!< PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus 142 | #define PCAN_DNG 0x03U //!< PCAN-Dongle 143 | #define PCAN_PCI 0x04U //!< PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express 144 | #define PCAN_USB 0x05U //!< PCAN-USB and PCAN-USB Pro 145 | #define PCAN_PCC 0x06U //!< PCAN-PC Card 146 | #define PCAN_VIRTUAL 0x07U //!< PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API 147 | #define PCAN_LAN 0x08U //!< PCAN Gateway devices 148 | 149 | /* PCAN parameters 150 | */ 151 | #define PCAN_DEVICE_ID 0x01U //!< Device identifier parameter 152 | #define PCAN_5VOLTS_POWER 0x02U //!< 5-Volt power parameter 153 | #define PCAN_RECEIVE_EVENT 0x03U //!< PCAN receive event handler parameter 154 | #define PCAN_MESSAGE_FILTER 0x04U //!< PCAN message filter parameter 155 | #define PCAN_API_VERSION 0x05U //!< PCAN-Basic API version parameter 156 | #define PCAN_CHANNEL_VERSION 0x06U //!< PCAN device channel version parameter 157 | #define PCAN_BUSOFF_AUTORESET 0x07U //!< PCAN Reset-On-Busoff parameter 158 | #define PCAN_LISTEN_ONLY 0x08U //!< PCAN Listen-Only parameter 159 | #define PCAN_LOG_LOCATION 0x09U //!< Directory path for log files 160 | #define PCAN_LOG_STATUS 0x0AU //!< Debug-Log activation status 161 | #define PCAN_LOG_CONFIGURE 0x0BU //!< Configuration of the debugged information (LOG_FUNCTION_***) 162 | #define PCAN_LOG_TEXT 0x0CU //!< Custom insertion of text into the log file 163 | #define PCAN_CHANNEL_CONDITION 0x0DU //!< Availability status of a PCAN-Channel 164 | #define PCAN_HARDWARE_NAME 0x0EU //!< PCAN hardware name parameter 165 | #define PCAN_RECEIVE_STATUS 0x0FU //!< Message reception status of a PCAN-Channel 166 | #define PCAN_CONTROLLER_NUMBER 0x10U //!< CAN-Controller number of a PCAN-Channel 167 | #define PCAN_TRACE_LOCATION 0x11U //!< Directory path for PCAN trace files 168 | #define PCAN_TRACE_STATUS 0x12U //!< CAN tracing activation status 169 | #define PCAN_TRACE_SIZE 0x13U //!< Configuration of the maximum file size of a CAN trace 170 | #define PCAN_TRACE_CONFIGURE 0x14U //!< Configuration of the trace file storing mode (TRACE_FILE_***) 171 | #define PCAN_CHANNEL_IDENTIFYING 0x15U //!< Physical identification of a USB based PCAN-Channel by blinking its associated LED 172 | #define PCAN_CHANNEL_FEATURES 0x16U //!< Capabilities of a PCAN device (FEATURE_***) 173 | #define PCAN_BITRATE_ADAPTING 0x17U //!< Using of an existing bit rate (PCAN-View connected to a channel) 174 | #define PCAN_BITRATE_INFO 0x18U //!< Configured bit rate as Btr0Btr1 value 175 | #define PCAN_BITRATE_INFO_FD 0x19U //!< Configured bit rate as TPCANBitrateFD string 176 | #define PCAN_BUSSPEED_NOMINAL 0x1AU //!< Configured nominal CAN Bus speed as Bits per seconds 177 | #define PCAN_BUSSPEED_DATA 0x1BU //!< Configured CAN data speed as Bits per seconds 178 | #define PCAN_IP_ADDRESS 0x1CU //!< Remote address of a LAN channel as string in IPv4 format 179 | #define PCAN_LAN_SERVICE_STATUS 0x1DU //!< Status of the Virtual PCAN-Gateway Service 180 | #define PCAN_ALLOW_STATUS_FRAMES 0x1EU //!< Status messages reception status within a PCAN-Channel 181 | #define PCAN_ALLOW_RTR_FRAMES 0x1FU //!< RTR messages reception status within a PCAN-Channel 182 | #define PCAN_ALLOW_ERROR_FRAMES 0x20U //!< Error messages reception status within a PCAN-Channel 183 | #define PCAN_INTERFRAME_DELAY 0x21U //!< Delay, in microseconds, between sending frames 184 | #define PCAN_ACCEPTANCE_FILTER_11BIT 0x22U //!< Filter over code and mask patterns for 11-Bit messages 185 | #define PCAN_ACCEPTANCE_FILTER_29BIT 0x23U //!< Filter over code and mask patterns for 29-Bit messages 186 | #define PCAN_IO_DIGITAL_CONFIGURATION 0x24U //!< Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive 187 | #define PCAN_IO_DIGITAL_VALUE 0x25U //!< Value assigned to a 32 digital I/O pins of a PCAN-USB Chip 188 | #define PCAN_IO_DIGITAL_SET 0x26U //!< Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High 189 | #define PCAN_IO_DIGITAL_CLEAR 0x27U //!< Clear multiple digital I/O pins to 0 190 | #define PCAN_IO_ANALOG_VALUE 0x28U //!< Get value of a single analog input pin 191 | #define PCAN_FIRMWARE_VERSION 0x29U //!< Get the version of the firmware used by the device associated with a PCAN-Channel 192 | #define PCAN_ATTACHED_CHANNELS_COUNT 0x2AU //!< Get the amount of PCAN channels attached to a system 193 | #define PCAN_ATTACHED_CHANNELS 0x2BU //!< Get information about PCAN channels attached to a system 194 | #define PCAN_ALLOW_ECHO_FRAMES 0x2CU //!< Echo messages reception status within a PCAN-Channel 195 | #define PCAN_DEVICE_PART_NUMBER 0x2DU //!< Get the part number associated to a device 196 | #define PCAN_HARD_RESET_STATUS 0x2EU //!< Activation status of hard reset processing via CAN_Reset calls 197 | #define PCAN_LAN_CHANNEL_DIRECTION 0x2FU //!< Communication direction of a PCAN-Channel representing a PCAN-LAN interface 198 | #define PCAN_EXT_BTR0BTR1 0x80U //!< UVS: bit-timing register 199 | #define PCAN_EXT_TX_COUNTER 0x81U //!< UVS: number of transmitted frames 200 | #define PCAN_EXT_RX_COUNTER 0x82U //!< UVS: number of received frames 201 | #define PCAN_EXT_ERR_COUNTER 0x83U //!< UVS: number of error frames 202 | #define PCAN_EXT_RX_QUE_OVERRUN 0x84U //!< UVS: receive queue overrun counter 203 | #define PCAN_EXT_HARDWARE_VERSION 0x85U //!< UVS: version number of the interface firmware 204 | #define PCAN_EXT_SOFTWARE_VERSION 0x86U //!< UVS: version number of the driver respectively library 205 | #define PCAN_EXT_RECEIVE_CALLBACK 0x87U //!< UVS: callback function called on the reception of an URB 206 | #define PCAN_EXT_LOG_USB 0x8FU //!< UVS: Log USB communication (URB buffer <==> CAN messages) 207 | 208 | /* DEPRECATED parameters 209 | */ 210 | #define PCAN_DEVICE_NUMBER PCAN_DEVICE_ID //!< Deprecated parameter. Use PCAN_DEVICE_ID instead 211 | 212 | /* PCAN parameter values 213 | */ 214 | #define PCAN_PARAMETER_OFF 0x00U //!< The PCAN parameter is not set (inactive) 215 | #define PCAN_PARAMETER_ON 0x01U //!< The PCAN parameter is set (active) 216 | #define PCAN_FILTER_CLOSE 0x00U //!< The PCAN filter is closed. No messages will be received 217 | #define PCAN_FILTER_OPEN 0x01U //!< The PCAN filter is fully opened. All messages will be received 218 | #define PCAN_FILTER_CUSTOM 0x02U //!< The PCAN filter is custom configured. Only registered messages will be received 219 | #define PCAN_CHANNEL_UNAVAILABLE 0x00U //!< The PCAN-Channel handle is illegal, or its associated hardware is not available 220 | #define PCAN_CHANNEL_AVAILABLE 0x01U //!< The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in) 221 | #define PCAN_CHANNEL_OCCUPIED 0x02U //!< The PCAN-Channel handle is valid, and is already being used 222 | #define PCAN_CHANNEL_PCANVIEW (PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED) //!< The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect 223 | 224 | #define LOG_FUNCTION_DEFAULT 0x00U //!< Logs system exceptions / errors 225 | #define LOG_FUNCTION_ENTRY 0x01U //!< Logs the entries to the PCAN-Basic API functions 226 | #define LOG_FUNCTION_PARAMETERS 0x02U //!< Logs the parameters passed to the PCAN-Basic API functions 227 | #define LOG_FUNCTION_LEAVE 0x04U //!< Logs the exits from the PCAN-Basic API functions 228 | #define LOG_FUNCTION_WRITE 0x08U //!< Logs the CAN messages passed to the CAN_Write function 229 | #define LOG_FUNCTION_READ 0x10U //!< Logs the CAN messages received within the CAN_Read function 230 | #define LOG_FUNCTION_ALL 0xFFFFU //!< Logs all possible information within the PCAN-Basic API functions 231 | 232 | #define TRACE_FILE_SINGLE 0x00U //!< A single file is written until it size reaches PAN_TRACE_SIZE 233 | #define TRACE_FILE_SEGMENTED 0x01U //!< Traced data is distributed in several files with size PAN_TRACE_SIZE 234 | #define TRACE_FILE_DATE 0x02U //!< Includes the date into the name of the trace file 235 | #define TRACE_FILE_TIME 0x04U //!< Includes the start time into the name of the trace file 236 | #define TRACE_FILE_OVERWRITE 0x80U //!< Causes the overwriting of available traces (same name) 237 | #define TRACE_FILE_DATA_LENGTH 0x100U //!< Causes using the data length column ('l') instead of the DLC column ('L') in the trace file 238 | 239 | #define FEATURE_FD_CAPABLE 0x01U //!< Device supports flexible data-rate (CAN-FD) 240 | #define FEATURE_DELAY_CAPABLE 0x02U //!< Device supports a delay between sending frames (FPGA based USB devices) 241 | #define FEATURE_IO_CAPABLE 0x04U //!< Device supports I/O functionality for electronic circuits (USB-Chip devices) 242 | 243 | #define SERVICE_STATUS_STOPPED 0x01U //!< The service is not running 244 | #define SERVICE_STATUS_RUNNING 0x04U //!< The service is running 245 | 246 | #define LAN_DIRECTION_READ 0x01U //!< The PCAN-Channel is limited to incoming communication only 247 | #define LAN_DIRECTION_WRITE 0x02U //!< The PCAN-Channel is limited to outgoing communication only 248 | #define LAN_DIRECTION_READ_WRITE (LAN_DIRECTION_READ | LAN_DIRECTION_WRITE) // The PCAN-Channel communication is bidirectional 249 | 250 | /* Other constants 251 | */ 252 | #define MAX_LENGTH_HARDWARE_NAME 33 //!< Maximum length of the name of a device: 32 characters + terminator 253 | #define MAX_LENGTH_VERSION_STRING 256 //!< Maximum length of a version string: 255 characters + terminator 254 | 255 | /* PCAN message types 256 | */ 257 | #define PCAN_MESSAGE_STANDARD 0x00U //!< The PCAN message is a CAN Standard Frame (11-bit identifier) 258 | #define PCAN_MESSAGE_RTR 0x01U //!< The PCAN message is a CAN Remote-Transfer-Request Frame 259 | #define PCAN_MESSAGE_EXTENDED 0x02U //!< The PCAN message is a CAN Extended Frame (29-bit identifier) 260 | #define PCAN_MESSAGE_FD 0x04U //!< The PCAN message represents a FD frame in terms of CiA Specs 261 | #define PCAN_MESSAGE_BRS 0x08U //!< The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate) 262 | #define PCAN_MESSAGE_ESI 0x10U //!< The PCAN message represents a FD error state indicator(CAN FD transmitter was error active) 263 | #define PCAN_MESSAGE_ECHO 0x20U //!< The PCAN message represents an echo CAN Frame 264 | #define PCAN_MESSAGE_ERRFRAME 0x40U //!< The PCAN message represents an error frame 265 | #define PCAN_MESSAGE_STATUS 0x80U //!< The PCAN message represents a PCAN status message 266 | 267 | /* LookUp Parameters 268 | */ 269 | #define LOOKUP_DEVICE_TYPE __T("devicetype") //!< Lookup channel by Device type (see PCAN devices e.g. PCAN_USB) 270 | #define LOOKUP_DEVICE_ID __T("deviceid") //!< Lookup channel by device id 271 | #define LOOKUP_CONTROLLER_NUMBER __T("controllernumber") //!< Lookup channel by CAN controller 0-based index 272 | #define LOOKUP_IP_ADDRESS __T("ipaddress") //!< Lookup channel by IP address (LAN channels only) 273 | 274 | /* Frame Type / Initialization Mode 275 | */ 276 | #define PCAN_MODE_STANDARD PCAN_MESSAGE_STANDARD 277 | #define PCAN_MODE_EXTENDED PCAN_MESSAGE_EXTENDED 278 | 279 | /* Baud rate codes = BTR0/BTR1 register values for the CAN controller. 280 | * You can define your own Baud rate with the BTROBTR1 register. 281 | * Take a look at www.peak-system.com for their free software "BAUDTOOL" 282 | * to calculate the BTROBTR1 register for every bit rate and sample point. 283 | */ 284 | #define PCAN_BAUD_1M 0x0014U //!< 1 MBit/s 285 | #define PCAN_BAUD_800K 0x0016U //!< 800 kBit/s 286 | #define PCAN_BAUD_500K 0x001CU //!< 500 kBit/s 287 | #define PCAN_BAUD_250K 0x011CU //!< 250 kBit/s 288 | #define PCAN_BAUD_125K 0x031CU //!< 125 kBit/s 289 | #define PCAN_BAUD_100K 0x432FU //!< 100 kBit/s 290 | #define PCAN_BAUD_95K 0xC34EU //!< 95,238 kBit/s 291 | #define PCAN_BAUD_83K 0x852BU //!< 83,333 kBit/s 292 | #define PCAN_BAUD_50K 0x472FU //!< 50 kBit/s 293 | #define PCAN_BAUD_47K 0x1414U //!< 47,619 kBit/s 294 | #define PCAN_BAUD_33K 0x8B2FU //!< 33,333 kBit/s 295 | #define PCAN_BAUD_20K 0x532FU //!< 20 kBit/s 296 | #define PCAN_BAUD_10K 0x672FU //!< 10 kBit/s 297 | #define PCAN_BAUD_5K 0x7F7FU //!< 5 kBit/s 298 | 299 | /* Represents the configuration for a CAN bit rate 300 | * Note: 301 | * * Each parameter and its value must be separated with a '='. 302 | * * Each pair of parameter/value must be separated using ','. 303 | * 304 | * Example: 305 | * f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1 306 | */ 307 | #define PCAN_BR_CLOCK __T("f_clock") 308 | #define PCAN_BR_CLOCK_MHZ __T("f_clock_mhz") 309 | #define PCAN_BR_NOM_BRP __T("nom_brp") 310 | #define PCAN_BR_NOM_TSEG1 __T("nom_tseg1") 311 | #define PCAN_BR_NOM_TSEG2 __T("nom_tseg2") 312 | #define PCAN_BR_NOM_SJW __T("nom_sjw") 313 | #define PCAN_BR_NOM_SAMPLE __T("nom_sam") 314 | #define PCAN_BR_DATA_BRP __T("data_brp") 315 | #define PCAN_BR_DATA_TSEG1 __T("data_tseg1") 316 | #define PCAN_BR_DATA_TSEG2 __T("data_tseg2") 317 | #define PCAN_BR_DATA_SJW __T("data_sjw") 318 | #define PCAN_BR_DATA_SAMPLE __T("data_ssp_offset") 319 | 320 | /* ----------- types -------------------------------------------------- 321 | */ 322 | 323 | #define TPCANHandle WORD //!< Represents a PCAN hardware channel handle 324 | #define TPCANStatus DWORD //!< Represents a PCAN status/error code (ATTENTION: changed from 64-bit to 32-bit) 325 | #define TPCANParameter BYTE //!< Represents a PCAN parameter to be read or set 326 | #define TPCANDevice BYTE //!< Represents a PCAN device 327 | #define TPCANMessageType BYTE //!< Represents the type of a PCAN message 328 | #define TPCANType BYTE //!< Represents the type of PCAN hardware to be initialized 329 | #define TPCANMode BYTE //!< Represents a PCAN filter mode 330 | #define TPCANBaudrate WORD //!< Represents a PCAN Baud rate register value 331 | #define TPCANBitrateFD LPSTR //!< Represents a PCAN-FD bit rate string 332 | #define TPCANTimestampFD UINT64//!< Represents a timestamp of a received PCAN FD message 333 | 334 | /** Represents a PCAN message 335 | */ 336 | typedef struct tagTPCANMsg 337 | { 338 | DWORD ID; //!< 11/29-bit message identifier 339 | TPCANMessageType MSGTYPE; //!< Type of the message 340 | BYTE LEN; //!< Data Length Code of the message (0..8) 341 | BYTE DATA[8]; //!< Data of the message (DATA[0]..DATA[7]) 342 | } TPCANMsg; 343 | 344 | /** Represents a timestamp of a received PCAN message 345 | * Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow 346 | */ 347 | typedef struct tagTPCANTimestamp 348 | { 349 | DWORD millis; //!< Base-value: milliseconds: 0.. 2^32-1 350 | WORD millis_overflow; //!< Roll-arounds of millis 351 | WORD micros; //!< Microseconds: 0..999 352 | } TPCANTimestamp; 353 | 354 | /** Represents a PCAN message from a FD capable hardware 355 | */ 356 | typedef struct tagTPCANMsgFD 357 | { 358 | DWORD ID; //!< 11/29-bit message identifier 359 | TPCANMessageType MSGTYPE; //!< Type of the message 360 | BYTE DLC; //!< Data Length Code of the message (0..15) 361 | BYTE DATA[64];//!< Data of the message (DATA[0]..DATA[63]) 362 | } TPCANMsgFD; 363 | 364 | /** Describes an available PCAN channel 365 | */ 366 | typedef struct tagTPCANChannelInformation 367 | { 368 | TPCANHandle channel_handle; //!< PCAN channel handle 369 | TPCANDevice device_type; //!< Kind of PCAN device 370 | BYTE controller_number; //!< CAN-Controller number 371 | DWORD device_features; //!< Device capabilities flag (see FEATURE_*) 372 | char device_name[MAX_LENGTH_HARDWARE_NAME]; //!< Device name 373 | DWORD device_id; //!< Device number 374 | DWORD channel_condition; //!< Availability status of a PCAN-Channel 375 | }TPCANChannelInformation; 376 | 377 | 378 | /* ----------- variables ---------------------------------------------- 379 | */ 380 | 381 | 382 | /* ----------- prototypes --------------------------------------------- 383 | */ 384 | 385 | #ifdef __cplusplus 386 | extern "C" { 387 | #define _DEF_ARG =0 388 | #else 389 | #define _DEF_ARG 390 | #endif 391 | 392 | /** @brief Initializes a PCAN Channel. 393 | * 394 | * @param[in] Channel The handle of a PCAN Channel. 395 | * @param[in] Btr0Btr1 The speed for the communication (BTR0BTR1 code). 396 | * @param[in] HwType (not used with PCAN USB devices) 397 | * @param[in] IOPort (not used with PCAN USB devices) 398 | * @param[in] Interrupt (not used with PCAN USB devices) 399 | * 400 | * @returns A TPCANStatus error code. 401 | */ 402 | TPCANStatus CAN_Initialize( 403 | TPCANHandle Channel, 404 | TPCANBaudrate Btr0Btr1, 405 | TPCANType HwType _DEF_ARG, 406 | DWORD IOPort _DEF_ARG, 407 | WORD Interrupt _DEF_ARG); 408 | 409 | /** @brief Initializes a FD capable PCAN Channel. 410 | * 411 | * @param[in] Channel The handle of a FD capable PCAN Channel. 412 | * @param[in] BitrateFD The speed for the communication (FD bit rate string). 413 | * 414 | * @remarks See PCAN_BR_* values 415 | *
    416 | *
  • Parameter and values must be separated by '='.
  • 417 | *
  • Couples of Parameter/value must be separated by ','.
  • 418 | *
  • Following Parameter must be filled out: f_clock, nom_brp, nom_sjw, nom_tseg1, nom_tseg2, 419 | * data_brp, data_sjw, data_tseg1, data_tseg2.
  • 420 | *
  • Following Parameters are optional (not used yet): data_ssp_offset, nom_sam.
  • 421 | *
422 | * @remarks Example: 423 | * @verbatim 424 | * f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1 425 | * @endverbatim 426 | * @returns A TPCANStatus error code. 427 | */ 428 | TPCANStatus CAN_InitializeFD( 429 | TPCANHandle Channel, 430 | TPCANBitrateFD BitrateFD); 431 | 432 | /** @brief Uninitializes one or all PCAN Channels initialized by CAN_Initialize 433 | * 434 | * @remarks Giving the TPCANHandle value "PCAN_NONEBUS", uninitializes all initialized channels. 435 | * 436 | * @param[in] Channel The handle of a PCAN Channel. 437 | * 438 | * @returns A TPCANStatus error code. 439 | */ 440 | TPCANStatus CAN_Uninitialize( 441 | TPCANHandle Channel); 442 | 443 | /** @brief Resets the receive and transmit queues of the PCAN Channel. 444 | * 445 | * @remarks A reset of the CAN controller is not performed. 446 | * 447 | * @param[in] Channel The handle of a PCAN Channel. 448 | * 449 | * @returns A TPCANStatus error code. 450 | */ 451 | TPCANStatus CAN_Reset( 452 | TPCANHandle Channel); 453 | 454 | /** @brief Gets the current status of a PCAN Channel. 455 | * 456 | * @param[in] Channel The handle of a PCAN Channel. 457 | * 458 | * @returns A TPCANStatus error code. 459 | */ 460 | TPCANStatus CAN_GetStatus( 461 | TPCANHandle Channel); 462 | 463 | /** @brief Reads a CAN message from the receive queue of a PCAN Channel. 464 | * 465 | * @param[in] Channel The handle of a PCAN Channel. 466 | * @param[out] MessageBuffer A TPCANMsg structure buffer to store the CAN message. 467 | * @param[out] TimestampBuffer A TPCANTimestamp structure buffer to get the reception time of the message. 468 | * If this value is not desired, this parameter should be passed as NULL. 469 | * 470 | * @returns A TPCANStatus error code. 471 | */ 472 | TPCANStatus CAN_Read( 473 | TPCANHandle Channel, 474 | TPCANMsg* MessageBuffer, 475 | TPCANTimestamp* TimestampBuffer); 476 | 477 | /** @brief Reads a CAN message from the receive queue of a FD capable PCAN Channel. 478 | * 479 | * @param[in] Channel The handle of a FD capable PCAN Channel. 480 | * @param[out] MessageBuffer A TPCANMsgFD structure buffer to store the CAN message. 481 | * @param[out] TimestampBuffer A TPCANTimestampFD buffer to get the reception time of the message. 482 | * If this value is not desired, this parameter should be passed as NULL. 483 | * 484 | * @returns A TPCANStatus error code. 485 | */ 486 | TPCANStatus CAN_ReadFD( 487 | TPCANHandle Channel, 488 | TPCANMsgFD* MessageBuffer, 489 | TPCANTimestampFD* TimestampBuffer); 490 | 491 | /** @brief Transmits a CAN message. 492 | * 493 | * @param[in] Channel The handle of a PCAN Channel. 494 | * @param[in] MessageBuffer A TPCANMsg buffer with the message to be sent. 495 | * 496 | * @returns A TPCANStatus error code. 497 | */ 498 | TPCANStatus CAN_Write( 499 | TPCANHandle Channel, 500 | TPCANMsg* MessageBuffer); 501 | 502 | /** @brief Transmits a CAN message over a FD capable PCAN Channel. 503 | * 504 | * @param[in] Channel The handle of a FD capable PCAN Channel. 505 | * @param[in] MessageBuffer A TPCANMsgFD buffer with the message to be sent. 506 | * 507 | * @returns A TPCANStatus error code. 508 | */ 509 | TPCANStatus CAN_WriteFD( 510 | TPCANHandle Channel, 511 | TPCANMsgFD* MessageBuffer); 512 | 513 | /** @brief Configures the reception filter. 514 | * 515 | * @remarks The message filter will be expanded with every call to this function. 516 | * If it is desired to reset the filter, please use the CAN_SetValue function. 517 | * 518 | * @param[in] Channel The handle of a PCAN Channel. 519 | * @param[in] FromID The lowest CAN ID to be received. 520 | * @param[in] ToID The highest CAN ID to be received. 521 | * @param[in] Mode Message type, Standard (11-bit identifier) or Extended (29-bit identifier). 522 | * 523 | * @returns A TPCANStatus error code. 524 | */ 525 | TPCANStatus CAN_FilterMessages( 526 | TPCANHandle Channel, 527 | DWORD FromID, 528 | DWORD ToID, 529 | TPCANMode Mode); 530 | 531 | /** @brief Retrieves a PCAN Channel value. 532 | * 533 | * @remarks Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used. 534 | * If a parameter is not available, a PCAN_ERROR_ILLPARAMTYPE error will be returned. 535 | * 536 | * @param[in] Channel The handle of a PCAN Channel. 537 | * @param[in] Parameter The TPCANParameter parameter to get. 538 | * @param[out] Buffer Buffer for the parameter value. 539 | * @param[in] BufferLength Size in bytes of the buffer. 540 | * 541 | * @returns A TPCANStatus error code. 542 | */ 543 | TPCANStatus CAN_GetValue( 544 | TPCANHandle Channel, 545 | TPCANParameter Parameter, 546 | void* Buffer, 547 | DWORD BufferLength); 548 | 549 | 550 | /** @brief Configures or sets a PCAN Channel value. 551 | * 552 | * @remarks Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used. 553 | * If a parameter is not available, a PCAN_ERROR_ILLPARAMTYPE error will be returned. 554 | * 555 | * @param[in] Channel The handle of a PCAN Channel. 556 | * @param[in] Parameter The TPCANParameter parameter to set. 557 | * @param[in] Buffer Buffer with the value to be set. 558 | * @param[in] BufferLength Size in bytes of the buffer. 559 | * 560 | * @returns A TPCANStatus error code. 561 | */ 562 | TPCANStatus CAN_SetValue( 563 | TPCANHandle Channel, 564 | TPCANParameter Parameter, 565 | void* Buffer, 566 | DWORD BufferLength); 567 | 568 | /** @brief Returns a descriptive text of a given TPCANStatus error code, in any desired language. 569 | * 570 | * @remarks The current languages available for translation are: 571 | * Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), Italian (0x10) and French (0x0C). 572 | * 573 | * @param[in] Error A TPCANStatus error code. 574 | * @param[in] Language Indicates a 'Primary language ID'. 575 | * @param[out] Buffer Buffer for a null terminated char array. 576 | * 577 | * @returns A TPCANStatus error code. 578 | */ 579 | TPCANStatus CAN_GetErrorText( 580 | TPCANStatus Error, 581 | WORD Language, 582 | LPSTR Buffer); 583 | 584 | /** @brief Finds a PCAN-Basic channel that matches with the given parameters 585 | * 586 | * @param[in] Parameters A comma separated string contained pairs of parameter-name/value 587 | * to be matched within a PCAN-Basic channel 588 | * @param[out] FoundChannel Buffer for returning the PCAN-Basic channel, when found 589 | * 590 | * @returns A TPCANStatus error code. 591 | */ 592 | TPCANStatus CAN_LookUpChannel( 593 | LPSTR Parameters, 594 | TPCANHandle* FoundChannel); 595 | 596 | #ifdef __cplusplus 597 | } 598 | #endif 599 | #endif /* PCAN_API_H_INCLUDED */ 600 | 601 | /* ---------------------------------------------------------------------- 602 | * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany 603 | * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 604 | * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ 605 | */ 606 | -------------------------------------------------------------------------------- /Binaries/Universal_64/README: -------------------------------------------------------------------------------- 1 | macOS Library for PCAN-USB Interfaces 2 | 3 | Copyright (c) 2013-2024 by UV Software, Berlin 4 | 5 | 6 | libPCBUSB 7 | ~~~~~~~~~ 8 | 9 | The PCBUSB library realizes a 'PCAN-USB Driver for macOS' using Apple´s IOUSBKit. 10 | It supports up to 8 PCAN-USB or PCAN-USB FD devices from PEAK-System Technik. 11 | See the header-file PCBUSB.h for details. 12 | 13 | PCAN is a registered trademark of PEAK-System Technik GmbH, Darmstadt, Germany. 14 | Mac and macOS are trademarks of Apple Inc., registered in the U.S. and other countries. 15 | 16 | This software is freeware without any warranty or support! 17 | 18 | Change-Log: 19 | - Version 0.13 of 07/28/2024: 20 | Synchronized PCBUSB header with PCANBasic header from PEAK's version 4.9.0 21 | Realized acceptance filtering by setting parameter: 22 | - PCAN_ACCEPTANCE_FILTER_11BIT (default = 0x00000000000007FF) 23 | - PCAN_ACCEPTANCE_FILTER_29BIT (default = 0x000000001FFFFFFF) 24 | - PCAN_MESSAGE_FILTER (default = PCAN_FILTER_OPEN) 25 | - PCAN_RECEIVE_STATUS (default = PCAN_PARAMETER_ON) 26 | Realized suppression of status frames by setting parameter: 27 | - PCAN_ALLOW_STATUS_FRAMES (default = PCAN_PARAMETER_ON) 28 | Realized suppression of remote frames by setting parameter: 29 | - PCAN_ALLOW_RTR_FRAMES (default = PCAN_PARAMETER_ON) 30 | - Version 0.12.2 of 11/01/2023: 31 | Synchronized PCBUSB header with PCANBasic header from PEAK's version 4.8.0 32 | Fixed a bug with pipe numbers for PCAN-USB FD devices (hardware version 6.0) 33 | Added missing linker option '-rpath /usr/local/lib' to the C++ examples 34 | Updated the README file (unsupported parameter PCAN_HARD_RESET_STATUS) 35 | - Version 0.12.1 of 09/23/2023: 36 | Fixed a bug with endianess of 32-bit device id. (issue #384: PCAN-USB [Pro] FD) 37 | Reworked return values of CAN_Read(), CAN_ReadFD(), CAN_Write(), CAN_WriteFD() 38 | Reset USB pipe #4 after write timed out (CAN Write stalled; macOS 11 and higher) 39 | - Version 0.12 of 01/31/2023: 40 | Realized setting of device id. for PCAN-USB FD devices 41 | Reworked status frame handling: 42 | - fixed some bugs in the driver layer (all device types) 43 | - suppressed initial CAN FD status frame in CAN 2.0 mode 44 | - corrected mapping of bus error states to PCAN status 45 | - fixed a bug with CAN id. of status messages 46 | - CAN_Read(), CAN_ReadFD(), CAN_Write(), CAN_WriteFD(): return bus error states 47 | SetValue(): Set default value if argument 'BufferLength' is equal to 0: 48 | - PCAN_LISTEN_ONLY (default = OFF) 49 | - PCAN_DEVICE_ID (default = 0) 50 | - PCAN_TRACE_LOCATION (default = cwd) 51 | - PCAN_TRACE_STATUS (default = OFF) 52 | - PCAN_TRACE_SIZE (default 0 = 100k frames!) 53 | - PCAN_TRACE_CONFIGURE (default = SINGLE_FILE) 54 | GetValue(): Implemented missing parameters: 55 | - PCAN_ALLOW_RTR_FRAMES (read-only!) 56 | - PCAN_ALLOW_STATUS_FRAMES (read-only!) 57 | - PCAN_ALLOW_ERROR_FRAMES (read-only!) 58 | - PCAN_CONTROLLER_NUMBER (read-only) 59 | - PCAN_DEVICE_PART_NUMBER (read-only) 60 | Made GetValue(PCAN_RECEIVE_EVENT) more robust if argument is greater than size of int 61 | Reading of additional bytes from firmware info packet to distinguish product variants 62 | Fixed a bug with stuck in CAN_Write when errors on bus 63 | (note: the solution only works on macOS 11.0 and newer) 64 | Fixed a bug with status frames not triggering the pipe for blocking read 65 | Fixed a bug with getting the firmware version from USB device name 66 | (note: since firmware 3.x the version is not encoded in the device name anymore) 67 | Fixed a bug with string length for bit-rate strings 68 | Fixed a bug with GetValue(BITRATE_INFO_FD) w/o BRSE 69 | Fixed a bug with size of parameter 'PCAN_TRACE_SIZE' 70 | Fixed some findings from static code analysis (Xcode and cppcheck) 71 | - Version 0.11.2 of 07/30/2022: 72 | Fixed the CAN FD URB issue ('Messages lost on high CAN FD bit-rates') 73 | Added installation instruction (after all these years) 74 | - Version 0.11.1 of 04/30/2022: 75 | Fixed the Monterey issue ('Driver not loaded') 76 | Fixed some findings from static code analysis 77 | Added `@rpath` to all build environments 78 | Improved the installation script 79 | Updated the README file 80 | - Version 0.11 of 01/31/2022: 81 | Synchronized PCBUSB header with PCANBasic header for v4.6.0. 82 | Fixed a bug with PCAN_CHANNEL_CONDITION when used by another process 83 | Fixed an omission with export declaration for CAN_LookUpChannel 84 | Implemented parameter PCAN_FIRMWARE_VERSION (read-only) 85 | Added error text for PCAN_ERROR_ILLMODE (all languages) 86 | Corrected some French error text (acc. to Peak´s changes) 87 | Return PCAN_ERROR_HWINUSE when interface is used by another process: 88 | - CAN_GetValue: PCAN_LISTEN_ONLY, PCAN_RECEIVE_STATUS, PCAN_LISTEN_ONLY 89 | Return PCAN_ERROR_ILLCLIENT if an invalid channel handle given: 90 | - CAN_GetValue: PCAN_RECEIVE_EVENT, PCAN_CHANNEL_CONDITION, PCAN_TRACE_LOCATION, 91 | PCAN_TRACE_STATUS, PCAN_TRACE_SIZE, PCAN_TRACE_CONFIGURE, 92 | PCAN_BITRATE_INFO, PCAN_BITRATE_INFO_FD, PCAN_BUSSPEED_NOMINAL, 93 | PCAN_BUSSPEED_DATA, PCAN_FIRMWARE_VERSION 94 | - CAN_SetValue: PCAN_DEVICE_ID, PCAN_TRACE_LOCATION, PCAN_TRACE_STATUS, 95 | PCAN_TRACE_SIZE, PCAN_TRACE_CONFIGURE 96 | - CAN_Reset, CAN_GetStatus , CAN_Read, CAN_ReadFD, CAN_Write, CAN_WriteFD 97 | * Peak-System harmonized its return codes in PCANBasic DLL version 4.6.0. 98 | Now the return codes matches my expectation. 99 | Added `@rpath` to the build environment (it got lost for some releases) 100 | Code signed the Universal macOS Binary (Apple Development certificate) 101 | - Version 0.10.1 of 12/05/2021: 102 | Built library as Universal macOS Binary (macOS_Library_for_PCANUSB_v0.10.1.tar.gz) 103 | Built library for x86_64 architecture (OS_X_Library_for_PCANUSB_v0.10.1.tar.gz) 104 | Parameter PCAN_CHANNEL_VERSION displays machine architecture from utsname() 105 | Fixed a bug with parameter PCAN_EXT_HARDWARE_VERSION for PCAN-USB Pro FD device 106 | - Version 0.10 of 12/22/2020: 107 | Support of PCAN-USB Pro FD devices, but only the first channel (CAN1) 108 | Set linker options -install_name, -compatibility_version, and -current_version 109 | Synchronized the API with Peak´s PCANBasic version 4.5.0.440 110 | Updated the Python example: reworked the output format 111 | - Version 0.9 of 06/25/2020: 112 | Data types from as replacement for Peak´s usage of Windows BYTE, 113 | WORD, DWORD and UINT64 (field CAN ID is now 32-bit wide) 114 | Synchronized the API with Peak´s PCANBasic version 4.4.0.288 115 | Parameter PCAN_DEVICE_ID can be read in pre-initialization state 116 | Fixed some bugs with status bit: PCAN_ERROR_QXMTFULL, PCAN_ERROR_XMTFULL, 117 | PCAN_ERROR_QOVERRUN, PCAN_ERROR_BUSLIGHT 118 | Added a delay of 1 usec in CAN_Write to run on macOS 10.15 (Catalina) 119 | - Version 0.8.1 of 09/27/2019: 120 | Adapted trace-file headers to Peak's changes in version 4.3.4.246 121 | - Version 0.8 of 09/20/2017: 122 | Support of PCAN-USB FD devices in CAN 2.0 mode (CAN classic) and CAN FD mode! 123 | Adapted the API according to Peak's changes in version 4.2.0.134 and harmonized 124 | return codes with it 125 | Fixed issue #208 'CAN_Write stuck when errors on the bus are present' 126 | Conducted an intermediate solution for issue #246 (writing into a trace file) 127 | Added run-path-relative install name to the library (using the @rpath macro) 128 | - Version 0.7 of 11/30/2016: 129 | Adapted the API according to Peak's changes in version 4.1.0.96 and harmonized 130 | return codes with it 131 | Implemented parameter PCAN_CHANNEL_FEATURE and PCAN_BITRATE_INFO 132 | - Version 0.6 of 02/20/2015: 133 | Parameter PCAN_RECEIVE_EVENT returns a file descriptor to realize 'blocking 134 | read' by select() as on the Linux implementation of the PCAN-Basic API 135 | Added two C++ examples and one Python example using the PCBUSB library 136 | - Version 0.5 of 11/23/2014: 137 | Feature 'Reading/Writing of parameter PCAN_DEVICE_NUMBER' implemented 138 | Fixed issue #104 'Hot plugging was not detected by the library/driver' 139 | Fixed issue #117 'Permission for libPCBUSB.x.y.lib wrong' (chmod 755) 140 | Return codes of API functions harmonized with PCANBasic.dll (1.3.3.61) 141 | - Version 0.4 of 02/23/2014: 142 | Time-stamps are now taken from CAN controller instead of taking them from the 143 | system clock 144 | Getting and setting of PCAN_* parameters reworked (to be almost compatible to 145 | the PCANBasic DLL, version 1.3) 146 | Resetting of RCV and XMT queue on the CAN controller realized 147 | - Version 0.3 of 11/02/2013: 148 | Fixed issue #11 'All channel initialized by the application will be closed 149 | even if they are in use' 150 | CAN_Unitialize: closing all channel initialized by the application at once 151 | implemented 152 | CAN_Read: receive queue overrun handling reworked 153 | CAN_*: wrong function return codes corrected 154 | CAN_GetErrorText: language support for English, German, French, Italian and 155 | Spanish added 156 | - Version 0.2 of 09/08/2013: 157 | Minor changes 158 | - Version 0.1 of 06/30/2013: 159 | Initial revision 160 | 161 | Limitations: 162 | - CAN_Initialize() resp. CAN_InitializeFD(): 163 | Only the following devices are supported: 164 | - PCAN-USB (item no. IPEH-002021 and IPEH-002022) 165 | - PCAN-USB FD (item no. IPEH-004022) 166 | - PCAN-USB Pro FD (item no. IPEH-004061), but only the first channel (CAN1) 167 | - CAN_Write() resp. CAN_WriteFD(): 168 | Transmission of the given message on the CAN bus is not acknowledged by 169 | the USB interface. 170 | A transmission queue like in the Windows driver is not realized. 171 | - CAN_FilterMessages(): 172 | Filter ranges are not supported. Acceptance filtering is supported by setting 173 | parameter (PCAN_ACCEPTANCE_FILTER_11BIT or PCAN_ACCEPTANCE_FILTER_29BIT). 174 | - CAN_GetValue(): 175 | Still unsupported parameter are: PCAN_5VOLTS_POWER, 176 | PCAN_BUSOFF_AUTORESET, PCAN_LOG_LOCATION, PCAN_LOG_STATUS, PCAN_LOG_CONFIGURE, 177 | PCAN_LOG_TEXT, PCAN_CHANNEL_IDENTIFYING, PCAN_BITRATE_ADAPTING, PCAN_IP_ADDRESS, 178 | PCAN_LAN_SERVICE_STATUS, PCAN_INTERFRAME_DELAY, PCAN_ATTACHED_CHANNELS_COUNT, 179 | PCAN_ATTACHED_CHANNELS, PCAN_HARD_RESET_STATUS, PCAN_LAN_CHANNEL_DIRECTION. 180 | - CAN_SetValue(): 181 | Still unsupported parameter are: PCAN_5VOLTS_POWER, PCAN_RECEIVE_EVENT, 182 | PCAN_BUSOFF_AUTORESET, PCAN_LOG_LOCATION, PCAN_LOG_STATUS, PCAN_LOG_CONFIGURE, 183 | PCAN_LOG_TEXT, PCAN_CHANNEL_IDENTIFYING, PCAN_BITRATE_ADAPTING, 184 | PCAN_ALLOW_STATUS_FRAMES, PCAN_ALLOW_RTR_FRAMES, PCAN_ALLOW_ERROR_FRAMES, 185 | PCAN_INTERFRAME_DELAY, PCAN_ALLOW_ECHO_FRAMES, PCAN_HARD_RESET_STATUS. 186 | - CAN_LookUpChannel(): 187 | Channel searching is currently not supported. 188 | - Writing into a trace file: 189 | Only 100'000 frames can be recorded into one trace file. 190 | An existing trace file with the same file name will be overwritten. 191 | 192 | Known bugs and caveats 193 | - The LED of the PCAN-USB FD device is not turned on (green) when the device 194 | is plugged into the USB bus. This is due to the fact that there is no 'real' 195 | driver for PCAN-USB devices under macOS. So the LED of the PCAN-USB FD device 196 | cannot signal the presence of a driver. When operating the LED signals the 197 | correct operation state of the PCAN-USB FD device (blinking green, or red 198 | on error). 199 | - The same LED issue is for the PCAN-USB Pro FD device. The LED for the first 200 | channel signals its operation state only when operated by an application. 201 | - The second channel of the PCAN-USB Pro FD device is not supported by the 202 | driver. It is not listed in the device list; its LED is turned off. 203 | - When a successfully initialized PCAN-USB device is physically removed from 204 | USB any subsequent call of API functions (e.g. CAN_Read) will not succeed 205 | even when the device is plugged in again. An error code will be returned in 206 | this case. 207 | 208 | Contact 209 | ~~~~~~~ 210 | 211 | E-Mail: mailto:info@mac-can.com 212 | Internet: http://www.mac-can.com 213 | -------------------------------------------------------------------------------- /Binaries/Universal_64/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ProjName=PCBUSB 4 | ProjVersion=0.13 5 | BaseDir=$(dirname $0) 6 | InstallDir=/usr/local/lib 7 | IncludeDir=/usr/local/include 8 | 9 | if [ -f "$BaseDir/lib$ProjName.$ProjVersion.dylib" ] 10 | then 11 | if [ ! -d "$InstallDir" ] 12 | then 13 | mkdir "$InstallDir" 14 | fi 15 | if [ -f "$InstallDir/lib$ProjName.dylib" ] 16 | then 17 | rm -f "$InstallDir/lib$ProjName.dylib" 18 | fi 19 | if [ -f "$InstallDir/lib$ProjName.$ProjVersion.dylib" ] 20 | then 21 | rm -f "$InstallDir/lib$ProjName.$ProjVersion.dylib" 22 | fi 23 | cp "$BaseDir/lib$ProjName.$ProjVersion.dylib" "$InstallDir/lib$ProjName.$ProjVersion.dylib" 24 | ln -s "$InstallDir/lib$ProjName.$ProjVersion.dylib" "$InstallDir/lib$ProjName.dylib" 25 | chmod 755 "$InstallDir/lib$ProjName.$ProjVersion.dylib" 26 | chmod 755 "$InstallDir/lib$ProjName.dylib" 27 | else 28 | echo "error dylib" 29 | fi 30 | 31 | if [ -f "$BaseDir/$ProjName.h" ] 32 | then 33 | if [ -d "$IncludeDir" ] 34 | then 35 | cp "$BaseDir/$ProjName.h" "$IncludeDir/$ProjName.h" 36 | else 37 | mkdir "$IncludeDir"; cp "$BaseDir/$ProjName.h" "$IncludeDir/$ProjName.h" 38 | fi 39 | else 40 | echo "error header" 41 | fi 42 | -------------------------------------------------------------------------------- /Binaries/Universal_64/install.txt: -------------------------------------------------------------------------------- 1 | macOS Library for PCAN-USB Interfaces 2 | 3 | Copyright (c) 2013-2024 by UV Software, Berlin 4 | 5 | 6 | How to install the PCBUSB-Library on Mac 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | 9 | 1. Download the Library 10 | 11 | First download the library either from the MacCAN homepage at 12 | or from the GitHub repo at . 13 | 14 | Note: Archives with name prefix 'macOS_' contain the artifacts that are compiled as 15 | Universal Binary for Intel x86_64 and Apple silicon. They require macOS 12.x 16 | (Monterey) or higher. 17 | Archives with name prefix 'OS_X_' contain the artifacts for OS X 10.x (Intel 18 | x86_64 only). 19 | 20 | 2. Install the Library 21 | 22 | Now open a terminal to extract the artifacts and to install the library. 23 | 24 | Note: In the following example I've downloaded version 0.13 from the MacCAN homepage. 25 | 'makemake' is my username, 'uv-pc014mac' the name of my Mac. 26 | 27 | 2.1 Extract the Artifacts 28 | 29 | If you have downloaded the library as a tarball, type this: 30 | 31 | makemake@uv-pc014mac ~ % tar -xvf ~/Downloads/macOS_Library_for_PCANUSB_v0.13.tar 32 | 33 | If you have downloaded a compressed archive, then run this: 34 | 35 | makemake@uv-pc014mac ~ % tar -xzvf ~/Downloads/macOS_Library_for_PCANUSB_v0.13.tar.gz 36 | 37 | 2.2 Install the dylib 38 | 39 | To install the dylib you need superuser privileges. Type this: 40 | 41 | makemake@uv-pc014mac ~ % cd PCBUSB 42 | makemake@uv-pc014mac PCBUSB % sudo /Users//PCBUSB/install.sh 43 | Password: 44 | 45 | 3. Using the library 46 | 47 | That's up to you. 48 | 49 | 50 | Contact 51 | ~~~~~~~ 52 | 53 | E-Mail: mailto:info@mac-can.com 54 | Internet: http://www.mac-can.com 55 | -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.0.10.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.0.10.1.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.0.11.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.0.11.1.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.0.11.2.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.0.11.2.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.0.11.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.0.11.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.0.12.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.0.12.1.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.0.12.2.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.0.12.2.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.0.12.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.0.12.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.0.13.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.0.13.dylib -------------------------------------------------------------------------------- /Binaries/Universal_64/libPCBUSB.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac-can/PCBUSB-Library/HEAD/Binaries/Universal_64/libPCBUSB.a -------------------------------------------------------------------------------- /Examples/C++/Makefile: -------------------------------------------------------------------------------- 1 | LIB = PCBUSB 2 | 3 | SRC = src 4 | 5 | CFLAGS += 6 | LDFLAGS += -rpath /usr/local/lib 7 | 8 | TARGET1 = pcbusb_send 9 | FILES1 = $(SRC)/$(TARGET1).cpp 10 | 11 | TARGET2 = pcbusb_recv 12 | FILES2 = $(SRC)/$(TARGET2).cpp 13 | 14 | all: $(TARGET1) $(TARGET2) 15 | 16 | $(TARGET1): $(FILES1) 17 | clang++ $(FILES1) $(CFLAGS) -l $(LIB) $(LDFLAGS) -o $(TARGET1) 18 | 19 | $(TARGET2): $(FILES2) 20 | clang++ $(FILES2) $(CFLAGS) -l $(LIB) $(LDFLAGS) -o $(TARGET2) 21 | 22 | clean: 23 | @-rm -f $(SRC)/*.o $(TARGET1) $(TARGET2) 24 | 25 | pristine: 26 | @-rm -f $(SRC)/*.o $(SRC)/*~ *~ $(TARGET1) $(TARGET2) 27 | 28 | install: 29 | @-cp $(TARGET1) /usr/local/bin 30 | @-cp $(TARGET2) /usr/local/bin 31 | -------------------------------------------------------------------------------- /Examples/C++/src/pcbusb_recv.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // macOS Library for PCAN-USB Interfaces 3 | // Example: receive CAN messages (Blockng read) 4 | // 5 | // To compile type `clang++ pcbusb_recv.cpp -l PCBUSB -o pcbusb_recv' 6 | // libPCBUSB.dylib is expected to be in the library search path. 7 | // 8 | // Note: Press Ctrl+C to terminate the program. 9 | // 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "PCBUSB.h" 18 | 19 | #define PCAN_CHANNEL PCAN_USBBUS1 20 | #define PCAN_BAUDRATE PCAN_BAUD_250K 21 | 22 | static volatile int running = 1; 23 | static void sigterm(int signo) 24 | { 25 | //printf("got signal %d\n", signo); 26 | running = 0; 27 | } 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | int fdes; 32 | fd_set rdfs; 33 | 34 | TPCANMsg message; 35 | TPCANStatus status; 36 | 37 | if ((signal(SIGTERM, sigterm) == SIG_ERR) || 38 | (signal(SIGINT, sigterm) == SIG_ERR)) { 39 | perror("Error"); 40 | return errno; 41 | } 42 | status = CAN_Initialize(PCAN_CHANNEL, PCAN_BAUDRATE, 0, 0, 0); 43 | printf("Initialize CAN: 0x%x\n", status); 44 | if (status != PCAN_ERROR_OK) goto leave; 45 | 46 | // get a file descriptor for blocking read via `select' 47 | status = CAN_GetValue(PCAN_CHANNEL, PCAN_RECEIVE_EVENT, &fdes, sizeof(int)); 48 | if (status != PCAN_ERROR_OK) goto leave; 49 | 50 | // see `man select' for details on I/O descriptor sets 51 | FD_ZERO(&rdfs); 52 | FD_SET(fdes, &rdfs); 53 | 54 | while (running) { 55 | status = CAN_Read(PCAN_CHANNEL, &message, NULL); 56 | if (status == PCAN_ERROR_OK) { 57 | if (!(message.MSGTYPE & PCAN_MESSAGE_STATUS)) 58 | printf(" - R ID:%4x LEN:%1x DATA:%02x %02x %02x %02x %02x %02x %02x %02x\n", 59 | (int) message.ID, (int) message.LEN, (int) message.DATA[0], 60 | (int) message.DATA[1], (int) message.DATA[2], 61 | (int) message.DATA[3], (int) message.DATA[4], 62 | (int) message.DATA[5], (int) message.DATA[6], 63 | (int) message.DATA[7]); 64 | } else if (status == PCAN_ERROR_QRCVEMPTY) { 65 | // block until at least one CAN message has been received 66 | if (select(fdes+1, &rdfs, NULL, NULL, NULL) < 0) 67 | perror("Error"); 68 | } else { 69 | printf("Error 0x%x\n", status); 70 | break; 71 | } 72 | } 73 | leave: 74 | CAN_Uninitialize(PCAN_NONEBUS); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /Examples/C++/src/pcbusb_send.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // macOS Library for PCAN-USB Interfaces 3 | // Example: send CAN messages 4 | // 5 | // To compile type `clang++ pcbusb_send.cpp -l PCBUSB -o pcbusb_send' 6 | // libPCBUSB.dylib is expected to be in the library search path. 7 | // 8 | // Note: Press Ctrl+C to terminate the program. 9 | // 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "PCBUSB.h" 18 | 19 | #define PCAN_CHANNEL PCAN_USBBUS2 20 | #define PCAN_BAUDRATE PCAN_BAUD_250K 21 | 22 | static volatile int running = 1; 23 | static void sigterm(int signo) 24 | { 25 | //printf("got signal %d\n", signo); 26 | running = 0; 27 | } 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | TPCANMsg message; 32 | TPCANStatus status; 33 | unsigned long frames = 0; 34 | 35 | if ((signal(SIGTERM, sigterm) == SIG_ERR) || 36 | (signal(SIGINT, sigterm) == SIG_ERR)) { 37 | perror("+++ Error"); 38 | return errno; 39 | } 40 | status = CAN_Initialize(PCAN_CHANNEL, PCAN_BAUDRATE, 0, 0, 0); 41 | printf("Initialize CAN: 0x%x\n", status); 42 | if (status != PCAN_ERROR_OK) goto leave; 43 | 44 | message.ID = 0x100; 45 | message.LEN = 8; 46 | message.MSGTYPE = PCAN_MESSAGE_STANDARD; 47 | memset(message.DATA, 0x00, message.LEN); 48 | 49 | while (running) { 50 | if ((status = CAN_Write(PCAN_CHANNEL, &message)) == PCAN_ERROR_OK) { 51 | frames++; 52 | // if ((frames % 2048) == 0) 53 | // printf(" - T Message %lu\n", frames); 54 | message.DATA[0] = (BYTE)((frames & 0x000000FFU) >> 0); 55 | message.DATA[1] = (BYTE)((frames & 0x0000FF00U) >> 8); 56 | message.DATA[2] = (BYTE)((frames & 0x00FF0000U) >> 16); 57 | message.DATA[3] = (BYTE)((frames & 0xFF000000U) >> 24); 58 | } 59 | } 60 | leave: 61 | status = CAN_Uninitialize(PCAN_NONEBUS); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Examples/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | # if any Makefile failed, stop building all... 3 | @for m in `find . -mindepth 2 -name Makefile`; do\ 4 | $(MAKE) -C `dirname $$m`; \ 5 | if [ $$? -ne 0 ]; then exit 1; fi; \ 6 | done 7 | 8 | clean: 9 | -@for m in `find . -mindepth 2 -name Makefile`; do\ 10 | $(MAKE) -C `dirname $$m` clean; \ 11 | done 12 | -------------------------------------------------------------------------------- /Examples/Python/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @-echo Nothing to be done for ''all'' 3 | 4 | clean: 5 | @-rm -f *.pyc 6 | -------------------------------------------------------------------------------- /Examples/Python/PCANBasic.py: -------------------------------------------------------------------------------- 1 | # PCANBasic.py 2 | # 3 | # ~~~~~~~~~~~~ 4 | # 5 | # PCAN-Basic API 6 | # 7 | # ~~~~~~~~~~~~ 8 | # 9 | # ------------------------------------------------------------------ 10 | # Author : Keneth Wagner 11 | # Last change: 2023-08-28 12 | # Modified: 2023-06-16 info@mac-can.com 13 | # 14 | # Language: Python 2.7, 3.8 15 | # ------------------------------------------------------------------ 16 | # 17 | # Copyright (C) 1999-2023 PEAK-System Technik GmbH, Darmstadt 18 | # more Info at http://www.peak-system.com 19 | # 20 | 21 | # Module Imports 22 | # 23 | from ctypes import * 24 | from string import * 25 | import platform 26 | 27 | if platform.system() == "Darwin": 28 | # To solve an issue with file system relative paths that are not allowed 29 | # in hardened programs in Python 2.7 (under macOS). 30 | # Installation path on macOS is '/usr/local/lib' 31 | from ctypes.util import find_library 32 | 33 | #/////////////////////////////////////////////////////////// 34 | # Type definitions 35 | #/////////////////////////////////////////////////////////// 36 | 37 | TPCANHandle = c_ushort # Represents a PCAN hardware channel handle 38 | TPCANStatus = int # Represents a PCAN status/error code 39 | TPCANParameter = c_ubyte # Represents a PCAN parameter to be read or set 40 | TPCANDevice = c_ubyte # Represents a PCAN device 41 | TPCANMessageType = c_ubyte # Represents the type of a PCAN message 42 | TPCANType = c_ubyte # Represents the type of PCAN hardware to be initialized 43 | TPCANMode = c_ubyte # Represents a PCAN filter mode 44 | TPCANBaudrate = c_ushort # Represents a PCAN Baud rate register value 45 | TPCANBitrateFD = c_char_p # Represents a PCAN-FD bit rate string 46 | TPCANTimestampFD = c_ulonglong # Represents a timestamp of a received PCAN FD message 47 | 48 | #/////////////////////////////////////////////////////////// 49 | # Value definitions 50 | #/////////////////////////////////////////////////////////// 51 | 52 | # Currently defined and supported PCAN channels 53 | # 54 | PCAN_NONEBUS = TPCANHandle(0x00) # Undefined/default value for a PCAN bus 55 | 56 | PCAN_ISABUS1 = TPCANHandle(0x21) # PCAN-ISA interface, channel 1 57 | PCAN_ISABUS2 = TPCANHandle(0x22) # PCAN-ISA interface, channel 2 58 | PCAN_ISABUS3 = TPCANHandle(0x23) # PCAN-ISA interface, channel 3 59 | PCAN_ISABUS4 = TPCANHandle(0x24) # PCAN-ISA interface, channel 4 60 | PCAN_ISABUS5 = TPCANHandle(0x25) # PCAN-ISA interface, channel 5 61 | PCAN_ISABUS6 = TPCANHandle(0x26) # PCAN-ISA interface, channel 6 62 | PCAN_ISABUS7 = TPCANHandle(0x27) # PCAN-ISA interface, channel 7 63 | PCAN_ISABUS8 = TPCANHandle(0x28) # PCAN-ISA interface, channel 8 64 | 65 | PCAN_DNGBUS1 = TPCANHandle(0x31) # PCAN-Dongle/LPT interface, channel 1 66 | 67 | PCAN_PCIBUS1 = TPCANHandle(0x41) # PCAN-PCI interface, channel 1 68 | PCAN_PCIBUS2 = TPCANHandle(0x42) # PCAN-PCI interface, channel 2 69 | PCAN_PCIBUS3 = TPCANHandle(0x43) # PCAN-PCI interface, channel 3 70 | PCAN_PCIBUS4 = TPCANHandle(0x44) # PCAN-PCI interface, channel 4 71 | PCAN_PCIBUS5 = TPCANHandle(0x45) # PCAN-PCI interface, channel 5 72 | PCAN_PCIBUS6 = TPCANHandle(0x46) # PCAN-PCI interface, channel 6 73 | PCAN_PCIBUS7 = TPCANHandle(0x47) # PCAN-PCI interface, channel 7 74 | PCAN_PCIBUS8 = TPCANHandle(0x48) # PCAN-PCI interface, channel 8 75 | PCAN_PCIBUS9 = TPCANHandle(0x409) # PCAN-PCI interface, channel 9 76 | PCAN_PCIBUS10 = TPCANHandle(0x40A) # PCAN-PCI interface, channel 10 77 | PCAN_PCIBUS11 = TPCANHandle(0x40B) # PCAN-PCI interface, channel 11 78 | PCAN_PCIBUS12 = TPCANHandle(0x40C) # PCAN-PCI interface, channel 12 79 | PCAN_PCIBUS13 = TPCANHandle(0x40D) # PCAN-PCI interface, channel 13 80 | PCAN_PCIBUS14 = TPCANHandle(0x40E) # PCAN-PCI interface, channel 14 81 | PCAN_PCIBUS15 = TPCANHandle(0x40F) # PCAN-PCI interface, channel 15 82 | PCAN_PCIBUS16 = TPCANHandle(0x410) # PCAN-PCI interface, channel 16 83 | 84 | PCAN_USBBUS1 = TPCANHandle(0x51) # PCAN-USB interface, channel 1 85 | PCAN_USBBUS2 = TPCANHandle(0x52) # PCAN-USB interface, channel 2 86 | PCAN_USBBUS3 = TPCANHandle(0x53) # PCAN-USB interface, channel 3 87 | PCAN_USBBUS4 = TPCANHandle(0x54) # PCAN-USB interface, channel 4 88 | PCAN_USBBUS5 = TPCANHandle(0x55) # PCAN-USB interface, channel 5 89 | PCAN_USBBUS6 = TPCANHandle(0x56) # PCAN-USB interface, channel 6 90 | PCAN_USBBUS7 = TPCANHandle(0x57) # PCAN-USB interface, channel 7 91 | PCAN_USBBUS8 = TPCANHandle(0x58) # PCAN-USB interface, channel 8 92 | PCAN_USBBUS9 = TPCANHandle(0x509) # PCAN-USB interface, channel 9 93 | PCAN_USBBUS10 = TPCANHandle(0x50A) # PCAN-USB interface, channel 10 94 | PCAN_USBBUS11 = TPCANHandle(0x50B) # PCAN-USB interface, channel 11 95 | PCAN_USBBUS12 = TPCANHandle(0x50C) # PCAN-USB interface, channel 12 96 | PCAN_USBBUS13 = TPCANHandle(0x50D) # PCAN-USB interface, channel 13 97 | PCAN_USBBUS14 = TPCANHandle(0x50E) # PCAN-USB interface, channel 14 98 | PCAN_USBBUS15 = TPCANHandle(0x50F) # PCAN-USB interface, channel 15 99 | PCAN_USBBUS16 = TPCANHandle(0x510) # PCAN-USB interface, channel 16 100 | 101 | PCAN_PCCBUS1 = TPCANHandle(0x61) # PCAN-PC Card interface, channel 1 102 | PCAN_PCCBUS2 = TPCANHandle(0x62) # PCAN-PC Card interface, channel 2 103 | 104 | PCAN_LANBUS1 = TPCANHandle(0x801) # PCAN-LAN interface, channel 1 105 | PCAN_LANBUS2 = TPCANHandle(0x802) # PCAN-LAN interface, channel 2 106 | PCAN_LANBUS3 = TPCANHandle(0x803) # PCAN-LAN interface, channel 3 107 | PCAN_LANBUS4 = TPCANHandle(0x804) # PCAN-LAN interface, channel 4 108 | PCAN_LANBUS5 = TPCANHandle(0x805) # PCAN-LAN interface, channel 5 109 | PCAN_LANBUS6 = TPCANHandle(0x806) # PCAN-LAN interface, channel 6 110 | PCAN_LANBUS7 = TPCANHandle(0x807) # PCAN-LAN interface, channel 7 111 | PCAN_LANBUS8 = TPCANHandle(0x808) # PCAN-LAN interface, channel 8 112 | PCAN_LANBUS9 = TPCANHandle(0x809) # PCAN-LAN interface, channel 9 113 | PCAN_LANBUS10 = TPCANHandle(0x80A) # PCAN-LAN interface, channel 10 114 | PCAN_LANBUS11 = TPCANHandle(0x80B) # PCAN-LAN interface, channel 11 115 | PCAN_LANBUS12 = TPCANHandle(0x80C) # PCAN-LAN interface, channel 12 116 | PCAN_LANBUS13 = TPCANHandle(0x80D) # PCAN-LAN interface, channel 13 117 | PCAN_LANBUS14 = TPCANHandle(0x80E) # PCAN-LAN interface, channel 14 118 | PCAN_LANBUS15 = TPCANHandle(0x80F) # PCAN-LAN interface, channel 15 119 | PCAN_LANBUS16 = TPCANHandle(0x810) # PCAN-LAN interface, channel 16 120 | 121 | # Represent the PCAN error and status codes 122 | # 123 | PCAN_ERROR_OK = TPCANStatus(0x00000) # No error 124 | PCAN_ERROR_XMTFULL = TPCANStatus(0x00001) # Transmit buffer in CAN controller is full 125 | PCAN_ERROR_OVERRUN = TPCANStatus(0x00002) # CAN controller was read too late 126 | PCAN_ERROR_BUSLIGHT = TPCANStatus(0x00004) # Bus error: an error counter reached the 'light' limit 127 | PCAN_ERROR_BUSHEAVY = TPCANStatus(0x00008) # Bus error: an error counter reached the 'heavy' limit 128 | PCAN_ERROR_BUSWARNING = TPCANStatus(PCAN_ERROR_BUSHEAVY) # Bus error: an error counter reached the 'warning' limit 129 | PCAN_ERROR_BUSPASSIVE = TPCANStatus(0x40000) # Bus error: the CAN controller is error passive 130 | PCAN_ERROR_BUSOFF = TPCANStatus(0x00010) # Bus error: the CAN controller is in bus-off state 131 | PCAN_ERROR_ANYBUSERR = TPCANStatus(PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE) # Mask for all bus errors 132 | PCAN_ERROR_QRCVEMPTY = TPCANStatus(0x00020) # Receive queue is empty 133 | PCAN_ERROR_QOVERRUN = TPCANStatus(0x00040) # Receive queue was read too late 134 | PCAN_ERROR_QXMTFULL = TPCANStatus(0x00080) # Transmit queue is full 135 | PCAN_ERROR_REGTEST = TPCANStatus(0x00100) # Test of the CAN controller hardware registers failed (no hardware found) 136 | PCAN_ERROR_NODRIVER = TPCANStatus(0x00200) # Driver not loaded 137 | PCAN_ERROR_HWINUSE = TPCANStatus(0x00400) # Hardware already in use by a Net 138 | PCAN_ERROR_NETINUSE = TPCANStatus(0x00800) # A Client is already connected to the Net 139 | PCAN_ERROR_ILLHW = TPCANStatus(0x01400) # Hardware handle is invalid 140 | PCAN_ERROR_ILLNET = TPCANStatus(0x01800) # Net handle is invalid 141 | PCAN_ERROR_ILLCLIENT = TPCANStatus(0x01C00) # Client handle is invalid 142 | PCAN_ERROR_ILLHANDLE = TPCANStatus(PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) # Mask for all handle errors 143 | PCAN_ERROR_RESOURCE = TPCANStatus(0x02000) # Resource (FIFO, Client, timeout) cannot be created 144 | PCAN_ERROR_ILLPARAMTYPE = TPCANStatus(0x04000) # Invalid parameter 145 | PCAN_ERROR_ILLPARAMVAL = TPCANStatus(0x08000) # Invalid parameter value 146 | PCAN_ERROR_UNKNOWN = TPCANStatus(0x10000) # Unknown error 147 | PCAN_ERROR_ILLDATA = TPCANStatus(0x20000) # Invalid data, function, or action 148 | PCAN_ERROR_ILLMODE = TPCANStatus(0x80000) # Driver object state is wrong for the attempted operation 149 | PCAN_ERROR_CAUTION = TPCANStatus(0x2000000)# An operation was successfully carried out, however, irregularities were registered 150 | PCAN_ERROR_INITIALIZE = TPCANStatus(0x4000000)# Channel is not initialized [Value was changed from 0x40000 to 0x4000000] 151 | PCAN_ERROR_ILLOPERATION = TPCANStatus(0x8000000)# Invalid operation [Value was changed from 0x80000 to 0x8000000] 152 | 153 | # PCAN devices 154 | # 155 | PCAN_NONE = TPCANDevice(0x00) # Undefined, unknown or not selected PCAN device value 156 | PCAN_PEAKCAN = TPCANDevice(0x01) # PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API 157 | PCAN_ISA = TPCANDevice(0x02) # PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus 158 | PCAN_DNG = TPCANDevice(0x03) # PCAN-Dongle 159 | PCAN_PCI = TPCANDevice(0x04) # PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express 160 | PCAN_USB = TPCANDevice(0x05) # PCAN-USB and PCAN-USB Pro 161 | PCAN_PCC = TPCANDevice(0x06) # PCAN-PC Card 162 | PCAN_VIRTUAL = TPCANDevice(0x07) # PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API 163 | PCAN_LAN = TPCANDevice(0x08) # PCAN Gateway devices 164 | 165 | # PCAN parameters 166 | # 167 | PCAN_DEVICE_ID = TPCANParameter(0x01) # Device identifier parameter 168 | PCAN_5VOLTS_POWER = TPCANParameter(0x02) # 5-Volt power parameter 169 | PCAN_RECEIVE_EVENT = TPCANParameter(0x03) # PCAN receive event handler parameter 170 | PCAN_MESSAGE_FILTER = TPCANParameter(0x04) # PCAN message filter parameter 171 | PCAN_API_VERSION = TPCANParameter(0x05) # PCAN-Basic API version parameter 172 | PCAN_CHANNEL_VERSION = TPCANParameter(0x06) # PCAN device channel version parameter 173 | PCAN_BUSOFF_AUTORESET = TPCANParameter(0x07) # PCAN Reset-On-Busoff parameter 174 | PCAN_LISTEN_ONLY = TPCANParameter(0x08) # PCAN Listen-Only parameter 175 | PCAN_LOG_LOCATION = TPCANParameter(0x09) # Directory path for log files 176 | PCAN_LOG_STATUS = TPCANParameter(0x0A) # Debug-Log activation status 177 | PCAN_LOG_CONFIGURE = TPCANParameter(0x0B) # Configuration of the debugged information (LOG_FUNCTION_***) 178 | PCAN_LOG_TEXT = TPCANParameter(0x0C) # Custom insertion of text into the log file 179 | PCAN_CHANNEL_CONDITION = TPCANParameter(0x0D) # Availability status of a PCAN-Channel 180 | PCAN_HARDWARE_NAME = TPCANParameter(0x0E) # PCAN hardware name parameter 181 | PCAN_RECEIVE_STATUS = TPCANParameter(0x0F) # Message reception status of a PCAN-Channel 182 | PCAN_CONTROLLER_NUMBER = TPCANParameter(0x10) # CAN-Controller number of a PCAN-Channel 183 | PCAN_TRACE_LOCATION = TPCANParameter(0x11) # Directory path for PCAN trace files 184 | PCAN_TRACE_STATUS = TPCANParameter(0x12) # CAN tracing activation status 185 | PCAN_TRACE_SIZE = TPCANParameter(0x13) # Configuration of the maximum file size of a CAN trace 186 | PCAN_TRACE_CONFIGURE = TPCANParameter(0x14) # Configuration of the trace file storing mode (TRACE_FILE_***) 187 | PCAN_CHANNEL_IDENTIFYING = TPCANParameter(0x15) # Physical identification of a USB based PCAN-Channel by blinking its associated LED 188 | PCAN_CHANNEL_FEATURES = TPCANParameter(0x16) # Capabilities of a PCAN device (FEATURE_***) 189 | PCAN_BITRATE_ADAPTING = TPCANParameter(0x17) # Using of an existing bit rate (PCAN-View connected to a channel) 190 | PCAN_BITRATE_INFO = TPCANParameter(0x18) # Configured bit rate as Btr0Btr1 value 191 | PCAN_BITRATE_INFO_FD = TPCANParameter(0x19) # Configured bit rate as TPCANBitrateFD string 192 | PCAN_BUSSPEED_NOMINAL = TPCANParameter(0x1A) # Configured nominal CAN Bus speed as Bits per seconds 193 | PCAN_BUSSPEED_DATA = TPCANParameter(0x1B) # Configured CAN data speed as Bits per seconds 194 | PCAN_IP_ADDRESS = TPCANParameter(0x1C) # Remote address of a LAN channel as string in IPv4 format 195 | PCAN_LAN_SERVICE_STATUS = TPCANParameter(0x1D) # Status of the Virtual PCAN-Gateway Service 196 | PCAN_ALLOW_STATUS_FRAMES = TPCANParameter(0x1E) # Status messages reception status within a PCAN-Channel 197 | PCAN_ALLOW_RTR_FRAMES = TPCANParameter(0x1F) # RTR messages reception status within a PCAN-Channel 198 | PCAN_ALLOW_ERROR_FRAMES = TPCANParameter(0x20) # Error messages reception status within a PCAN-Channel 199 | PCAN_INTERFRAME_DELAY = TPCANParameter(0x21) # Delay, in microseconds, between sending frames 200 | PCAN_ACCEPTANCE_FILTER_11BIT = TPCANParameter(0x22) # Filter over code and mask patterns for 11-Bit messages 201 | PCAN_ACCEPTANCE_FILTER_29BIT = TPCANParameter(0x23) # Filter over code and mask patterns for 29-Bit messages 202 | PCAN_IO_DIGITAL_CONFIGURATION = TPCANParameter(0x24) # Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive 203 | PCAN_IO_DIGITAL_VALUE = TPCANParameter(0x25) # Value assigned to a 32 digital I/O pins of a PCAN-USB Chip 204 | PCAN_IO_DIGITAL_SET = TPCANParameter(0x26) # Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High 205 | PCAN_IO_DIGITAL_CLEAR = TPCANParameter(0x27) # Clear multiple digital I/O pins to 0 206 | PCAN_IO_ANALOG_VALUE = TPCANParameter(0x28) # Get value of a single analog input pin 207 | PCAN_FIRMWARE_VERSION = TPCANParameter(0x29) # Get the version of the firmware used by the device associated with a PCAN-Channel 208 | PCAN_ATTACHED_CHANNELS_COUNT = TPCANParameter(0x2A) # Get the amount of PCAN channels attached to a system 209 | PCAN_ATTACHED_CHANNELS = TPCANParameter(0x2B) # Get information about PCAN channels attached to a system 210 | PCAN_ALLOW_ECHO_FRAMES = TPCANParameter(0x2C) # Echo messages reception status within a PCAN-Channel 211 | PCAN_DEVICE_PART_NUMBER = TPCANParameter(0x2D) # Get the part number associated to a device 212 | PCAN_HARD_RESET_STATUS = TPCANParameter(0x2E) # Activation status of hard reset processing via PCANBasic.Reset calls 213 | 214 | # DEPRECATED parameters 215 | # 216 | PCAN_DEVICE_NUMBER = PCAN_DEVICE_ID # DEPRECATED. Use PCAN_DEVICE_ID instead 217 | 218 | # PCAN parameter values 219 | # 220 | PCAN_PARAMETER_OFF = int(0x00) # The PCAN parameter is not set (inactive) 221 | PCAN_PARAMETER_ON = int(0x01) # The PCAN parameter is set (active) 222 | PCAN_FILTER_CLOSE = int(0x00) # The PCAN filter is closed. No messages will be received 223 | PCAN_FILTER_OPEN = int(0x01) # The PCAN filter is fully opened. All messages will be received 224 | PCAN_FILTER_CUSTOM = int(0x02) # The PCAN filter is custom configured. Only registered messages will be received 225 | PCAN_CHANNEL_UNAVAILABLE = int(0x00) # The PCAN-Channel handle is illegal, or its associated hardware is not available 226 | PCAN_CHANNEL_AVAILABLE = int(0x01) # The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in) 227 | PCAN_CHANNEL_OCCUPIED = int(0x02) # The PCAN-Channel handle is valid, and is already being used 228 | PCAN_CHANNEL_PCANVIEW = PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED # The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect 229 | 230 | LOG_FUNCTION_DEFAULT = int(0x00) # Logs system exceptions / errors 231 | LOG_FUNCTION_ENTRY = int(0x01) # Logs the entries to the PCAN-Basic API functions 232 | LOG_FUNCTION_PARAMETERS = int(0x02) # Logs the parameters passed to the PCAN-Basic API functions 233 | LOG_FUNCTION_LEAVE = int(0x04) # Logs the exits from the PCAN-Basic API functions 234 | LOG_FUNCTION_WRITE = int(0x08) # Logs the CAN messages passed to the CAN_Write function 235 | LOG_FUNCTION_READ = int(0x10) # Logs the CAN messages received within the CAN_Read function 236 | LOG_FUNCTION_ALL = int(0xFFFF) # Logs all possible information within the PCAN-Basic API functions 237 | 238 | TRACE_FILE_SINGLE = int(0x00) # A single file is written until it size reaches PAN_TRACE_SIZE 239 | TRACE_FILE_SEGMENTED = int(0x01) # Traced data is distributed in several files with size PAN_TRACE_SIZE 240 | TRACE_FILE_DATE = int(0x02) # Includes the date into the name of the trace file 241 | TRACE_FILE_TIME = int(0x04) # Includes the start time into the name of the trace file 242 | TRACE_FILE_OVERWRITE = int(0x80) # Causes the overwriting of available traces (same name) 243 | TRACE_FILE_DATA_LENGTH = int(0x100) # Causes using the data length column ('l') instead of the DLC column ('L') in the trace file 244 | 245 | FEATURE_FD_CAPABLE = int(0x01) # Device supports flexible data-rate (CAN-FD) 246 | FEATURE_DELAY_CAPABLE = int(0x02) # Device supports a delay between sending frames (FPGA based USB devices) 247 | FEATURE_IO_CAPABLE = int(0x04) # Device supports I/O functionality for electronic circuits (USB-Chip devices) 248 | 249 | SERVICE_STATUS_STOPPED = int(0x01) # The service is not running 250 | SERVICE_STATUS_RUNNING = int(0x04) # The service is running 251 | 252 | # Other constants 253 | # 254 | MAX_LENGTH_HARDWARE_NAME = int(33) # Maximum length of the name of a device: 32 characters + terminator 255 | MAX_LENGTH_VERSION_STRING = int(256) # Maximum length of a version string: 255 characters + terminator 256 | 257 | # PCAN message types 258 | # 259 | PCAN_MESSAGE_STANDARD = TPCANMessageType(0x00) # The PCAN message is a CAN Standard Frame (11-bit identifier) 260 | PCAN_MESSAGE_RTR = TPCANMessageType(0x01) # The PCAN message is a CAN Remote-Transfer-Request Frame 261 | PCAN_MESSAGE_EXTENDED = TPCANMessageType(0x02) # The PCAN message is a CAN Extended Frame (29-bit identifier) 262 | PCAN_MESSAGE_FD = TPCANMessageType(0x04) # The PCAN message represents a FD frame in terms of CiA Specs 263 | PCAN_MESSAGE_BRS = TPCANMessageType(0x08) # The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate) 264 | PCAN_MESSAGE_ESI = TPCANMessageType(0x10) # The PCAN message represents a FD error state indicator(CAN FD transmitter was error active) 265 | PCAN_MESSAGE_ECHO = TPCANMessageType(0x20) # The PCAN message represents an echo CAN Frame 266 | PCAN_MESSAGE_ERRFRAME = TPCANMessageType(0x40) # The PCAN message represents an error frame 267 | PCAN_MESSAGE_STATUS = TPCANMessageType(0x80) # The PCAN message represents a PCAN status message 268 | 269 | # LookUp Parameters 270 | # 271 | LOOKUP_DEVICE_TYPE = b"devicetype" # Lookup channel by Device type (see PCAN devices e.g. PCAN_USB) 272 | LOOKUP_DEVICE_ID = b"deviceid" # Lookup channel by device id 273 | LOOKUP_CONTROLLER_NUMBER = b"controllernumber" # Lookup channel by CAN controller 0-based index 274 | LOOKUP_IP_ADDRESS = b"ipaddress" # Lookup channel by IP address (LAN channels only) 275 | 276 | # Frame Type / Initialization Mode 277 | # 278 | PCAN_MODE_STANDARD = PCAN_MESSAGE_STANDARD 279 | PCAN_MODE_EXTENDED = PCAN_MESSAGE_EXTENDED 280 | 281 | # Baud rate codes = BTR0/BTR1 register values for the CAN controller. 282 | # You can define your own Baud rate with the BTROBTR1 register. 283 | # Take a look at www.peak-system.com for our free software "BAUDTOOL" 284 | # to calculate the BTROBTR1 register for every bit rate and sample point. 285 | # 286 | PCAN_BAUD_1M = TPCANBaudrate(0x0014) # 1 MBit/s 287 | PCAN_BAUD_800K = TPCANBaudrate(0x0016) # 800 kBit/s 288 | PCAN_BAUD_500K = TPCANBaudrate(0x001C) # 500 kBit/s 289 | PCAN_BAUD_250K = TPCANBaudrate(0x011C) # 250 kBit/s 290 | PCAN_BAUD_125K = TPCANBaudrate(0x031C) # 125 kBit/s 291 | PCAN_BAUD_100K = TPCANBaudrate(0x432F) # 100 kBit/s 292 | PCAN_BAUD_95K = TPCANBaudrate(0xC34E) # 95,238 kBit/s 293 | PCAN_BAUD_83K = TPCANBaudrate(0x852B) # 83,333 kBit/s 294 | PCAN_BAUD_50K = TPCANBaudrate(0x472F) # 50 kBit/s 295 | PCAN_BAUD_47K = TPCANBaudrate(0x1414) # 47,619 kBit/s 296 | PCAN_BAUD_33K = TPCANBaudrate(0x8B2F) # 33,333 kBit/s 297 | PCAN_BAUD_20K = TPCANBaudrate(0x532F) # 20 kBit/s 298 | PCAN_BAUD_10K = TPCANBaudrate(0x672F) # 10 kBit/s 299 | PCAN_BAUD_5K = TPCANBaudrate(0x7F7F) # 5 kBit/s 300 | 301 | # Represents the configuration for a CAN bit rate 302 | # Note: 303 | # * Each parameter and its value must be separated with a '='. 304 | # * Each pair of parameter/value must be separated using ','. 305 | # 306 | # Example: 307 | # f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1 308 | # 309 | PCAN_BR_CLOCK = TPCANBitrateFD(b"f_clock") 310 | PCAN_BR_CLOCK_MHZ = TPCANBitrateFD(b"f_clock_mhz") 311 | PCAN_BR_NOM_BRP = TPCANBitrateFD(b"nom_brp") 312 | PCAN_BR_NOM_TSEG1 = TPCANBitrateFD(b"nom_tseg1") 313 | PCAN_BR_NOM_TSEG2 = TPCANBitrateFD(b"nom_tseg2") 314 | PCAN_BR_NOM_SJW = TPCANBitrateFD(b"nom_sjw") 315 | PCAN_BR_NOM_SAMPLE = TPCANBitrateFD(b"nom_sam") 316 | PCAN_BR_DATA_BRP = TPCANBitrateFD(b"data_brp") 317 | PCAN_BR_DATA_TSEG1 = TPCANBitrateFD(b"data_tseg1") 318 | PCAN_BR_DATA_TSEG2 = TPCANBitrateFD(b"data_tseg2") 319 | PCAN_BR_DATA_SJW = TPCANBitrateFD(b"data_sjw") 320 | PCAN_BR_DATA_SAMPLE = TPCANBitrateFD(b"data_ssp_offset") 321 | 322 | # Supported Non-PnP Hardware types 323 | # 324 | PCAN_TYPE_ISA = TPCANType(0x01) # PCAN-ISA 82C200 325 | PCAN_TYPE_ISA_SJA = TPCANType(0x09) # PCAN-ISA SJA1000 326 | PCAN_TYPE_ISA_PHYTEC = TPCANType(0x04) # PHYTEC ISA 327 | PCAN_TYPE_DNG = TPCANType(0x02) # PCAN-Dongle 82C200 328 | PCAN_TYPE_DNG_EPP = TPCANType(0x03) # PCAN-Dongle EPP 82C200 329 | PCAN_TYPE_DNG_SJA = TPCANType(0x05) # PCAN-Dongle SJA1000 330 | PCAN_TYPE_DNG_SJA_EPP = TPCANType(0x06) # PCAN-Dongle EPP SJA1000 331 | 332 | # Represents a PCAN message 333 | # 334 | class TPCANMsg (Structure): 335 | """ 336 | Represents a PCAN message 337 | """ 338 | _fields_ = [ ("ID", c_uint), # 11/29-bit message identifier 339 | ("MSGTYPE", TPCANMessageType), # Type of the message 340 | ("LEN", c_ubyte), # Data Length Code of the message (0..8) 341 | ("DATA", c_ubyte * 8) ] # Data of the message (DATA[0]..DATA[7]) 342 | 343 | # Represents a timestamp of a received PCAN message 344 | # Total Microseconds = micros + (1000 * millis) + (0x100000000 * 1000 * millis_overflow) 345 | # 346 | class TPCANTimestamp (Structure): 347 | """ 348 | Represents a timestamp of a received PCAN message 349 | Total Microseconds = micros + (1000 * millis) + (0x100000000 * 1000 * millis_overflow) 350 | """ 351 | _fields_ = [ ("millis", c_uint), # Base-value: milliseconds: 0.. 2^32-1 352 | ("millis_overflow", c_ushort), # Roll-arounds of millis 353 | ("micros", c_ushort) ] # Microseconds: 0..999 354 | 355 | # Represents a PCAN message from a FD capable hardware 356 | # 357 | class TPCANMsgFD (Structure): 358 | """ 359 | Represents a PCAN message 360 | """ 361 | _fields_ = [ ("ID", c_uint), # 11/29-bit message identifier 362 | ("MSGTYPE", TPCANMessageType), # Type of the message 363 | ("DLC", c_ubyte), # Data Length Code of the message (0..15) 364 | ("DATA", c_ubyte * 64) ] # Data of the message (DATA[0]..DATA[63]) 365 | 366 | # Describes an available PCAN channel 367 | # 368 | class TPCANChannelInformation (Structure): 369 | """ 370 | Describes an available PCAN channel 371 | """ 372 | _fields_ = [ ("channel_handle", TPCANHandle), # PCAN channel handle 373 | ("device_type", TPCANDevice), # Kind of PCAN device 374 | ("controller_number", c_ubyte), # CAN-Controller number 375 | ("device_features", c_uint), # Device capabilities flag (see FEATURE_*) 376 | ("device_name", c_char * MAX_LENGTH_HARDWARE_NAME), # Device name 377 | ("device_id", c_uint), # Device number 378 | ("channel_condition", c_uint) ] # Availability status of a PCAN-Channel 379 | 380 | #/////////////////////////////////////////////////////////// 381 | # PCAN-Basic API function declarations 382 | #/////////////////////////////////////////////////////////// 383 | 384 | # PCAN-Basic API class implementation 385 | # 386 | class PCANBasic: 387 | """ 388 | PCAN-Basic API class implementation 389 | """ 390 | def __init__(self): 391 | # Loads the PCANBasic API 392 | # 393 | if platform.system() == 'Windows': 394 | # Loads the API on Windows 395 | self.__m_dllBasic = windll.LoadLibrary("PCANBasic") 396 | elif platform.system() == 'Linux': 397 | # Loads the API on Linux 398 | self.__m_dllBasic = cdll.LoadLibrary("libpcanbasic.so") 399 | elif platform.system() == 'Darwin': 400 | # Loads the API on Mac 401 | # 402 | # NOTE: 403 | # ~~~~~ 404 | # The macOS library for PCAN-USB interfaces from PEAK-System, PCBUSB library, 405 | # is a third-party software creaded and mantained by the MacCAN project. For 406 | # information and support, please contact MacCAN (info@mac-can). 407 | # 408 | self.__m_dllBasic = cdll.LoadLibrary(find_library("libPCBUSB.dylib")) 409 | 410 | if self.__m_dllBasic == None: 411 | print ("Exception: The PCAN-Basic DLL couldn't be loaded!") 412 | 413 | # Initializes a PCAN Channel 414 | # 415 | def Initialize( 416 | self, 417 | Channel, 418 | Btr0Btr1, 419 | HwType = TPCANType(0), 420 | IOPort = c_uint(0), 421 | Interrupt = c_ushort(0)): 422 | 423 | """ 424 | Initializes a PCAN Channel 425 | 426 | Parameters: 427 | Channel : A TPCANHandle representing a PCAN Channel 428 | Btr0Btr1 : The speed for the communication (BTR0BTR1 code) 429 | HwType : Non-PnP: The type of hardware and operation mode 430 | IOPort : Non-PnP: The I/O address for the parallel port 431 | Interrupt: Non-PnP: Interrupt number of the parallel port 432 | 433 | Returns: 434 | A TPCANStatus error code 435 | """ 436 | try: 437 | res = self.__m_dllBasic.CAN_Initialize(Channel,Btr0Btr1,HwType,IOPort,Interrupt) 438 | return TPCANStatus(res) 439 | except: 440 | print ("Exception on PCANBasic.Initialize") 441 | raise 442 | 443 | # Initializes a FD capable PCAN Channel 444 | # 445 | def InitializeFD( 446 | self, 447 | Channel, 448 | BitrateFD): 449 | 450 | """ 451 | Initializes a FD capable PCAN Channel 452 | 453 | Parameters: 454 | Channel : The handle of a FD capable PCAN Channel 455 | BitrateFD : The speed for the communication (FD bit rate string) 456 | 457 | Remarks: 458 | See PCAN_BR_* values. 459 | * parameter and values must be separated by '=' 460 | * Couples of Parameter/value must be separated by ',' 461 | * Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2, 462 | nom_brp, nom_sjw, nom_tseg1, nom_tseg2. 463 | * Following Parameters are optional (not used yet): data_ssp_offset, nom_sam 464 | 465 | Example: 466 | f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1 467 | 468 | Returns: 469 | A TPCANStatus error code 470 | """ 471 | try: 472 | res = self.__m_dllBasic.CAN_InitializeFD(Channel,BitrateFD) 473 | return TPCANStatus(res) 474 | except: 475 | print ("Exception on PCANBasic.InitializeFD") 476 | raise 477 | 478 | # Uninitializes one or all PCAN Channels initialized by CAN_Initialize 479 | # 480 | def Uninitialize( 481 | self, 482 | Channel): 483 | 484 | """ 485 | Uninitializes one or all PCAN Channels initialized by CAN_Initialize 486 | 487 | Remarks: 488 | Giving the TPCANHandle value "PCAN_NONEBUS", uninitialize all initialized channels 489 | 490 | Parameters: 491 | Channel : A TPCANHandle representing a PCAN Channel 492 | 493 | Returns: 494 | A TPCANStatus error code 495 | """ 496 | try: 497 | res = self.__m_dllBasic.CAN_Uninitialize(Channel) 498 | return TPCANStatus(res) 499 | except: 500 | print ("Exception on PCANBasic.Uninitialize") 501 | raise 502 | 503 | # Resets the receive and transmit queues of the PCAN Channel 504 | # 505 | def Reset( 506 | self, 507 | Channel): 508 | 509 | """ 510 | Resets the receive and transmit queues of the PCAN Channel 511 | 512 | Remarks: 513 | A reset of the CAN controller is not performed 514 | 515 | Parameters: 516 | Channel : A TPCANHandle representing a PCAN Channel 517 | 518 | Returns: 519 | A TPCANStatus error code 520 | """ 521 | try: 522 | res = self.__m_dllBasic.CAN_Reset(Channel) 523 | return TPCANStatus(res) 524 | except: 525 | print ("Exception on PCANBasic.Reset") 526 | raise 527 | 528 | # Gets the current status of a PCAN Channel 529 | # 530 | def GetStatus( 531 | self, 532 | Channel): 533 | 534 | """ 535 | Gets the current status of a PCAN Channel 536 | 537 | Parameters: 538 | Channel : A TPCANHandle representing a PCAN Channel 539 | 540 | Returns: 541 | A TPCANStatus error code 542 | """ 543 | try: 544 | res = self.__m_dllBasic.CAN_GetStatus(Channel) 545 | return TPCANStatus(res) 546 | except: 547 | print ("Exception on PCANBasic.GetStatus") 548 | raise 549 | 550 | # Reads a CAN message from the receive queue of a PCAN Channel 551 | # 552 | def Read( 553 | self, 554 | Channel): 555 | 556 | """ 557 | Reads a CAN message from the receive queue of a PCAN Channel 558 | 559 | Remarks: 560 | The return value of this method is a 3-touple, where 561 | the first value is the result (TPCANStatus) of the method. 562 | The order of the values are: 563 | [0]: A TPCANStatus error code 564 | [1]: A TPCANMsg structure with the CAN message read 565 | [2]: A TPCANTimestamp structure with the time when a message was read 566 | 567 | Parameters: 568 | Channel : A TPCANHandle representing a PCAN Channel 569 | 570 | Returns: 571 | A touple with three values 572 | """ 573 | try: 574 | msg = TPCANMsg() 575 | timestamp = TPCANTimestamp() 576 | res = self.__m_dllBasic.CAN_Read(Channel,byref(msg),byref(timestamp)) 577 | return TPCANStatus(res),msg,timestamp 578 | except: 579 | print ("Exception on PCANBasic.Read") 580 | raise 581 | 582 | # Reads a CAN message from the receive queue of a FD capable PCAN Channel 583 | # 584 | def ReadFD( 585 | self, 586 | Channel): 587 | 588 | """ 589 | Reads a CAN message from the receive queue of a FD capable PCAN Channel 590 | 591 | Remarks: 592 | The return value of this method is a 3-touple, where 593 | the first value is the result (TPCANStatus) of the method. 594 | The order of the values are: 595 | [0]: A TPCANStatus error code 596 | [1]: A TPCANMsgFD structure with the CAN message read 597 | [2]: A TPCANTimestampFD that is the time when a message was read 598 | 599 | Parameters: 600 | Channel : The handle of a FD capable PCAN Channel 601 | 602 | Returns: 603 | A touple with three values 604 | """ 605 | try: 606 | msg = TPCANMsgFD() 607 | timestamp = TPCANTimestampFD() 608 | res = self.__m_dllBasic.CAN_ReadFD(Channel,byref(msg),byref(timestamp)) 609 | return TPCANStatus(res),msg,timestamp 610 | except: 611 | print ("Exception on PCANBasic.ReadFD") 612 | raise 613 | 614 | # Transmits a CAN message 615 | # 616 | def Write( 617 | self, 618 | Channel, 619 | MessageBuffer): 620 | 621 | """ 622 | Transmits a CAN message 623 | 624 | Parameters: 625 | Channel : A TPCANHandle representing a PCAN Channel 626 | MessageBuffer: A TPCANMsg representing the CAN message to be sent 627 | 628 | Returns: 629 | A TPCANStatus error code 630 | """ 631 | try: 632 | res = self.__m_dllBasic.CAN_Write(Channel,byref(MessageBuffer)) 633 | return TPCANStatus(res) 634 | except: 635 | print ("Exception on PCANBasic.Write") 636 | raise 637 | 638 | # Transmits a CAN message over a FD capable PCAN Channel 639 | # 640 | def WriteFD( 641 | self, 642 | Channel, 643 | MessageBuffer): 644 | 645 | """ 646 | Transmits a CAN message over a FD capable PCAN Channel 647 | 648 | Parameters: 649 | Channel : The handle of a FD capable PCAN Channel 650 | MessageBuffer: A TPCANMsgFD buffer with the message to be sent 651 | 652 | Returns: 653 | A TPCANStatus error code 654 | """ 655 | try: 656 | res = self.__m_dllBasic.CAN_WriteFD(Channel,byref(MessageBuffer)) 657 | return TPCANStatus(res) 658 | except: 659 | print ("Exception on PCANBasic.WriteFD") 660 | raise 661 | 662 | # Configures the reception filter 663 | # 664 | def FilterMessages( 665 | self, 666 | Channel, 667 | FromID, 668 | ToID, 669 | Mode): 670 | 671 | """ 672 | Configures the reception filter 673 | 674 | Remarks: 675 | The message filter will be expanded with every call to this function. 676 | If it is desired to reset the filter, please use the 'SetValue' function. 677 | 678 | Parameters: 679 | Channel : A TPCANHandle representing a PCAN Channel 680 | FromID : A c_uint value with the lowest CAN ID to be received 681 | ToID : A c_uint value with the highest CAN ID to be received 682 | Mode : A TPCANMode representing the message type (Standard, 11-bit 683 | identifier, or Extended, 29-bit identifier) 684 | 685 | Returns: 686 | A TPCANStatus error code 687 | """ 688 | try: 689 | res = self.__m_dllBasic.CAN_FilterMessages(Channel,FromID,ToID,Mode) 690 | return TPCANStatus(res) 691 | except: 692 | print ("Exception on PCANBasic.FilterMessages") 693 | raise 694 | 695 | # Retrieves a PCAN Channel value 696 | # 697 | def GetValue( 698 | self, 699 | Channel, 700 | Parameter): 701 | 702 | """ 703 | Retrieves a PCAN Channel value 704 | 705 | Remarks: 706 | Parameters can be present or not according with the kind 707 | of Hardware (PCAN Channel) being used. If a parameter is not available, 708 | a PCAN_ERROR_ILLPARAMTYPE error will be returned. 709 | 710 | The return value of this method is a 2-touple, where 711 | the first value is the result (TPCANStatus) of the method and 712 | the second one, the asked value 713 | 714 | Parameters: 715 | Channel : A TPCANHandle representing a PCAN Channel 716 | Parameter : The TPCANParameter parameter to get 717 | 718 | Returns: 719 | A touple with 2 values 720 | """ 721 | try: 722 | if Parameter == PCAN_API_VERSION or Parameter == PCAN_HARDWARE_NAME or Parameter == PCAN_CHANNEL_VERSION or Parameter == PCAN_LOG_LOCATION or Parameter == PCAN_TRACE_LOCATION or Parameter == PCAN_BITRATE_INFO_FD or Parameter == PCAN_IP_ADDRESS or Parameter == PCAN_FIRMWARE_VERSION or Parameter == PCAN_DEVICE_PART_NUMBER: 723 | mybuffer = create_string_buffer(256) 724 | 725 | elif Parameter == PCAN_ATTACHED_CHANNELS: 726 | res = self.GetValue(Channel, PCAN_ATTACHED_CHANNELS_COUNT) 727 | if TPCANStatus(res[0]) != PCAN_ERROR_OK: 728 | return TPCANStatus(res[0]), 729 | mybuffer = (TPCANChannelInformation * res[1])() 730 | 731 | elif Parameter == PCAN_ACCEPTANCE_FILTER_11BIT or Parameter == PCAN_ACCEPTANCE_FILTER_29BIT: 732 | mybuffer = c_int64(0) 733 | 734 | else: 735 | mybuffer = c_int(0) 736 | 737 | res = self.__m_dllBasic.CAN_GetValue(Channel,Parameter,byref(mybuffer),sizeof(mybuffer)) 738 | if Parameter == PCAN_ATTACHED_CHANNELS: 739 | return TPCANStatus(res),mybuffer 740 | else: 741 | return TPCANStatus(res),mybuffer.value 742 | except: 743 | print ("Exception on PCANBasic.GetValue") 744 | raise 745 | 746 | # Returns a descriptive text of a given TPCANStatus 747 | # error code, in any desired language 748 | # 749 | def SetValue( 750 | self, 751 | Channel, 752 | Parameter, 753 | Buffer): 754 | 755 | """ 756 | Configures or sets a PCAN Channel value 757 | 758 | Remarks: 759 | Parameters can be present or not according with the kind 760 | of Hardware (PCAN Channel) being used. If a parameter is not available, 761 | a PCAN_ERROR_ILLPARAMTYPE error will be returned. 762 | 763 | Parameters: 764 | Channel : A TPCANHandle representing a PCAN Channel 765 | Parameter : The TPCANParameter parameter to set 766 | Buffer : Buffer with the value to be set 767 | BufferLength : Size in bytes of the buffer 768 | 769 | Returns: 770 | A TPCANStatus error code 771 | """ 772 | try: 773 | if Parameter == PCAN_LOG_LOCATION or Parameter == PCAN_LOG_TEXT or Parameter == PCAN_TRACE_LOCATION: 774 | mybuffer = create_string_buffer(256) 775 | elif Parameter == PCAN_ACCEPTANCE_FILTER_11BIT or Parameter == PCAN_ACCEPTANCE_FILTER_29BIT: 776 | mybuffer = c_int64(0) 777 | else: 778 | mybuffer = c_int(0) 779 | 780 | mybuffer.value = Buffer 781 | res = self.__m_dllBasic.CAN_SetValue(Channel,Parameter,byref(mybuffer),sizeof(mybuffer)) 782 | return TPCANStatus(res) 783 | except: 784 | print ("Exception on PCANBasic.SetValue") 785 | raise 786 | 787 | def GetErrorText( 788 | self, 789 | Error, 790 | Language = 0): 791 | 792 | """ 793 | Returns a descriptive text of a given TPCANStatus error 794 | code, in any desired language 795 | 796 | Remarks: 797 | 798 | The current languages available for translation are: 799 | Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), 800 | Italian (0x10) and French (0x0C) 801 | 802 | The return value of this method is a 2-touple, where 803 | the first value is the result (TPCANStatus) of the method and 804 | the second one, the error text 805 | 806 | Parameters: 807 | Error : A TPCANStatus error code 808 | Language : Indicates a 'Primary language ID' (Default is Neutral(0)) 809 | 810 | Returns: 811 | A touple with 2 values 812 | """ 813 | try: 814 | mybuffer = create_string_buffer(256) 815 | res = self.__m_dllBasic.CAN_GetErrorText(Error,Language,byref(mybuffer)) 816 | return TPCANStatus(res),mybuffer.value 817 | except: 818 | print ("Exception on PCANBasic.GetErrorText") 819 | raise 820 | 821 | def LookUpChannel( 822 | self, 823 | Parameters): 824 | 825 | """ 826 | Finds a PCAN-Basic channel that matches with the given parameters 827 | 828 | Remarks: 829 | 830 | The return value of this method is a 2-touple, where 831 | the first value is the result (TPCANStatus) of the method and 832 | the second one a TPCANHandle value 833 | 834 | Parameters: 835 | Parameters : A comma separated string contained pairs of parameter-name/value 836 | to be matched within a PCAN-Basic channel 837 | 838 | Returns: 839 | A touple with 2 values 840 | """ 841 | try: 842 | mybuffer = TPCANHandle(0) 843 | res = self.__m_dllBasic.CAN_LookUpChannel(Parameters,byref(mybuffer)) 844 | return TPCANStatus(res),mybuffer 845 | except: 846 | print ("Exception on PCANBasic.LookUpChannel") 847 | raise 848 | -------------------------------------------------------------------------------- /Examples/Python/pcbusb_recv.py: -------------------------------------------------------------------------------- 1 | from PCANBasic import * ## PCAN-Basic library import 2 | 3 | import string ## String functions 4 | import time ## Time-related library 5 | import select ## Waiting for I/O completion 6 | import signal ## Set handlers for asynchronous events 7 | import sys ## System-specific parameters and functions 8 | 9 | 10 | def sigterm(signo, frame): 11 | result = PCANBasic().Uninitialize(PCAN_NONEBUS) 12 | if result != PCAN_ERROR_OK: 13 | print("Error: {}".format(PCANBasic().GetErrorText(result))) 14 | sys.exit(1) 15 | else: 16 | sys.exit(0) 17 | 18 | 19 | pcan = PCANBasic() 20 | channel = PCAN_USBBUS1 21 | baudrate = PCAN_BAUD_250K 22 | result = pcan.GetValue(channel,PCAN_CHANNEL_VERSION) 23 | if result[0] == PCAN_ERROR_OK: 24 | print(cast(result[1], c_char_p).value.decode("ascii")) 25 | 26 | result = pcan.Initialize(channel,baudrate) 27 | if result != PCAN_ERROR_OK: 28 | print("Error: {}".format(pcan.GetErrorText(result))) 29 | sys.exit(1) 30 | 31 | result = pcan.GetValue(channel,PCAN_RECEIVE_EVENT) 32 | if result[0] == PCAN_ERROR_OK: 33 | fd = result[1] 34 | else: 35 | fd = -1 36 | 37 | print("Press ^C to abort...") 38 | signal.signal(signal.SIGTERM, sigterm) 39 | signal.signal(signal.SIGINT, sigterm) 40 | 41 | while 1: 42 | result = pcan.Read(channel) 43 | if result[0] == PCAN_ERROR_OK: 44 | CANmsg = result[1] 45 | print("ID={:03X} LEN={:d} DATA=[{}]".format(CANmsg.ID,CANmsg.LEN,' '.join('{:02X}'.format(x) for x in CANmsg.DATA))) 46 | elif result[0] == PCAN_ERROR_QRCVEMPTY: 47 | if fd != -1: 48 | select.select([fd],[],[]) 49 | else: 50 | time.sleep(0.001) 51 | 52 | result = pcan.Uninitialize() 53 | if result != PCAN_ERROR_OK: 54 | print("Error: {}".format(pcan.GetErrorText(result))) 55 | sys.exit(1) 56 | else: 57 | sys.exit(0) 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | macOS Library for PCAN-USB Interfaces - Copyright (C) 2013-2024 by UV Software 2 | All rights reserved. 3 | 4 | 5 | END-USER LICENSE AGREEMENT FOR THIS SOFTWARE 6 | Important - read carefully! 7 | 8 | This End-User License Agreement ("EULA") is a legal agreement between 9 | you ("Licensee") and UV Software ("Licensor") for the software product 10 | identified above, which includes computer software and may include 11 | associated media, printed materials, and "online" or electronic 12 | documentation ("SOFTWARE PRODUCT"). By installing, copying, or otherwise 13 | using the SOFTWARE PRODUCT, you agree to be bound by the terms of this 14 | EULA. If you do not agree to the terms of this EULA, do not install or 15 | use the SOFTWARE PRODUCT. 16 | 17 | 18 | SOFTWARE PRODUCT LICENSE 19 | 20 | The SOFTWARE PRODUCT is licensed, not sold. 21 | 22 | The definition of SOFTWARE PRODUCT includes any files generated by the 23 | SOFTWARE PRODUCT. 24 | 25 | 26 | 1. GRANT OF LICENSE 27 | 28 | This EULA grants you the following rights: 29 | 30 | Installation and Use: You may install and use an unlimited number of 31 | copies of the SOFTWARE PRODUCT. 32 | 33 | Reproduction and Distribution: You may reproduce and distribute an 34 | unlimited number of copies of the SOFTWARE PRODUCT; provided that each 35 | copy shall be a true and complete copy, including all copyright and 36 | trademark notices, and shall be accompanied by a copy of this EULA. 37 | Copies of the SOFTWARE PRODUCT may be distributed as a standalone 38 | product or included with your own product. 39 | 40 | 41 | 2. DESCRIPTION OF OTHER RIGHTS AND LIMITATIONS 42 | 43 | Limitations on Reverse Engineering, Decompilation, and Disassembly: You 44 | may not reverse engineer, decompile or disassemble the SOFTWARE PRODUCT 45 | in any circumstances. 46 | 47 | Support Services: UV Software will not provide you with support services 48 | ("SUPPORT SERVICES") related to the SOFTWARE PRODUCT. 49 | 50 | Termination: Without prejudice to any other rights of UV Software, your 51 | rights under this EULA will terminate automatically without notice from 52 | UV Software if you fail to comply with any term(s) of this EULA. In such 53 | event you must destroy all copies of the SOFTWARE PRODUCT and any 54 | related materials. 55 | 56 | 57 | 3. LIMITED WARRANTY AND DISCLAIMER OF WARRANTY 58 | 59 | NO WARRANTIES: You expressly acknowledge and agree that use of the 60 | SOFTWARE PRODUCT is at your sole risk. The SOFTWARE PRODUCT is provided 61 | "AS IS" and without warranty of any kind. UV Software hereby EXPRESSLY 62 | DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED, 63 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF 64 | MERCHANTABILITY, NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. 65 | You are solely responsible for determining the appropriateness of using 66 | this SOFTWARE PRODUCT and assume all risks associated with the use of 67 | this SOFTWARE PRODUCT, including but not limited to the risks of program 68 | errors, damage to or loss of data, programs or equipment, and 69 | unavailability or interruption of operations. 70 | 71 | NO LIABILITY FOR DAMAGES: UNDER NO CIRCUMSTANCES, INCLUDING NEGLIGENCE, 72 | SHALL UV Software BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 73 | CONSEQUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS 74 | OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, 75 | OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF OR RELATING TO THIS LICENSE, 76 | EVEN IF UV Software HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 77 | In no event shall UV Software's total liability to you for all damages 78 | exceed the amount paid for this license to the SOFTWARE PRODUCT. The 79 | entire risk arising out of use or performance of the SOFTWARE PRODUCT 80 | remains with you. 81 | 82 | 83 | 4. COPYRIGHT 84 | 85 | All title and copyrights in and to the SOFTWARE PRODUCT (including but 86 | not limited to any images, photographs, animations, video, audio, music, 87 | text, and "applets" incorporated into the SOFTWARE PRODUCT), the 88 | accompanying printed materials, and any copies of the SOFTWARE PRODUCT 89 | are owned by UV Software. The SOFTWARE PRODUCT is protected by copyright 90 | laws and international treaty provisions. Therefore, you must treat the 91 | SOFTWARE PRODUCT like any other copyrighted material. 92 | 93 | 94 | 5. TRADEMARKS 95 | 96 | All product and company names mentioned in the SOFTWARE PRODUCT may be 97 | trademarks and/or service marks of their respective owners. 98 | 99 | 100 | 6. GOVERNING LAW 101 | 102 | This agreement shall be governed by the laws of Germany. 103 | 104 | 105 | 7. MISCELLANEOUS 106 | 107 | If for any reason a court of competent jurisdiction finds any provision, 108 | or portion of this EULA, to be unenforceable, the remainder of this EULA 109 | shall continue in full force and effect. This EULA constitutes the entire 110 | agreement between the parties with respect to the use of the SOFTWARE 111 | PRODUCT and supersedes all prior or contemporaneous understandings 112 | regarding such subject matter. No amendment to or modification of this 113 | EULA will be binding unless in writing and signed by UV Software. 114 | 115 | 116 | 117 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 118 | Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany 119 | Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 120 | E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### macOS® Library for PCAN-USB Interfaces 2 | 3 | *Copyright © 2013-2024 by UV Software, Berlin.*\ 4 | *All rights reserved.* 5 | 6 | # Running CAN and CAN FD on a Mac® 7 | 8 | The PCBUSB library realizes an USB to CAN user-space driver under macOS for PCAN-USB interfaces from PEAK-System Technik, Darmstadt. 9 | It supports up to 8 PCAN-USB or PCAN-USB FD devices. 10 | The library offers an easy to use API to read received CAN messages from a 64K message queue and to transmit CAN messages. 11 | Standard CAN frames (11-bit identifier) as well as extended CAN frames (29-bit identifier) are supported. 12 | The PCAN-USB FD device can be operated in CAN 2.0 and CAN FD mode. 13 | 14 | ## PCBUSB library 15 | 16 | The dynamic library libPCBUSB is running under macOS 10.13 and later (Intel architecture and Apple silicon). 17 | The API is almost compatible to PEAK´s PCANBasic DLL on Windows. 18 | See the [MacCAN](https://www.mac-can.com/) website for details. 19 | 20 | ### Target Platform 21 | 22 | - macOS 12.0 and later (Intel and Apple silicon) 23 | - OS X 10.13 and later (Intel architecture only) 24 | 25 | ### Development Environment 26 | 27 | #### macOS Sonoma 28 | 29 | - macOS Sonoma (14.5) on a Mac mini (M1, 2020) 30 | - Apple clang version 15.0.0 (clang-1500.3.9.4) 31 | - Xcode Version 15.4 (15F31d) 32 | 33 | #### macOS Monterey 34 | 35 | - macOS Monterey (12.7.5) on a MacBook Pro (2019) 36 | - Apple clang version 13.0.0 (clang-1300.0.29.30) 37 | - Xcode Version 13.2.1 (13C100) 38 | 39 | #### macOS High Sierra 40 | 41 | - macOS High Sierra (10.13.6) on a MacBook Pro (late 2011) 42 | - Apple LLVM version 10.0.0 (clang-1000.11.45.5) 43 | - Xcode Version 10.1 (10B61) 44 | 45 | ### Supported Devices 46 | 47 | Only the following devices from PEAK-System Technik are supported: 48 | - PCAN-USB (product code: IPEH-002021, IPEH-002022) 49 | 50 | Since version 0.8 (Build 689 of September 20, 2017): 51 | - PCAN-USB FD (product code: IPEH-004022) 52 | 53 | ### Known Bugs and Caveats 54 | 55 | For a list of known bugs and caveats see the README file delivered with each release 56 | and tab [Issues](https://github.com/mac-can/PCBUSB-Library/issues). 57 | 58 | ## This and That 59 | 60 | This repo contains only binaries files of the PCBUSB library. 61 | 62 | ### License 63 | 64 | The PCBUSB library is freeware without any warranty or support! 65 | 66 | Please note the copyright and license agreement. 67 | 68 | ### Trademarks 69 | 70 | Mac and macOS are trademarks of Apple Inc., registered in the U.S. and other countries. \ 71 | PCAN is a registered trademark of PEAK-System Technik GmbH, Darmstadt, Germany. \ 72 | All other company, product and service names mentioned herein may be trademarks, registered trademarks, or service marks of their respective owners. 73 | 74 | ### Hazard Note 75 | 76 | _If you connect your CAN device to a real CAN network when using this library, you might damage your application._ 77 | 78 | ### Contact 79 | 80 | E-Mail: mailto://info@mac.can.com \ 81 | Internet: https://www.mac-can.com 82 | --------------------------------------------------------------------------------