19 October 2015, 20:47 | #1 | |
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
\\.\pipe\WinUAE
Quote:
BTW I'm still curious about the "named pipe" stuff (sending input from windows to winuae keyboard) since it could be useful to automate some other things. So any info on that is appreciated. But perhaps it is better if I start a new thread about that? |
|
20 October 2015, 15:53 | #2 | ||
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
Some details and then a more specific version of the question I tagged on above.
The named pipe is Code:
\\.\pipe\WinUAE Toni wrote about commands for the named pipe here Quote:
Quote:
https://github.com/tonioni/WinUAE/bl...nputevents.def I posted to the autohotkey forum yesterday asking for help with writing to a named pipe from windows and got a line of code to try. But I haven't had success with it. I'm not sure if I'm formatting the string to send incorrectly or not. Toni can you give a few examples of whole strings to send to winuae's named pipe. For example what string to write to the named pipe to to pause emulation or what string to trigger the winuae keyboard event F. I have tried "EVT SPC_PAUSE 1" , "evt_SPC_PAUSE 1" and a few more without success. Again, maybe one of these is correct and the problem lies with the autohotkey language method I'm trying. But to test further I want to make sure I get the string to send right first. |
||
21 October 2015, 12:13 | #3 |
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
I took another quick stap at it, this time with python
Code:
f = open('\\.\pipe\WinUAE', 'w', 0) f.write("EVT_SPC_PAUSE true") Code:
No such file or directory: '\\.\\pipe\\WinUAE' |
21 October 2015, 13:27 | #4 |
Registered User
Join Date: Mar 2013
Location: Slovenia
Posts: 138
|
Did you try escaping the string in python (\\\\. ....) or using python raw string (r' ... ')?
Taking a quick look here (http://stackoverflow.com/questions/1...arp-and-python), it looks like you will also need to use the win32file module, but I've never worked with pipes on windows, so I'm not sure. |
21 October 2015, 15:39 | #5 |
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
Escaping like this
Code:
f = open('\\\\.\\pipe\\WinUAE', 'w', 0) f.write('SPC_PAUSE 1') (I've tried a bunch of variations of the string to send e.g. SPC_PAUSE 1, SPC_PAUSE true, SPC_PAUSE, with and without "EVT " or "EVT_" prefix) I'll try to test the win32 python method next. |
21 October 2015, 20:42 | #6 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
ipctester: http://www.winuae.net/files/stuff/ipctester.zip
Attach the dump file if you still managed to crash winuae with your own program. (or attach the program that crashes it) |
21 October 2015, 21:22 | #7 |
Registered User
Join Date: Mar 2013
Location: Slovenia
Posts: 138
|
Hi,
I tried this myself (might come handy someday!), here's what I came up with: - you should use win32file module (part of Python Win32 extensions), since using plain open() on a named pipe doesn't work so well (it does open, but windows being windows, the named pipe is 'special', not like in unix) - win32file API: http://docs.activestate.com/activepy...win32file.html - use ipctester.cpp & uaeipc.cpp as a guide - the ipc_restore, ipc_quit, ipc_debug and ipc_event commands work - none of the events or config options I tried to set were recognized (I got a 404 response), I don't know why - I successfully used the debug commands, those work OK Here's the code snippets, if it's any help: - import win32file module: Code:
from win32file import * Code:
up = CreateFile(r'\\.\pipe\WinUAE', GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, None) Code:
WriteFile(up, 'ipc_restore\0', None) Code:
ReadFile(up, 4096) # or to directly print the result: print ReadFile(up, 4096)[1] Code:
CloseHandle(up) Code:
WriteFile(up, 'DBG ea\0') print ReadFile(up, 4096)[1] toni: what is the proper syntax of ipc message to, for example, set config value nr_floppies? I tried lots of variations like 'CFG nr_floppies=1', but I always get a 404 response. Last edited by TCD; 23 October 2015 at 11:01. Reason: Back-to-back posts merged. |
21 October 2015, 22:00 | #8 | |
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
Toni: Thank you. With ipctester.exe I can connect
Code:
Connected to '\\.\pipe\WinUAE' ready Code:
ipc_event 200 SPC_PAUSE 1 404 SPC_PAUSE 1 404 To make use of this in some scripts I'll next try to figure out how to expand the ipctester stuff so I can silently on the command line run something with a parameter , e.g. "SPC_PAUSE 1", and have it autoconnect to the winUAE pipe, write "ipc_event" and if return 200 write the parameter. I don't know any C++ so I'll try with python but if something like that is easy to add on to the ipctester code then I'm all ears. chaos: thank you. I will follow try to follow those steps. Ipctester returned 404 even when the command worked so are you sure your commands didn't work? Quote:
|
|
21 October 2015, 22:15 | #9 | ||
Registered User
Join Date: Mar 2013
Location: Slovenia
Posts: 138
|
Quote:
Quote:
With the blocking comment, I just wanted to warn you that if you read from the pipe when it's empty, the read call will block - that is, your program will freeze. There is probably a way to tell the read function to not block ... |
||
21 October 2015, 22:40 | #10 |
Registered User
Join Date: Mar 2013
Location: Slovenia
Posts: 138
|
Since I have nothing better to do , here's a python script that will send command line arguments to WinUAE through the named pipe, and print the status returned.
Use it like this: uae_ipc.py EVT SPC_PAUSE 1 (for event) uae_ipc.py DBG ea (for debugger) ... |
21 October 2015, 23:39 | #11 | |||
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
Quote:
Quote:
A comment in your python source says Quote:
Code:
uae_ipc.py "EVT SPC_PAUSE 1" "EVT SPC_SCREENSHOT 1" edit: Aha, now I get it your code there makes unquoted spaced input like this Code:
uae_ipc.py EVT SPC_PAUSE 1 While you had nothing better to do I also had nothing better to do so I tried to expand the ipctester c++ code to accept command line parameters. Only problem is I don't know any c++. But I've pieced something together through googling a lot that kind of works. It adds this at line 74 in ipctester.cpp Code:
if (argc >= 2) { int i; for (i=1;i<argc;i++) { DWORD ret; if (strlen(argv[i]) == 0) continue; threadmode_in = 0; while (threadmode_out) Sleep(10); if (!WriteFile(p, argv[i], strlen (argv[i]) + 1, &ret, NULL)) { printf("WriteFile() failed, err=%d\n", GetLastError()); return 0; } threadmode_in = 1; } return 0; } Code:
Couldn't open pipe '\\.\pipe\WinUAE' err=2 Last edited by boir; 21 October 2015 at 23:49. |
|||
22 October 2015, 11:01 | #12 |
Registered User
Join Date: Mar 2013
Location: Slovenia
Posts: 138
|
I don't have a C compiler for windows, sorry. But you can compile python into an executable, it's not pretty though (many files).
I attached a compiled exe of my script, you will probably need to keep that directory with all the files in it. |
22 October 2015, 13:12 | #13 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
Just a guess: you always talk about opening the pipe, but I don't see that you close it anywhere. Maybe you can only open it for a limited number of times and then have to close one of the previous attempts (better always close it before you leave the program).
At least the documentation of CreateFile says "When an application is finished using the object handle returned by CreateFile, use the CloseHandle function to close the handle". |
22 October 2015, 20:17 | #14 |
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
I added a single line (" Sleep(400); ") and haven't seen the issue in any test after that, even when running the exe multiple times in sequence.
Code:
if (argc >= 2) { int i; for (i=1;i<argc;i++) { DWORD ret; if (strlen(argv[i]) == 0) return 0; threadmode_in = 0; while (threadmode_out) Sleep(10); if (!WriteFile(p, argv[i], strlen (argv[i]) + 1, &ret, NULL)) { printf("WriteFile() failed, err=%d\n", GetLastError()); return 0; } Sleep(400); //avoids pipe inaccessible issue threadmode_in = 1; } return 0; } |
22 October 2015, 21:11 | #15 | |
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
There is now also a working function for the Autohotkey language here.
Autohotkey makes it easy to do macros, multi key combination hotkeys and so on. Below is an example where a joypad button does warp in WinUAE while the button is pressed and stops warp on button release (instead of WinUAE default behaviour one press to toggle on and one press to toggle off). Code:
#IfWinActive, ahk_Exe WinUAE.exe Joy4:: ;Y button on the xbox360 controller GetKeyState, state, %A_ThisHotkey%, P if state = U return WinUAE("EVT SPC_WARP 1") KeyWait, %A_ThisHotkey% ;wait for button release WinUAE("EVT SPC_WARP 1") return #IfWinActive WinUAE(command) { VarSetCapacity(result, 4096) if !DllCall("CallNamedPipe", "str", "\\.\pipe\WinUAE" , "astr", command, "int", StrPut(command, "cp0") , "ptr", &result, "int", 4096 , "uint*", bytesRead, "uint", 1) throw Exception("CallNamedPipe failed with error " A_LastError) return RegExReplace(StrGet(&result, bytesRead, "cp0"), "\R$") } Toni: the writer of the autohotkey function, lexikos, says he ran into a bug with unicode and ipc in WinUAE (that the autohotkey function then was adapted the work around). He wrote Quote:
https://github.com/tonioni/WinUAE/bl...aeipc.cpp#L347 |
|
22 October 2015, 21:28 | #16 | ||
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Quote:
Quote:
|
||
22 October 2015, 21:44 | #17 |
Registered User
Join Date: Aug 2015
Location: europe
Posts: 17
|
|
23 October 2015, 08:57 | #18 | |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,505
|
Quote:
But something like autohotkey can still be useful for very complex sequences and named pipe interface is much better than key injection. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Unable to type pipe and backslash characters | gryf | support.FS-UAE | 7 | 04 August 2015 23:47 |
[AmigaDOS] How to pipe output to argument? | mrrhq | New to Emulation or Amiga scene | 5 | 11 May 2015 11:34 |
Amiga, vfork(), and pipe() | tygre | Coders. General | 5 | 03 December 2011 01:35 |
Pipe Dream (original) | MethodGit | request.Old Rare Games | 3 | 16 December 2010 22:17 |
Pipe Mania - AGA-fixed/1-filed by Galahad | MethodGit | request.Old Rare Games | 10 | 28 May 2009 01:34 |
|
|