How do I program an Interpolated Position Mode sequence in IEC-61131 Structured Text using the Maxon EPOS Libraries? - iec61131-3

The Maxon EPOS libraries define some Function Blocks that seemingly handle Interpolated Position Mode, however there are no samples, as far as I can determine, that specify how to use them.
Here is what I have so far but at the moment it just skips right through it when called with Execute set to TRUE
FUNCTION_BLOCK FB_MAIN_Routine1
TYPE
POSITIONS: ARRAY[1..64] OF DINT;
VELOCITIES: ARRAY[1..64] OF DINT;
TIME_VALUES: ARRAY[1..64] OF USINT;
END_TYPE
VAR_EXTERNAL
Axis1: AXIS_REF;
END_VAR
VAR_INPUT
Execute: BOOL;
END_VAR
VAR_OUTPUT
Done: BOOL;
END_VAR
VAR
Start: BOOL := FALSE;
LoadPointsAx1: BOOL := FALSE;
fbClearIpmBufferAx1: MU_ClearIpmBuffer;
fbAddPvtValuesAx1: MU_AddPvtValues;
fbStartIpmTrajectoryAx1: MU_StartIpmTrajectory;
fbGetIpmStatusAx1: MU_GetIpmStatus;
fbGetIpmTrajectoryStatusAx1: MU_GetIpmTrajectoryStatus;
PositionsAx1: POSITIONS := [49500, 47703, 45906, 44109, 42312, 40516, 38719, 36922, 35125, 33329, 31532, 29735, 27938, 26142, 24345, 22548, 20751, 21834, 23037, 24240, 25443, 26646, 27848, 29051, 30254, 31457, 32660, 33863, 35065, 36268, 37471, 38674, 39877, 41080, 42282, 43485, 44688, 45891, 47094, 48297, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500, 49500];
VelocitiesAx1: VELOCITIES := [-216, -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, -216, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
TimeValuesAx1: TIME_VALUES := [250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
END_VAR
fbGetIpmStatusAx1(Axis := Axis1, Enable := Execute);
fbClearIpmBufferAx1(Axis := Axis1, Execute := Execute);
If fbClearIpmBufferAx1.Done Then
LoadPointsAx1 := TRUE;
END_IF;
fbAddPvtValuesAx1(Axis := Axis1, Execute := LoadPointsAx1, Position := PositionsAx1, Velocity := VelocitiesAx1, TimeValue := TimeValuesAx1);
If fbAddPvtValuesAx1.Done Then
Start := TRUE;
End_If;
fbStartIpmTrajectoryAx1(Axis := Axis1, Execute := Start);
fbGetIpmTrajectoryStatusAx1(Axis := Axis1, Enable := fbStartIpmTrajectoryAx1.Done);
If (Execute = FALSE) Or fbGetIpmTrajectoryStatusAx1.TargetReached Then
Done := Execute;
Start := FALSE;
LoadPointsAx1 := FALSE;
fbAddPvtValuesAx1(Axis := Axis1, Execute := FALSE);
fbStartIpmTrajectoryAx1(Axis := Axis1, Execute := FALSE);
fbGetIpmTrajectoryStatusAx1(Axis := Axis1, Enable := FALSE);
End_If;
END_FUNCTION_BLOCK

Unlike other moves of operation (e.g. Velocity Mode or Position Mode), Interpolated Position Mode needs to be initialised.
A call to MU_ActivateInterpolatedPositionMode solves this.

Related

control volume only for opera gx with ahk

i am new here and new with ahk.
I would like to have a script to control the volume of a spereate program like in the Microsoft Sound Mixer.
I want to control the volume of Opera GX browser when it is minimized.
After some research, I found a code in the ahk forum, which works with spotify. But I need it for the Opera GX Browser
If (!A_IsAdmin)
{
MsgBox Run the Script as Administrator!
ExitApp
}
Process Exist, Spotify.exe
ProcessId := ErrorLevel
If (!ProcessId)
{
MsgBox Spotify is not running!
ExitApp
}
LCTRL & UP::SetAppVolume(ProcessId, GetAppVolume(ProcessId) + 5)
LCTRL & DOWN::SetAppVolume(ProcessId, GetAppVolume(ProcessId) - 5)
Return
GetAppVolume(PID)
{
Local MasterVolume := ""
IMMDeviceEnumerator := ComObjCreate("{BCDE0395-E52F-467C-8E3D-C4579291692E}", "{A95664D2-9614-4F35-A746-DE8DB63617E6}")
DllCall(NumGet(NumGet(IMMDeviceEnumerator+0)+4*A_PtrSize), "UPtr", IMMDeviceEnumerator, "UInt", 0, "UInt", 1, "UPtrP", IMMDevice, "UInt")
ObjRelease(IMMDeviceEnumerator)
VarSetCapacity(GUID, 16)
DllCall("Ole32.dll\CLSIDFromString", "Str", "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}", "UPtr", &GUID)
DllCall(NumGet(NumGet(IMMDevice+0)+3*A_PtrSize), "UPtr", IMMDevice, "UPtr", &GUID, "UInt", 23, "UPtr", 0, "UPtrP", IAudioSessionManager2, "UInt")
ObjRelease(IMMDevice)
DllCall(NumGet(NumGet(IAudioSessionManager2+0)+5*A_PtrSize), "UPtr", IAudioSessionManager2, "UPtrP", IAudioSessionEnumerator, "UInt")
ObjRelease(IAudioSessionManager2)
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+3*A_PtrSize), "UPtr", IAudioSessionEnumerator, "UIntP", SessionCount, "UInt")
Loop % SessionCount
{
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+4*A_PtrSize), "UPtr", IAudioSessionEnumerator, "Int", A_Index-1, "UPtrP", IAudioSessionControl, "UInt")
IAudioSessionControl2 := ComObjQuery(IAudioSessionControl, "{BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D}")
ObjRelease(IAudioSessionControl)
DllCall(NumGet(NumGet(IAudioSessionControl2+0)+14*A_PtrSize), "UPtr", IAudioSessionControl2, "UIntP", currentProcessId, "UInt")
If (PID == currentProcessId)
{
ISimpleAudioVolume := ComObjQuery(IAudioSessionControl2, "{87CE5498-68D6-44E5-9215-6DA47EF883D8}")
DllCall(NumGet(NumGet(ISimpleAudioVolume+0)+4*A_PtrSize), "UPtr", ISimpleAudioVolume, "FloatP", MasterVolume, "UInt")
ObjRelease(ISimpleAudioVolume)
}
ObjRelease(IAudioSessionControl2)
}
ObjRelease(IAudioSessionEnumerator)
Return Round(MasterVolume * 100)
}
SetAppVolume(PID, MasterVolume) ; WIN_V+
{
MasterVolume := MasterVolume > 100 ? 100 : MasterVolume < 0 ? 0 : MasterVolume
IMMDeviceEnumerator := ComObjCreate("{BCDE0395-E52F-467C-8E3D-C4579291692E}", "{A95664D2-9614-4F35-A746-DE8DB63617E6}")
DllCall(NumGet(NumGet(IMMDeviceEnumerator+0)+4*A_PtrSize), "UPtr", IMMDeviceEnumerator, "UInt", 0, "UInt", 1, "UPtrP", IMMDevice, "UInt")
ObjRelease(IMMDeviceEnumerator)
VarSetCapacity(GUID, 16)
DllCall("Ole32.dll\CLSIDFromString", "Str", "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}", "UPtr", &GUID)
DllCall(NumGet(NumGet(IMMDevice+0)+3*A_PtrSize), "UPtr", IMMDevice, "UPtr", &GUID, "UInt", 23, "UPtr", 0, "UPtrP", IAudioSessionManager2, "UInt")
ObjRelease(IMMDevice)
DllCall(NumGet(NumGet(IAudioSessionManager2+0)+5*A_PtrSize), "UPtr", IAudioSessionManager2, "UPtrP", IAudioSessionEnumerator, "UInt")
ObjRelease(IAudioSessionManager2)
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+3*A_PtrSize), "UPtr", IAudioSessionEnumerator, "UIntP", SessionCount, "UInt")
Loop % SessionCount
{
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+4*A_PtrSize), "UPtr", IAudioSessionEnumerator, "Int", A_Index-1, "UPtrP", IAudioSessionControl, "UInt")
IAudioSessionControl2 := ComObjQuery(IAudioSessionControl, "{BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D}")
ObjRelease(IAudioSessionControl)
DllCall(NumGet(NumGet(IAudioSessionControl2+0)+14*A_PtrSize), "UPtr", IAudioSessionControl2, "UIntP", currentProcessId, "UInt")
If (PID == currentProcessId)
{
ISimpleAudioVolume := ComObjQuery(IAudioSessionControl2, "{87CE5498-68D6-44E5-9215-6DA47EF883D8}")
DllCall(NumGet(NumGet(ISimpleAudioVolume+0)+3*A_PtrSize), "UPtr", ISimpleAudioVolume, "Float", MasterVolume/100.0, "UPtr", 0, "UInt")
ObjRelease(ISimpleAudioVolume)
}
ObjRelease(IAudioSessionControl2)
}
ObjRelease(IAudioSessionEnumerator)
}
Thanks
Try changing the 7th line to Process Exist, Opera.exe

