KOGNA read I/O bit from main status
Moderators: TomKerekes, dynomotion
KOGNA read I/O bit from main status
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
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
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: KOGNA read I/O bit from main status
Hi Raffaello,
You should be able to use the GetBitState200 method for getting bits 200 through 289 from the Main Status Record.
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?
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
- Attachments
-
- KM_MainStatus.cs
- (40.13 KiB) Downloaded 201 times
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: KOGNA read I/O bit from main status
Hello Tom,
I recompiled KMotion_dotNet, end now in decompiled dll I can see:
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
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);
}
I'm using the DSPKOGNA.out from 5.3.1
Thanks
Raffaello
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: KOGNA read I/O bit from main status
Hi Raffaello,
That would be the result if the correction was not made. There were 2 corrections. The other was this:
was corrected to:
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;
}
}
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.
Tom Kerekes
Dynomotion, Inc.
Re: KOGNA read I/O bit from main status
Hello Tom,
I sow the two correction.
The decompiled file that I get look like this:
first,
and second
It seems that the two corrections were applied
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;
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);
}
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: KOGNA read I/O bit from main status
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.
Tom Kerekes
Dynomotion, Inc.
Re: KOGNA read I/O bit from main status
Hi Tom,
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
I recompiled KMotion_dotNet project with this KM_MainStatus.cs to get a new KMotion_dotNet.dll that I use in my project.TomKerekes wrote: ↑Tue Dec 05, 2023 11:03 pmAttached is a corrected KM_MainStatus.cs file. Are you able to recompile KMotion_dotNet?
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
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: KOGNA read I/O bit from main status
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.
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.
Tom Kerekes
Dynomotion, Inc.
Re: KOGNA read I/O bit from main status
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.
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.
Re: KOGNA read I/O bit from main status
Hello,
in the source file BitState200[] is a three elements array
but at runtime I get a two elements array!
In my C# projet I use only 6 file:
Could you provide to me this 6 files, for x64 environment?
Thanks
Raffaello
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
At this point, I have to say I'm not able to recompile, sorryTomKerekes wrote: ↑Tue Dec 05, 2023 11:03 pmBut 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?
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