Skip to content

Instantly share code, notes, and snippets.

View nikvoronin's full-sized avatar
:octocat:
await git status

Nikolai Voronin nikvoronin

:octocat:
await git status
View GitHub Profile
@nikvoronin
nikvoronin / xm4bat.ps1
Created February 13, 2023 10:20
Query battery level for WH-1000XM4 wireless headphones
# https://stackoverflow.com/a/75174377
Get-PnpDevice -FriendlyName "*WH-1000XM4*" | ForEach-Object {
$local:test = $_ |
Get-PnpDeviceProperty -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2' |
Where Type -ne Empty;
if ($test) {
"To query battery for $($_.FriendlyName), run the following:"
" Get-PnpDeviceProperty -InstanceId '$($test.InstanceId)' -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2' | % Data"
""
@nikvoronin
nikvoronin / PrintAllPerformanceCounters.cs
Last active January 28, 2022 21:15
Prints all windows performance counters with categories, instances and counters.
// NuGet package `System.Diagnostics.PerformanceCounter` have to be installed
// .NET 6
#nullable disable
using System.Globalization;
using System.Diagnostics;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
using var writer = new StreamWriter( Console.OpenStandardOutput() );
@nikvoronin
nikvoronin / Tc3_ReadVariableByPointerOverAds.cs
Created November 17, 2020 07:36
GoTwinCAT. Read Variable by Pointer Over ADS
while (!Console.KeyAvailable) {
var result = await client.ReadValueAsync<ushort>( "MAIN.pState^", CancellationToken.None );
ushort state = result.Succeeded
? result.Value
: (ushort) 0;
Console.Write( $"{(state == 100 ? "*" : "+")}" );
await Task.Delay( 50 );
}
<TcTargetDesc>
<TargetType>TC/BSD-OS</TargetType>
<TargetVersion>
<Version>3</Version>
<Revision>1</Revision>
<Build>4024</Build>
</TargetVersion>
<TargetFeatures>
<NetId>39.159.94.42.1.1</NetId>
</TargetFeatures>
<TcTargetDesc>
<TargetType>CX9020-M510-CE</TargetType>
<TargetVersion>
<Version>3</Version>
<Revision>1</Revision>
<Build>4024</Build>
</TargetVersion>
<TargetFeatures>
<NetId>5.59.222.141.1.1</NetId>
</TargetFeatures>
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using TwinCAT.Ads; // v4.4.0.0
namespace AdsReadSystemConfig
{
class Program
{
__kernel void halton(
uint base1,
uint base2,
const int bufferSize,
__global float2* rngBuffer)
{
uint mBase2 = base1;
uint mBase3 = base2;
float mX;
float mY;
__kernel void xorshift(
uint s1, // seed(base) 1
uint s2, // seed(base) 2
const int bufferSize,
__global float2* rngBuffer)
{
uint st;
for(int i = 0; i < bufferSize; i++) {
st = s1 ^ (s1 << 11);
@nikvoronin
nikvoronin / MQTTnet_DataAgentConsole.cs
Last active January 3, 2021 21:48
MQTTnet Test Queue Reader
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Client.Options;
using System;
using System.Threading.Tasks;
namespace Tc3_DataAgentConsole
{
class Program
{
PROGRAM MAIN
VAR
PAYLOAD: UINT := 100;
usage, usageMax: UDINT;
latencyMax, latencyAct: UDINT;
cycleExecTime, cycleTimeSti, cycleExecSti: REAL;
cycleLoad, cycleLoadUser: REAL;
TcSysLatency: TC_SysLatency;