In Autohotkey how to wait until screen is on?

I am using a script to switch between my TV and my monitor and also switching the audio (TV or speakers). My problem is, if the TV is not active the audio isn't in the speakers list, so I want to halt my script to wait until the TV is on. Is there a way to check this?
Found this code, gets all display devices. So all I needed to do is check if the device with the certain name exists...
CheckIfDisplayExists:
Gosub, GetDisplayDevices
For DeviceName, DeviceID in Devices
{
If (InStr(DeviceName, "SAMSUNG"))
{
; < display exists, run the rest of the code >
}
}
This is the code to get all display devices:
GetDisplayDevices:
; http://www.daveamenta.com/2011-05/programmatically-or-command-line-change-the-default-sound-playback-device-in-windows-7/
Devices := {}
IMMDeviceEnumerator := ComObjCreate("{BCDE0395-E52F-467C-8E3D-C4579291692E}", "{A95664D2-9614-4F35-A746-DE8DB63617E6}")
; IMMDeviceEnumerator::EnumAudioEndpoints
; eRender = 0, eCapture, eAll
; 0x1 = DEVICE_STATE_ACTIVE
DllCall(NumGet(NumGet(IMMDeviceEnumerator+0)+3*A_PtrSize), "UPtr", IMMDeviceEnumerator, "UInt", 0, "UInt", 0x1, "UPtrP", IMMDeviceCollection, "UInt")
ObjRelease(IMMDeviceEnumerator)
; IMMDeviceCollection::GetCount
DllCall(NumGet(NumGet(IMMDeviceCollection+0)+3*A_PtrSize), "UPtr", IMMDeviceCollection, "UIntP", Count, "UInt")
Loop % (Count)
{
; IMMDeviceCollection::Item
DllCall(NumGet(NumGet(IMMDeviceCollection+0)+4*A_PtrSize), "UPtr", IMMDeviceCollection, "UInt", A_Index-1, "UPtrP", IMMDevice, "UInt")
; IMMDevice::GetId
DllCall(NumGet(NumGet(IMMDevice+0)+5*A_PtrSize), "UPtr", IMMDevice, "UPtrP", pBuffer, "UInt")
DeviceID := StrGet(pBuffer, "UTF-16"), DllCall("Ole32.dll\CoTaskMemFree", "UPtr", pBuffer)
; IMMDevice::OpenPropertyStore
; 0x0 = STGM_READ
DllCall(NumGet(NumGet(IMMDevice+0)+4*A_PtrSize), "UPtr", IMMDevice, "UInt", 0x0, "UPtrP", IPropertyStore, "UInt")
ObjRelease(IMMDevice)
; IPropertyStore::GetValue
VarSetCapacity(PROPVARIANT, A_PtrSize == 4 ? 16 : 24)
VarSetCapacity(PROPERTYKEY, 20)
DllCall("Ole32.dll\CLSIDFromString", "Str", "{A45C254E-DF1C-4EFD-8020-67D146A850E0}", "UPtr", &PROPERTYKEY)
NumPut(14, &PROPERTYKEY + 16, "UInt")
DllCall(NumGet(NumGet(IPropertyStore+0)+5*A_PtrSize), "UPtr", IPropertyStore, "UPtr", &PROPERTYKEY, "UPtr", &PROPVARIANT, "UInt")
DeviceName := StrGet(NumGet(&PROPVARIANT + 8), "UTF-16") ; LPWSTR PROPVARIANT.pwszVal
DllCall("Ole32.dll\CoTaskMemFree", "UPtr", NumGet(&PROPVARIANT + 8)) ; LPWSTR PROPVARIANT.pwszVal
ObjRelease(IPropertyStore)
ObjRawSet(Devices, DeviceName, DeviceID)
}
ObjRelease(IMMDeviceCollection)
return

