Author Topic: CanOpen (REAL64) GNSS messages with C Code POU  (Read 12358 times)

Offline mfaber

  • PLUS+1 Novice
  • *
  • Posts: 4
  • Karma: +0/-0
CanOpen (REAL64) GNSS messages with C Code POU
« on: March 31, 2023, 12:13:07 AM »
Hi, all. I am trying to integrate a GNSS receiver with CanOpen interface to Plus1. The Latitude, Longitude and heading values are received with CanOpen as a 8 byte hex array. This hex array needs to be converted to a Real64 floating number using IEEE754 system in order to make sense of it. (in radians). Then it can be converted to degrees and then to a S32 integer in order to be useful in guide. I am using C Code POU's to do this. However, I am not very experienced with POU's in Guide so I am having a bit of trouble. I have written an algorithm in C that converts a hex array to a Real64 floating point number. I know this code works because I have tested it independent of Guide. When I test it in Guide however, I am consistently getting 0 on the output from the POU.

During this initial testing the output is a Real64 number which I know Guide cannot work with, but I have made sure that the hex array will correspond to a floating point number larger than 0 so at least the numbers before the decimal point can be displayed. Once this is working then I can refine the code (or add another POU) to do the next steps such as convert to integer accurately.

Can anybody with some experience using C code in POU's have a look over how I have set up the POU and let me know what I have done wrong or missed out? Or anything else you can see that is not correct? Attached is the P1P file.

Cheers,

Offline Matt_Eng

  • PLUS+1 Developer
  • ***
  • Posts: 21
  • Karma: +10/-0
Re: CanOpen (REAL64) GNSS messages with C Code POU
« Reply #1 on: March 31, 2023, 05:03:48 PM »
Hi,

There are a few setup issues in the POU.
The first is that the POU inputs and outputs weren't actually being used, so they have to be connected up.
The second issue is that the GUIDE graphical code can't interface to a Double type, so that has to be converted before it is handed over to GUIDE.

---POU code start
double radians_lat;
Bytes_to_Radians(byte_array, &radians_lat);
*radians = (int32_t)radians_lat;
---POU code end

Return value of ~3.034 or just 3 when I run it in the debugger.
This should at least let you continue then with the rest of the conversions

The debugger can be pretty handy for c code, I often set the True constant next to the POU as a break point, and then just step through the code. This will also let you see some of the local variables in your c code to find any issues. (When stepping through the C file, the Local Variables are in the main GUIDE window in the bottom dock)

-Matt_Eng

Offline mfaber

  • PLUS+1 Novice
  • *
  • Posts: 4
  • Karma: +0/-0
Re: CanOpen (REAL64) GNSS messages with C Code POU
« Reply #2 on: April 11, 2023, 07:07:18 AM »
Thanks Matt_Eng, that cleared things up for me. I appreciate it.