How to best assign Beckhoff EL6851 DMX channels - plc

on Beckhoff's EL6851, to assign DMX channels to the variables I can either do this :
Option1
bEL6851_DmxChannels AT %Q* : ARRAY[1..512] OF USINT;
or this
Option2 :
bEL6851_DmxChannelsChunk1 AT %Q* : ARRAY[1..64] OF USINT;
bEL6851_DmxChannelsChunk2 AT %Q* : ARRAY[65..128] OF USINT;
bEL6851_DmxChannelsChunk3 AT %Q* : ARRAY[129..192] OF USINT;
bEL6851_DmxChannelsChunk4 AT %Q* : ARRAY[193..256] OF USINT;
bEL6851_DmxChannelsChunk5 AT %Q* : ARRAY[257..320] OF USINT;
bEL6851_DmxChannelsChunk6 AT %Q* : ARRAY[321..384] OF USINT;
bEL6851_DmxChannelsChunk7 AT %Q* : ARRAY[385..448] OF USINT;
bEL6851_DmxChannelsChunk8 AT %Q* : ARRAY[449..512] OF USINT;
Option1 means I need to double click 512 times to assing every variable - not an option.
Option2 meansI get 8 arrays instead of 1. How can I now make this into a single array that works as standard 512 elements array in Option1.
I tried this but simple copy doesn't work. I guess some references or pointers ?
FOR counter := 1 TO 64 BY 1 DO
bEL6851_DmxChannels[counter] := bEL6851_DmxChannelsChunk1[counter];
END_FOR
...
bEL6851_DmxChannels[counter] := 255; // this won't work.

Turns out that all you have to do to make it work with 512 elements array is tick the "All Types" after you right click each 64 channels chunk. Hope that saves someone few headaches !

I am not sure it will work in your case (i mean if you can assign it to module vars) but one of the ways is to create multiple level array.
VAR
DmxChannels : ARRAY[1..512] OF USINT;
DmxChannelsM AT %Q* : ARRAY[1..8,1..64] OF USINT;
i,j:INT;
END_VAR
FOR i := 1 TO 8 DO
FOR j := 1 TO 64 DO
DmxChannels[((i - 1) * 64) + j] :=
DmxChannelsM[i,j];
END_FOR
END_FOR

Related

How to examine the structures in Windbg?

I'm trying to use dt command to see the values of the structure fields. But it doesn't work for some reason:
dt ntkrnlmp!_SECURITY_SUBJECT_CONTEXT rdx
Cannot find specified field members.
Nevertheless, if I check if windbg knows the structure, it works just fine:
dt ntkrnlmp!_SECURITY_SUBJECT_CONTEXT
+0x000 ClientToken : Ptr64 Void
+0x008 ImpersonationLevel : _SECURITY_IMPERSONATION_LEVEL
+0x010 PrimaryToken : Ptr64 Void
+0x018 ProcessAuditId : Ptr64 Void
add # before register name
dt foo!blah #bar or use
? #rdx and provide the physical value
dt foo!blah 0x13371337

Calculation of the number of microseconds in Ada

