English Amiga Board Amiga Lore


Go Back   English Amiga Board > Support > support.WinUAE

 
 
Thread Tools
Old 19 October 2015, 20:47   #1
boir
Registered User
 
Join Date: Aug 2015
Location: europe
Posts: 17
\\.\pipe\WinUAE

Quote:
Originally Posted by Toni Wilen View Post
Warp mode speed limit is done, will be in next beta, it was much simpler than I originally assumed.
Terrific!

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?
boir is offline  
AdSense AdSense  
Old 20 October 2015, 15:53   #2
boir
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
I found that on winuae github for ipctester.cpp . I guess that is the ipctester tool source but I still haven't found an ipctester.exe executable file.

Toni wrote about commands for the named pipe here
Quote:
- Named pipe also supports debugger commands, either using dbg_<name of debugger command> or first setting it to debugger mode using "ipc_debug" command. ("ipc_config" = config mode, "ipc_event" = event mode, "ipc_restore" = back to normal mode). Other direct commands are cfg_<config entry and evt_<event name>. (Works exactly same as uae-configuration commands)
and here
Quote:
"EVT <event name> <state value>"

<event name> = input event name, same as in config file and in source package inputevents.def. (KEY_A for example). Note that it supports all kinds of input events, it is not limited to keys.

Keys and button <state value> is either press (1) or release (0).
The inputevents list is at
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.
boir is offline  
Old 21 October 2015, 12:13   #3
boir
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")
but get the error message
Code:
No such file or directory: '\\.\\pipe\\WinUAE'
I tried with a variation of strings but from the error it looks like something else is missing. Is it necessary to in the Window's script also create a named pipe for writing to WinUAE to work? This is the first time I've had to do with named pipes so I'm probably missing some basic step.
boir is offline  
Old 21 October 2015, 13:27   #4
chaos
Registered User

chaos's Avatar
 
Join Date: Mar 2013
Location: Slovenia
Posts: 131
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.
chaos is offline  
Old 21 October 2015, 15:39   #5
boir
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')
was a step forward. The command still does not pause the emulation but when the WinUAE window is manually closed after sending the command from python there is a "WinUAE has stopped working" error message. So the command makes some kind of contact.

(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.
boir is offline  
Old 21 October 2015, 20:42   #6
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 42
Posts: 19,561
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)
Toni Wilen is online now  
Old 21 October 2015, 21:22   #7
chaos
Registered User

chaos's Avatar
 
Join Date: Mar 2013
Location: Slovenia
Posts: 131
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 *
- open the WinUAE pipe (the syntax is basically copied from ipctester.cpp):
Code:
up = CreateFile(r'\\.\pipe\WinUAE', GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, None)
- write into pipe:
Code:
WriteFile(up, 'ipc_restore\0', None)
- read return status (reads are blocking, careful)
Code:
ReadFile(up, 4096)
# or to directly print the result:
print ReadFile(up, 4096)[1]
- close pipe:
Code:
CloseHandle(up)
So, debug stuff works:
Code:
WriteFile(up, 'DBG ea\0')
print ReadFile(up, 4096)[1]
but not much else ... for now ...

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.
chaos is offline  
Old 21 October 2015, 22:00   #8
boir
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
I can send these commands to successfully pause the emulator and then unpause again
Code:
ipc_event
200
SPC_PAUSE 1
404
SPC_PAUSE 1
404
The initial "ipc_event" appears to be necessary. If I do "evt_SPC_PAUSE 1" or "SPC_PAUSE 1" without it the return is "501" and the emulator doesn't pause. Some more notes from my test: As long as the same winuae process is running I can close and restart ipctester without having to resend "ipc_event". But sending "ipc_event" again also doesn't break anything.

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:
(reads are blocking, careful)
What does that mean?
boir is offline  
Old 21 October 2015, 22:15   #9
chaos
Registered User

chaos's Avatar
 
Join Date: Mar 2013
Location: Slovenia
Posts: 131
Quote:
Originally Posted by boir View Post
The initial "ipc_event" appears to be necessary. If I do "evt_SPC_PAUSE 1" or "SPC_PAUSE 1" without it the return is "501" and the emulator doesn't pause.
You can also just use "EVT SPC_PAUSE 1".