How can I adjust the socket data length to be flexible?

d := make([]byte, 4096)
conn.Read(d)
I created a fixed array to get data from the socket.
But I want to get the data in a flexible size rather than a fixed size.
The reason is that i need to unmarshal the data received from the socket, but the data is fixed in size, so calling the unmarshal function will not work.
So what I want to ask is how to get the data from the socket in a flexible size or how to delete empty values ​​from a fixed size.
ex)
data := make([]byte, 4096)
conn.Read(data)
fmt.Println(len(data)) ===> 105 (Actual data length)
or
data([4, 128, 16, 8, 7, 0, 0, 0, 0, 7, 9, 128, 0...])
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
data([4, 128, 16, 8, 7, 0, 0, 0, 0, 7, 9, 128])
For example,
data := make([]byte, 0, 4096)
n, err := conn.Read(data[:cap(data)])
data = data[:n]
if err != nil {
// handle error
}
fmt.Println(len(data))

Autohotkey Most of numpad keys don't work

Here is my script. When I try it, only the NumpadClear (Num5) key works. I use Windows 7 64bit.
#SingleInstance force
#UseHook
#InstallKeybdHook
*~NumpadIns::MouseMove, 0, 1, 0, R
*~NumpadClear::MouseMove, 0, -1, 0, R
*~NumpadEnd::MouseMove, -1, 0, 0, R
*~NumpadPgDn::MouseMove, 1, 0, 0, R
*~NumpadDown::Click
*~NumpadEnter::Click Right
This AutoHotkey script should achieve what you're looking for.
It will work whether NumLock is turned off or on.
#SingleInstance force
#UseHook
#InstallKeybdHook
NumpadIns::MouseMove, 0, 1, 0, R
NumpadClear::MouseMove, 0, -1, 0, R
NumpadEnd::MouseMove, -1, 0, 0, R
NumpadPgDn::MouseMove, 1, 0, 0, R
NumpadDown::Click
NumpadEnter::Click Right
Numpad0::MouseMove, 0, 1, 0, R
Numpad5::MouseMove, 0, -1, 0, R
Numpad1::MouseMove, -1, 0, 0, R
Numpad3::MouseMove, 1, 0, 0, R
Numpad2::Click
;NumpadEnter::Click Right