in C langage we have get_usec() which gives us the number of microseconds since the start of the current second.
-Speaking of the "current second" necessarily refers to time reference which is often EpochTime.
-In Ada.Calendar package, I see Seconds or Clocks functions by example with ability to split & get the seconds.
But how to get the number of microseconds since the start of the current second, please?
Thanks
Mark
Note that Ada.Calendar is for local time, and may jump backwards. If it's available (are there any post-83 compilers that don't provide it?), you'll be better off using Ada.Real_Time ARM D.8:
Now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;
Count : Ada.Real_Time.Seconds_Count;
Sub : Ada.Real_Time.Time_Span;
...
Ada.Real_Time.Split (T => Now, SC => Count, TS => Sub);
Now Count contains the number of whole seconds since the epoch and Sub contains the fraction of a second in addition to Count. Ada.Real_Time.To_Duration converts a Time_Span to Duration, allowing you to multiply it by 1E6 to get microseconds.
The packages Ada.Calendar and Ada.Calendar.Formatting provide the information you will need.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
procedure Main is
Now : Time := Clock;
Seconds : Second_Duration := Sub_Second (Now);
begin
Put_Line
("Sub seconds since current second: " &
Second_Duration'Image (Seconds));
end Main;
The output of one execution of this program is:
Sub seconds since current second: 0.655316600
In this execution the value indicated 655316.6 microseconds.
It can also be done (of course) without Ada.Calendar.Formatting, like this for example:
with Ada.Calendar; use Ada.Calendar;
...
type Seconds_In_Day is range 0 .. 86_400;
-- Or use Integer if it is 32 bits.
Now : constant Day_Duration := Seconds (Clock);
Subsec : Duration := Now - Day_Duration (Seconds_In_Day (Now));
...
if Subsec < 0.0 then
-- Conversion of Now rounded up instead of down.
Subsec := Subsec + 1.0;
end if;
with the result in Subsec.
But using Ada.Calendar.Formatting.Sub_Second is shorter, and may be better (faster or more accurate) for all I know; I did not compare the two methods.
Many thaks for yours answers.
Using all yours examples, i made some trials, one is below :
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Real_Time; use Ada.Real_Time;
procedure Display_Current_Year is
--need to precise the origin package Ada.Real-Time else ambiguous
Now : Ada.Calendar.Time := Clock;
Now_Year : Year_Number;
Now_Month : Month_Number;
Now_Day : Day_Number;
Now_Seconds : Day_Duration;
Current_Real_Time : Ada.Real_Time.Time;
Time_Span : Ada.Real_Time.Time_Span;
Seconds_Count : Ada.Real_Time.Seconds_Count;
Hour : float;
begin
--- Ada.Calendar
Split (Now,
Now_Year,
Now_Month,
Now_Day,
Now_Seconds);
Put_Line("Calendar : Date du jour = ");
Put_Line ("Current year is: "
& Year_Number'Image (Now_Year));
Put_Line ("Current month is: "
& Month_Number'Image (Now_Month));
Put_Line ("Current day is: "
& Day_Number'Image (Now_Day));
Put_Line ("'Current' seconde is: "
& Day_Duration'Image (Now_Seconds));
New_Line;
--Ada.Real_Time;
Current_Real_Time := Ada.Real_Time.Clock;
Ada.Real_Time.Split (T => Current_Real_Time,
Sc => Seconds_Count,
Ts => Time_Span);
Put_Line ("Real_Time : Seconds_Count = " & Seconds_Count'Img);
Hour := (float(Seconds_count) / 3600.00);
Put_Line ("Hour since seconds origin : "
& (Hour'Img));
end Display_Current_Year;
with result :
$ ./display_current_year
Calendar : Date du jour =
Current year is: 2022
Current month is: 2
Current day is: 27
'Current' seconde is: 68625.325897000
Real_Time : Seconds_Count = 30953
Hour since seconds origin : 8.59806E+00
$
-Results for calendar are OK, but why 30953 seconds !!
Where does GNAT take the Epoch, if this is, in this case, please?
Thanks
Mark
You can do a dirty trick where you define a record My_raw_duration_Type : whole_part, fraction_part, both U32. Define Unchecked_Conversion To_Raw (Ada.Real_Time.Duration, My_Raw_Duration_Type). Then take the result of that and call it My_Raw_Duration. The milliseconds result you want is integer(float(My_Raw_Duration.Fraction_Part)/float(4*1032**2) * 1000.0);

Using FromArgb for Int32[] value results in swapped Red and Blue values

I have this Int32[] value 14508153 which should be:
R : 121
G : 96
B : 221
If I use:
[System.Drawing.Color]::FromArgb(14508153)
It returns:
R : 221
G : 96
B : 121
A : 0
IsKnownColor : False
IsEmpty : False
IsNamedColor : False
IsSystemColor : False
Name : dd6079
Questions
How or why are those values swapped for R and B using that function?
Is there a built-in PowerShell method to convert them correctly?
I can't speak to why the bytes need to be rearranged (see the bottom section for thoughts), but here's how you can do it:
Add-Type -AssemblyName System.Drawing
$bytes = [System.BitConverter]::GetBytes(14508153)
[byte[]] $rearrangedBytes = $bytes[2], $bytes[1], $bytes[0], $bytes[3]
[System.Drawing.Color]::FromArgb(
[System.BitConverter]::ToInt32($rearrangedBytes, 0)
)
See System.BitConverter.GetBytes(), System.BitConverter.ToInt32().
The above yields:
R : 121
G : 96
B : 221
A : 0
IsKnownColor : False
IsEmpty : False
IsNamedColor : False
IsSystemColor : False
Name : 7960dd
It appears that only 3 of the bytes in your [int] (System.Int32) value are relevant, and that they are in Big-Endian order (see the Wikipedia article about endianness).
By contrast, System.Drawing.Color.FromArgb() expects all 4 bytes to be relevant, in Little-Endian order.

Verified software toolchain: if-then-else proof

I'm learning using the Verified Software Toolchain (VST). I get stuck at proving a simple "if-then-else" block.
Here is the .c file:
int iftest(int a){
int r=0;
if(a==2){
r=0;
else{
r=0;
}
return r;
}
I write a specification about the iftest() as follow:
Definition if_spec :=`
DECLARE _iftest`
WITH a0:int
PRE [_a OF tint]
PROP ()
LOCAL (`(eq (Vint a0)) (eval_id _a))
SEP ()
POST [tint]
PROP ()
LOCAL ((`(eq (Vint (Int.repr 0))) retval))
SEP ().`
the proof steps are:
Lemma body_iftest : semax_body Vprog Gtot f_iftest if_spec.Proof.
start_function.
name a _a.
name r _r.
forward. (*r=0*)
simplify_typed_comparison.
forward. (*if(E)*). go_lower. subst. normalize.
it generates a hypothesis:Post := EX x : ?214, ?215 x : environ -> mpred and the "then" clause can't go on by "go_lower" and "normalize".
In the current version of VST there is a forward_if PRED tactic. Here is how you can use it to solve your goal:
Require Import floyd.proofauto.
Require Import iftest.
Local Open Scope logic.
Local Open Scope Z.
Definition if_spec :=
DECLARE _iftest
WITH a0:int
PRE [_a OF tint]
PROP ()
LOCAL (`(eq (Vint a0)) (eval_id _a))
SEP ()
POST [tint]
PROP ()
LOCAL ((`(eq (Vint (Int.repr 0))) retval))
SEP ().
Definition Vprog : varspecs := nil.
Definition Gtot : funspecs := if_spec :: nil.
Lemma body_iftest : semax_body Vprog Gtot f_iftest if_spec.
Proof.
start_function.
name a _a.
name r _r.
forward.
forward_if (PROP ()
LOCAL (`(eq (Vint (Int.repr 0))) (eval_id _r)) SEP()).
+ forward.
entailer.
+ forward.
entailer.
+ forward.
Qed.
P.S. #bazza is right about a missing } before else. I assume it is fixed.
Potentially a non-helpful answer, but I can't help noticing that your .c code has 3 {'s and only 2 }'s, suggesting that it doesn't compile. Could the error message you're receiving have something to do with that?

How to get a child item into a variable on its own

I am relatively sure this is quite easy to do but my google fu is not running strong
At the moment I am doing:
add-pssnapin windows.serverbackup
get-wbsummary
This returns me:
NextBackupTime : 07/09/2012 12:00:00
NumberOfVersions : 210
LastSuccessfulBackupTime : 06/09/2012 21:00:13
LastSuccessfulBackupTargetPath : \\?\Volume{bf315689-e5ed-11e1-a376-d067e5f384ea}
LastSuccessfulBackupTargetLabel : SBSERVE 2012_08_21 12:20 DISK_01
LastBackupTime : 06/09/2012 21:00:13
LastBackupTarget : SBSERVE 2012_08_21 12:20 DISK_01
DetailedMessage :
LastBackupResultHR : 0
LastBackupResultDetailedHR : 0
CurrentOperationStatus : NoOperationInProgress
What I want to do is get just the result portion (not its title into a variable) so for example $lastbackuptime = 07/09/2012 12:00:00
PS> $wbs = Get-WBSummary
PS> $lastbackuptime = $wbs.NextBackupTime