KOGNA read I/O bit from main status

Moderators: TomKerekes, dynomotion

TorRaf
Posts: 15
Joined: Thu Sep 02, 2021 12:15 pm

KOGNA read I/O bit from main status

Post by TorRaf » Tue Dec 05, 2023 10:26 am

Hi Tom,

I'm writing C# application and I switch from KFlop to Kogna.

To refresh my GUI I have a timer to ask MainStatus each 250ms. I always can read axis position/destination, but how can I get kogna's bit?
I need to read bit from 218 to 223 (EX_IO8 to EX_IO13)

As workaround I could use ReadBit command, but I would like to use MainStatus to use the same mechanism used with Kflop.

Thanks

Raffaello

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: KOGNA read I/O bit from main status

Post by TomKerekes » Tue Dec 05, 2023 11:03 pm

Hi Raffaello,

You should be able to use the GetBitState200 method for getting bits 200 through 289 from the Main Status Record.

Code: Select all

    bool bit218 = MainStatus.GetBitState200(218) == 1; // Get bit 218 from main status
But I see there is a bug. This returns lower bits 0-63. Attached is a corrected KM_MainStatus.cs file. Are you able to recompile KMotion_dotNet?
Attachments
KM_MainStatus.cs
(40.13 KiB) Downloaded 8 times
Regards,

Tom Kerekes
Dynomotion, Inc.

TorRaf
Posts: 15
Joined: Thu Sep 02, 2021 12:15 pm

Re: KOGNA read I/O bit from main status

Post by TorRaf » Thu Dec 07, 2023 2:33 pm

Hello Tom,

I recompiled KMotion_dotNet, end now in decompiled dll I can see:

Code: Select all

public int GetBitState200(int index)
        {
            return GetValue(MainStatus.BitsState200[index - 200 >> 5], (index - 200) & 0x1F, 1);
        }
but I always get the wrong value. I have put a break point when I ask for a new status end I observ that the value of MainStatus.BitState[] and MainStatus.BitState200[] are identical.

I'm using the DSPKOGNA.out from 5.3.1

Thanks
Raffaello

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: KOGNA read I/O bit from main status

Post by TomKerekes » Thu Dec 07, 2023 6:40 pm

Hi Raffaello,

That would be the result if the correction was not made. There were 2 corrections. The other was this:

Code: Select all

        /// <summary>
        /// Bulk status record Current KFLOP/Kogna 64 IO Bit states
        /// Kogna - 90 bits 200-289 of state lsb=I/O bit200
        /// </summary>
        public int[] BitsState200
        {
            get
            {
                return MainStatus.BitsState;
            }
        }
was corrected to:

Code: Select all

        /// <summary>
        /// Bulk status record Current KFLOP/Kogna 64 IO Bit states
        /// Kogna - 90 bits 200-289 of state lsb=I/O bit200
        /// </summary>
        public int[] BitsState200
        {
            get
            {
                return MainStatus.BitsState200;
            }
        }
Regards,

Tom Kerekes
Dynomotion, Inc.

TorRaf
Posts: 15
Joined: Thu Sep 02, 2021 12:15 pm

Re: KOGNA read I/O bit from main status

Post by TorRaf » Thu Dec 07, 2023 9:48 pm

Hello Tom,

I sow the two correction.

The decompiled file that I get look like this:

first,

Code: Select all

public int Enables => MainStatus.Enables;

        public int AxisDone => MainStatus.AxisDone;

        public int[] BitsDirection => MainStatus.BitsDirection;

        public int BitsDirection200 => MainStatus.BitsDirection200;

        public int BitsDirection280 => MainStatus.BitsDirection280;

        public int[] BitsState => MainStatus.BitsState;

        public int[] BitsState200 => MainStatus.BitsState200;

        public int PinMuxModes => MainStatus.PinMuxModes;
and second

Code: Select all

   public int GetKFlopBitState(int index)
        {
            if (index > 31)
            {
                return GetValue(MainStatus.BitsState[1], index - 32, 1);
            }

            return GetValue(MainStatus.BitsState[0], index, 1);
        }

        public int GetBitState200(int index)
        {
            return GetValue(MainStatus.BitsState200[index - 200 >> 5], (index - 200) & 0x1F, 1);
        }
It seems that the two corrections were applied

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: KOGNA read I/O bit from main status

Post by TomKerekes » Fri Dec 08, 2023 12:45 am

I'm not sure why you mention decompiled code you have the source code. Here is what works for me:

Regards,

Tom Kerekes
Dynomotion, Inc.

TorRaf
Posts: 15
Joined: Thu Sep 02, 2021 12:15 pm

Re: KOGNA read I/O bit from main status

Post by TorRaf » Fri Dec 08, 2023 9:42 am

Hi Tom,
TomKerekes wrote:
Tue Dec 05, 2023 11:03 pm
Attached is a corrected KM_MainStatus.cs file. Are you able to recompile KMotion_dotNet?
I recompiled KMotion_dotNet project with this KM_MainStatus.cs to get a new KMotion_dotNet.dll that I use in my project.
When I decompile the new dll to check if the two modification are applied I can find both.

But at run time the instance of my KM_MainStatus look like see the image
https://industrialphotons-my.sharepoint ... g?e=9gKXs4

How you can see (I hope the link works :) ), the BitStates200[] is a 2 elements array (in your video was 3 elements) and it is equal to BitState[]
So, should be my recompilation dosen't work fine :(

Raffaello

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: KOGNA read I/O bit from main status

Post by TomKerekes » Fri Dec 08, 2023 7:01 pm

Hi Raffaello,

It seems it is somehow still using an old binary. One thing I sometimes do is delete the new binary to see if I indeed get a dll not found error as a sanity check.

I don't understand why you look at decompiled code rather than the actual source code.
Regards,

Tom Kerekes
Dynomotion, Inc.

Moray
Posts: 282
Joined: Thu Apr 26, 2018 10:16 pm

Re: KOGNA read I/O bit from main status

Post by Moray » Fri Dec 08, 2023 11:07 pm

Rather than delete files, I often just add a random letter to the filename.

I keep all my old KMotion installs, but just add an x to the end, that way if I've still got something pointing to the wrong directory I quickly know about it, but I still have access to all the files in case there is something I've forgotten to copy over.

TorRaf
Posts: 15
Joined: Thu Sep 02, 2021 12:15 pm

Re: KOGNA read I/O bit from main status

Post by TorRaf » Mon Dec 11, 2023 2:40 pm

Hello,

in the source file BitState200[] is a three elements array

Code: Select all

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public int[] BitsState200;    // Kogna - 90 bits 200-289 of state lsb=I/O bit200
but at runtime I get a two elements array!
TomKerekes wrote:
Tue Dec 05, 2023 11:03 pm
But I see there is a bug. This returns lower bits 0-63. Attached is a corrected KM_MainStatus.cs file. Are you able to recompile KMotion_dotNet?
At this point, I have to say I'm not able to recompile, sorry :(

In my C# projet I use only 6 file:
  • KMotion_dotNet.dll
    (used as reference to the projet)
  • KMotion_dotNet_Interop.dll
  • KMotionDLL.dll
  • KMotionServer.exe
  • GCodeInterpreter.dll
  • Catel.Core.dll
    (last 5,cpied to the execution folder)


Could you provide to me this 6 files, for x64 environment?

Thanks
Raffaello

Post Reply