First time using codesys and CAN here. I can't seem to read anything off our CAN network. I know for certain that the baudrate and CAN-IDs are correct because I used PCAN View to verify they were correct. I'm using the CANAPI 1.0.0.2 library in codesys to read the CAN messages on a display.
Below I have snap shots of the driver configuration, code for receiving CAN messages, the implementation of ProcessMessage() method, and the driver29bit.ReceiveMessage() method. All snap shots were taken while connected to the device from a laptop. The communication port on the CAN hub is what I connected to with both the device and PCAN adapter so I know it isn't a wiring issue.
My code is based off the CANAPI example found at the codesys store. If I understand the process in the example correctly, the driver is configured, msgProcessor is configured with the driver, and then the singleID receiver is configured into the driver. The singleIDreceiver and msgProcessor are both passed to the ReceiveMessage() method in which the internal function processes the single CAN ID and passes the message to msgProcessor. From there, the CAN message should be passed to the internal variable "message" in msgProcessor, where I can then implement the message in the ProcessMessage() method.
What I've noticed is that ProcessMessage() is never called, I set a break point in there during the live test and the break point was never hit. I also have noticed that ReceiveMessage() returns "FALSE" every time. Could someone with more knowledge about CAN networks explain what I am doing wrong or what the problem is? I'm very green when it comes to CAN stuff.
List of things I have tried or noticed:
I've tried changing the usiNetwork from 0 - > 1 - > 2 and if I change the Network to 2 then the generated receiverIDs return '0' but 0 and 1 usiNetworks work for generating IDs.
I've tried changing the g_tTimeLimit anywhere from 0 to 100 and tried matching them to the cycle times of the CAN messages.
If you look at the ReceiveMessage picture below, you'll notice that the itfMsgProcessor has a value of "16#307FC25C". When checking for that value using PCAN View, that message is no where on the network. What does that mean?
My driver configurations and singleIDReceivers show "NO_ERROR".
I don't recall what else I have tried at the moment but if I remember I will come back and post them here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I decided to try out the CFC side of the CAN-API using an area receiver instead, since the CAN message addresses are pretty close. I still can't read anything off of the CAN and now the area receivers and driver configurations won't "configure". I'm getting Errors such as NO_CANBUSS_DRIVER, WRONG_BAUDRATE, and INVALID_DRIVER_HANDLE.
Between the way I have my drivers and receivers configured in ST and CFC, they are the exact same except ST is 29bitDriver (singleIDreceiver) and CFC is 11bitDriver (areaReceiver). The message coming over the CAN are 16#??? which means they are 11 bit so both 11bit and 29bit drivers should work.
The 29bitdrivers (ST) are able to generate singleIDreceiver handles but the 11bitDriver (CFC) is not able to generate the areaReceiver handle.
Below I have the pictures of how CFC is set up for the areaReceiver and a snapshot of the CANDriver_11bit's internal data. Under _CANBus in DriverConfig, the uiBaudrate, usiNetwork, and ctMessages are all set to "0" (Forgot to click down the list for the screen shot). I don't know how that is possible considering that I set-up driver configuration in my CFC.
I'm really at loss of what I'm doing wrong here...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
EDIT: My CAN-High/Low wires were backwards going into the hub. For anyone else who happens to come across this thread, the CAN-API example in the codesys store works and you can use the 29bitDrivers to receive 11 bit messages but you need to configure the singleIDConfig as shown below.
π
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, could you share your project code, because I need to work with the can bus. I have been trying to use the CAN API example but I have not been able to get the messages sent correctly. Thank you.
π
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi together,
I'm using a 11bit driver system which seems to work well so far.
May someone here knows if i have to configure a singleID for each message i like to receive and evaluate?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the example project, you can see that a CAN.CANAreaReceiver is used which has an VAR_IN_OUT reference to a RECEIVER_AREA structure. This structure has a dwIdStart and dwIdEnd to filter a range of ID's and process them through the referenced msgProcessor.
Last edit: TimvH 2023-09-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First time using codesys and CAN here. I can't seem to read anything off our CAN network. I know for certain that the baudrate and CAN-IDs are correct because I used PCAN View to verify they were correct. I'm using the CANAPI 1.0.0.2 library in codesys to read the CAN messages on a display.
Below I have snap shots of the driver configuration, code for receiving CAN messages, the implementation of ProcessMessage() method, and the driver29bit.ReceiveMessage() method. All snap shots were taken while connected to the device from a laptop. The communication port on the CAN hub is what I connected to with both the device and PCAN adapter so I know it isn't a wiring issue.
My code is based off the CANAPI example found at the codesys store. If I understand the process in the example correctly, the driver is configured, msgProcessor is configured with the driver, and then the singleID receiver is configured into the driver. The singleIDreceiver and msgProcessor are both passed to the ReceiveMessage() method in which the internal function processes the single CAN ID and passes the message to msgProcessor. From there, the CAN message should be passed to the internal variable "message" in msgProcessor, where I can then implement the message in the ProcessMessage() method.
What I've noticed is that ProcessMessage() is never called, I set a break point in there during the live test and the break point was never hit. I also have noticed that ReceiveMessage() returns "FALSE" every time. Could someone with more knowledge about CAN networks explain what I am doing wrong or what the problem is? I'm very green when it comes to CAN stuff.
List of things I have tried or noticed:
I've tried changing the usiNetwork from 0 - > 1 - > 2 and if I change the Network to 2 then the generated receiverIDs return '0' but 0 and 1 usiNetworks work for generating IDs.
I've tried changing the g_tTimeLimit anywhere from 0 to 100 and tried matching them to the cycle times of the CAN messages.
If you look at the ReceiveMessage picture below, you'll notice that the itfMsgProcessor has a value of "16#307FC25C". When checking for that value using PCAN View, that message is no where on the network. What does that mean?
My driver configurations and singleIDReceivers show "NO_ERROR".
I don't recall what else I have tried at the moment but if I remember I will come back and post them here.
more posts ...
I decided to try out the CFC side of the CAN-API using an area receiver instead, since the CAN message addresses are pretty close. I still can't read anything off of the CAN and now the area receivers and driver configurations won't "configure". I'm getting Errors such as NO_CANBUSS_DRIVER, WRONG_BAUDRATE, and INVALID_DRIVER_HANDLE.
Between the way I have my drivers and receivers configured in ST and CFC, they are the exact same except ST is 29bitDriver (singleIDreceiver) and CFC is 11bitDriver (areaReceiver). The message coming over the CAN are 16#??? which means they are 11 bit so both 11bit and 29bit drivers should work.
The 29bitdrivers (ST) are able to generate singleIDreceiver handles but the 11bitDriver (CFC) is not able to generate the areaReceiver handle.
Below I have the pictures of how CFC is set up for the areaReceiver and a snapshot of the CANDriver_11bit's internal data. Under _CANBus in DriverConfig, the uiBaudrate, usiNetwork, and ctMessages are all set to "0" (Forgot to click down the list for the screen shot). I don't know how that is possible considering that I set-up driver configuration in my CFC.
I'm really at loss of what I'm doing wrong here...
Why have your Images been deleted? May Could you setup a sharepoint again?
Nevermind, I fixed it.
EDIT: My CAN-High/Low wires were backwards going into the hub. For anyone else who happens to come across this thread, the CAN-API example in the codesys store works and you can use the 29bitDrivers to receive 11 bit messages but you need to configure the singleIDConfig as shown below.
Thanks
Hi, could you share your project code, because I need to work with the can bus. I have been trying to use the CAN API example but I have not been able to get the messages sent correctly. Thank you.
Hi together,
I'm using a 11bit driver system which seems to work well so far.
May someone here knows if i have to configure a singleID for each message i like to receive and evaluate?
In the example project, you can see that a CAN.CANAreaReceiver is used which has an VAR_IN_OUT reference to a RECEIVER_AREA structure. This structure has a dwIdStart and dwIdEnd to filter a range of ID's and process them through the referenced msgProcessor.
Last edit: TimvH 2023-09-19