Invalid MIT magic cookie when connecting to X server

I'm trying to write my own code to connect to an X server. I ran xauth to get the magic cookie I needed and wrote the following code to try and test out establishing a connection:
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
int main()
{
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
struct sockaddr_un serv_addr;
memset((void*)&serv_addr, 0, sizeof(serv_addr));
serv_addr.sun_family = AF_UNIX;
strcpy(serv_addr.sun_path, "/tmp/.X11-unix/X0");
int servlen = 17 + sizeof(serv_addr.sun_family);
int err = connect(sockfd, (struct sockaddr*)&serv_addr, servlen);
char arr[] = {108, 0, // 'l' for little-endian
11, 0, // X version
0, 0, // X minor version
18, 0, // length of auth protocol name
16, 0, // length of auth protocol data
0, 0, // padding
77, 73, 84, 45, 77, 65, 71, 73, 67, 45, 67, 79, 79, 75, 73, 69, 45, 49, // MIT-MAGIC-COOKIE-1
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
223, 88, 218, 121, 215, 6, 185, 105, 137, 80, 105, 252, 49, 109, 38, 200, // data from .Xauthority
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
ssize_t bytes_written = write(sockfd, arr, sizeof(arr));
printf("%d\n", bytes_written);
uint8_t buf[5000];
ssize_t bytes_read = read(sockfd, buf, 5000);
printf("%d\n", bytes_read);
unsigned char k;
for(k = 0; k < 40; k++) {
printf("%c", buf[k]);
}
return 0;
}
The X server responds all right but it gives me an authentication failed message with "Invalid MIT-MAGIC-COOKIE-1 key" as the reason. The key I'm giving is the same as the one in my .Xauthority file (df58da79d706b969895069fc316d26c8, in case anyone wants to check!) Is there something else I'm missing?
you have too much of padding zeroes. should be:
char arr[] = {108, 0, // 'l' for little-endian
11, 0, // X version
0, 0, // X minor version
18, 0, // length of auth protocol name
16, 0, // length of auth protocol data
0, 0, // padding
77, 73, 84, 45, 77, 65, 71, 73, 67, 45, 67, 79, 79, 75, 73, 69, 45, 49, // MIT-MAGIC-COOKIE-1
0, 0, // two bytes to pad 18-byte MIT-MAGIC-COOKIE-1 to factor of 4 - 20
223, 88, 218, 121, 215, 6, 185, 105, 137, 80, 105, 252, 49, 109, 38, 200 // data from .Xauthority
}; // no need for more padding, auth data is 16 bytes long, factor of 4
From page 140 of X11 protocol:
Information sent by the client at connection setup:
1 byte-order
▶x42 MSB first
▶x6C LSB first
1 unused
2 CARD16 protocol-major-version
2 CARD16 protocol-minor-version
2 n length of authorization-protocol-name
2 d length of authorization-protocol-data
2 unused
n STRING8 authorization-protocol-name
p unused, p=pad(n)
d STRING8 authorization-protocol-data
q unused, q=pad(d)