How to read values from a Device which has CANOpen

Hi Drakku,

You can think of a “function block” as a function with multiple inputs and multiple outputs. After you set the inputs, you call the function block and the outputs update. Essentially, you’re passing a structure as the input to a function. The function uses some of the structure elements as inputs (does not modify them) and changes others (the outputs). The function block may also change something else on the system (i.e. send a CANopen message via the CANopen interface). So yes, changing the inputs to the function block will change how it works, but you want it to work off of the inputs you have. This example program should be modified to fit your use case and then it will run as-is. The sample includes a state machine so it will step through all of the steps necessary to read a message and then send a message. Of course, the sequence of steps can be modified if needed.

It sounds like you’re writing most of your project in C. Unfortunately, it looks like most of the samples for this library are only available in the Structured Text programming language. That’s okay though! You can mix and match (have both C and ST programs running at the same time). I would recommend first leaving everything in this program as-is for learning and testing purposes. Once you feel confident that you understand how you want to lay your program out, you can start copying (or recreating) the sample in a C program. There are some minor syntax differences between ST and C, so you can’t just copy and paste without making any edits.

Also another question is : in the FB , " CAN_L2.CANopenRegisterCOBID_0.cobid:= 16#182" What does 16#182 mean?
What if i needs to read the PDO1 at CAN ID 181h?

16# is the Structured Text notation for a hexadecimal value. So 16#182 just means a 182 value in hex format. If you need to read a value at 181, you would use 16#181.