Quote:
Ipctester returned 404 even when the command worked so are you sure your commands didn't work?
Looks like I misinterpreted that. "SPC_PAUSE 1" works for me too, and I also get a 404 response.

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 ...
chaos is offline  
Old 21 October 2015, 22:40   #10
chaos
Registered User

chaos's Avatar
 
Join Date: Mar 2013
Location: Slovenia
Posts: 131
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)
...
Attached Files
File Type: zip uae_ipc.zip (466 Bytes, 34 views)
chaos is offline  
Old 21 October 2015, 23:39   #11
boir
Registered User
 
Join Date: Aug 2015
Location: europe
Posts: 17
Quote:
You can also just use "EVT SPC_PAUSE 1".
Indeed

Quote:
Since I have nothing better to do , here's a python script
Very helpful, thank you.

A comment in your python source says
Quote:
# join all command line args (except scriptname)
but if I pass two parameters like this
Code:
uae_ipc.py "EVT SPC_PAUSE 1" "EVT SPC_SCREENSHOT 1"
only the first pause command is triggered. No real problem though since I can simply run two separate times.
edit: Aha, now I get it your code there makes unquoted spaced input like this
Code:
uae_ipc.py EVT SPC_PAUSE 1
into one single parameter.

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;
  }
It runs and accept command line parameters. But after a few runs I got the error
Code:
Couldn't open pipe '\\.\pipe\WinUAE' err=2
Maybe someone who in fact knows c++ can fix that and other problems with the code? A standalone executable could be useful for those who don't have python and pywin32 installed.

Last edited by boir; 21 October 2015 at 23:49.
boir is offline  
Old 22 October 2015, 11:01   #12
chaos
Registered User

chaos's Avatar
 
Join Date: Mar 2013
Location: Slovenia
Posts: 131
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.
Attached Files
File Type: zip uae-ipc-exe.zip (2.61 MB, 27 views)
chaos is offline  
Old 22 October 2015, 13:12   #13
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,510
Quote:
Originally Posted by boir View Post
But after a few runs I got the error
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".
thomas is offline  
Old 22 October 2015, 20:17   #14
boir
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;
  }
chaos: thanks, now there are multiple options for anyone who wants to do IPC with WinUAE then.
boir is offline  
Old 22 October 2015, 21:11   #15
boir
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:
... this version did not work correctly on the Unicode build because of a bug in WinUAE:
Code:
outlen = _tcsclen ((TCHAR*)ipc->outbuf) + sizeof (TCHAR);
For a string of n characters, the code writes n+2 bytes. Since each TCHAR is 2 bytes, the result is truncated. The developers of WinUAE might like to know about this error. Correct code might look like:
Code:
outlen = (_tcsclen ((TCHAR*)ipc->outbuf) + 1) * sizeof (TCHAR);
I think he is refering to this code location
https://github.com/tonioni/WinUAE/bl...aeipc.cpp#L347
boir is offline  
Old 22 October 2015, 21:28   #16
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 42
Posts: 19,561
Quote:
Originally Posted by boir View Post
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).
Input panel has multiple toggle options, including "keep pressed-toggle", there is no need for external programs.

Quote:
I think he is refering to this code location
Fixed, thanks.
Toni Wilen is online now  
Old 22 October 2015, 21:44   #17
boir
Registered User
 
Join Date: Aug 2015
Location: europe
Posts: 17
Quote:
Originally Posted by Toni Wilen View Post
Input panel has multiple toggle options, including "keep pressed-toggle", there is no need for external programs.
Wow, I can't believe I hadn't noticed the "Toggle" column. WinUAE is full of good surprises.
boir is offline  
Old 23 October 2015, 08:57   #18
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 42
Posts: 19,561
Quote:
Originally Posted by boir View Post
Wow, I can't believe I hadn't noticed the "Toggle" column. WinUAE is full of good surprises.
Yeah, there are lots of hidden features and options

But something like autohotkey can still be useful for very complex sequences and named pipe interface is much better than key injection.
Toni Wilen is online now  
AdSense AdSense  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 13:16.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.22469 seconds with 12 queries