I attach a script for control over TCP/IP: AV receiver Pioneer (vsx-921 in my case) and IR transmitter (which is controlled by WinLirc) for turn on/off TV, Sat and light.
Users of laptops from Asus will find a familiar image, notified of the results of execution.
After pressing the registered hot keys, a connection is established with Pioneer or WinLirc, a command is sent, a response is received, and a small picture and response status is displayed.
Perhaps the script still needs to be fine-tuned, but overall it works. Perhaps somewhere there is not the most correct code, this is my first script ...
Code
Code: Select all
; Some information about controlling Pioneer receivers via TCP : https://github.com/rwifall/pioneer-receiver-notes/blob/master/README.md
; About the interaction with Lirc/WinLirc via TCP is easier to read in the description for Lirc: http://www.lirc.org/html/irsend.html
; Gate - controlled device, it can be Pioneer or device from Lirc/WinLirc config
; SendText - command text, for example "mz" (Pioneer) or "send_once RemoteName buttonName repeats" (Lirc/WinLirc)
; SendCount - the number of repeat SendText, for example the Pioneer volume command "vu" changes the volume by 0.5 dB,
; if you repeat 5 times, then at once you can change to 2.5 dB
Menu, Tray, Icon, images\RemoteControl.ico, 1
PioneerIP := "192.168.1.XX" ; replace with your value
PioneerPort := 8102
LircIP := "192.168.1.XX" ; replace with your value
LircPort := 8765
SendCount := 1
<^F1:: ; Pioneer On/Off
Gate := "Pioneer"
SendText := "pz`r`n"
ExpectResp := "PWR"
Gosub Exposition
return
<^F2:: ; Pioneer Input - Radio
Gate := "Pioneer"
SendText := "02fn`r`n"
ExpectResp := "FN"
Gosub Exposition
return
<^F3:: ; Lirc - Sat On/Off
Gate := "Sat"
SendText := "send_once SatReciever Power 1`r`n"
ExpectResp := "BEGIN"
Gosub Exposition
return
<^F4:: ; Pioneer Input - Sat
Gate := "Pioneer"
SendText := "10fn`r`n"
ExpectResp := "FN"
Gosub Exposition
return
<^F5:: ; Lirc - TV On/Off
Gate := "TV"
SendText := "send_once TV Power 1`r`n"
ExpectResp := "BEGIN"
Gosub Exposition
return
<^F8:: ; Pioneer Input - Schuppen
Gate := "Pioneer"
SendText := "25fn`r`n"
ExpectResp := "FN"
Gosub Exposition
return
<^F10:: ; Pioneer Volume Mute
Gate := "Pioneer"
SendText := "mz`r`n"
ExpectResp := "MUT"
Gosub Exposition
return
<^F11:: ; Pioneer Volume Down
if count > 0
{
count++
return
}
count = 1
SetTimer, IntroductionDown, 600
return
IntroductionDown:
SetTimer, IntroductionDown, Off
Gate := "Pioneer"
SendText := "vd`r`n"
ExpectResp := "VOL"
SendCount := count * 5
count = 0
Gosub Exposition
return
<^F12:: ; Pioneer Volume Up
if count > 0
{
count++
return
}
count = 1
SetTimer, IntroductionUp, 600
return
IntroductionUp:
SetTimer, IntroductionUp, Off
Gate := "Pioneer"
SendText := "vu`r`n"
ExpectResp := "VOL"
SendCount := count * 5
count = 0
Gosub Exposition
return
<^<!Right:: ; Pioneer Next Radio
Gate := "Pioneer"
SendText := "tpi`r`n"
ExpectResp := "PR"
Gosub Exposition
return
<^<!Left:: ; Pioneer Prev Radio
Gate := "Pioneer"
SendText := "tpd`r`n"
ExpectResp := "PR"
Gosub Exposition
return
<^<+F1:: ; Lirc - Lamp Main_on/Off
Gate := "Lamp"
SendText := "send_once Lamp Main_on/Off 1`r`n"
ExpectResp := "BEGIN"
Gosub Exposition
return
Exposition:
if WinExist("RemoNote") ;check if another process is running, otherwise sleep
{
Loop, 10
{
Sleep 500
if !WinExist("RemoNote")
break
}
}
Device := (Gate = "Lamp" or Gate = "TV" or Gate = "Sat") ? "Lirc" : "Pioneer"
IPAddress := %Device%IP
Port := %Device%Port
hModule := DllCall("LoadLibrary", "Str", "Ws2_32.dll", "Ptr")
socket := Connect(IPAddress,Port)
if socket = -1 ; if the error is a message, clear the connection, return to listening to the keys
{
MsgBox % "Connect error - " DllCall("Ws2_32\WSAGetLastError")
DllCall("Ws2_32\WSACleanup")
return
}
Gosub Notiffication
Gosub SendData
return
Connect(IPAddress,Port)
{
VarSetCapacity(wsaData, 32)
DllCall("Ws2_32\WSAStartup", UShort, 0x0002, UInt, &wsaData)
socket := DllCall("Ws2_32\socket", Int, 2, Int, 1, Int, 6)
VarSetCapacity(sockaddr, 16)
NumPut(2, sockaddr, 0, 2)
NumPut(DllCall("Ws2_32\htons", UShort, Port), sockaddr, 2, UShort)
NumPut(DllCall("Ws2_32\inet_addr", AStr, IPAddress), sockaddr, 4)
if DllCall("Ws2_32\connect", UInt, socket, UInt, &sockaddr, Int, 16)
return -1
return socket
}
SendData:
Critical
SendLen := StrLen(SendText)
DllCall("Ws2_32\WSAAsyncSelect", UInt, socket, UInt, WinExist("A"), UInt, 0x5555, Int, 1)
OnMessage(0x5555, "ReceiveData")
loop, %SendCount%
{
if TruSend := DllCall("Ws2_32\send", UInt, socket, AStr, SendText, Int, SendLen, Int, 0) <> SendLen
MsgBox % "Error. Was sent: " TruSend "`n" SendText SendLen "`nОшибка: " DllCall("Ws2_32\WSAGetLastError")
Sleep, 100 ; 100 ms interval between instruction for Pioneer
}
return
ReceiveData(socket,event)
{
global ExpectResp
Critical
ReceivedDataSize := 1024
if event=1
{
VarSetCapacity(ReceivedData, ReceivedDataSize, 0)
DllCall("Ws2_32\recv", UInt, socket, Str, ReceivedData, Int, ReceivedDataSize, Int, 0)
ReceivedData := StrGet(&ReceivedData,"cp0")
; If there is a required answer, disable data reception, because Pioneer can give a lot of answers
if ReceivedData ~= ".*" ExpectResp
DllCall("Ws2_32\WSAAsyncSelect", UInt, socket, UInt, WinExist("A"), UInt, 0, Int,0)
}
Debriefing(ReceivedData)
}
Debriefing(ReceivedData)
{
global Gate, ExpectResp
if Gate = Pioneer
{
Loop, parse, ReceivedData, `n, `r
{
if A_LoopField ~= ExpectResp
ReceivedData := RegExReplace(A_LoopField,ExpectResp)
}
if ExpectResp = VOL
ReceivedData := "Volume: " Round(-0.5*ReceivedData+80.5,1) " dB"
else if ExpectResp = MUT
ReceivedData := ReceivedData ? "Mute off" : "Mute"
else if ExpectResp = PWR
ReceivedData := ReceivedData ? "Pioneer: On" : "Pioneer: Off"
else if ExpectResp = FN
{
if ReceivedData = 02
ReceivedData := "FM Radio input"
else if ReceivedData = 10
ReceivedData := "Satellite input"
else if ReceivedData = 25
ReceivedData := "HDMI 2 input"
else if ReceivedData = 26
ReceivedData := "LAN input"
}
else if ExpectResp = PR
{
if ReceivedData = A01
ReceivedData := "1st FM station`n" ReceivedData " - 91,2"
else if ReceivedData = A02
ReceivedData := "2d FM station`n" ReceivedData " - 87,5"
else if ReceivedData = A03
}
}
else if (Gate = "Lamp" or Gate = "TV" or Gate = "Sat")
{
Loop, parse, ReceivedData, `n,`r
{
If A_LoopField ~= "^(|BEGIN|ERROR|\d|DATA)$"
continue
if A_LoopField ~= "send_once\s(.*)\d"
{
ReceivedData1 := RegExReplace(A_LoopField,"send_once\s(.*)\d","$1")
continue
}
if A_LoopField ~= "^END"
break
ReceivedData2 := A_LoopField
}
ReceivedData := ReceivedData1 "`n" ReceivedData2
}
Guicontrol,, LogEdit, %ReceivedData%
}
Notiffication:
Gui, Add, Picture, x0 y0 w218 h218 AltSubmit, images\%Gate%.png
Gui, font, cWhite s14,
Gui, Add, Text, x10 y152 r3 w198 Center BackgroundTrans vLogEdit,
Gui, Color, 777777
Gui +LastFound +Owner -Caption
WinSet, TransColor, 777777 235
Gui,Show, y795 w218 h218, RemoNote
SetTimer, GuiDestroy, -2000
return
GuiDestroy:
Gui, Destroy
DllCall("Ws2_32\WSACleanup")
DllCall("FreeLibrary", "Ptr", hModule)
SendCount := 1
return
- images.zip
- pictures
- (45.12 KiB) Downloaded 52 times