Console.device

4 posts / 0 new
Last post
Anonymous (not verified)
Anonymous's picture
Console.device

Hi Everyone!

Does anyone have any example of using the console.device under Os4. With the library interface style. I have found some examples on the internet but they are ancient and in old style. I only need a quick and easy example, that opens the console, writes some text to it, receives some text from it, and closes it would be great.

Thanks,

Yogi

salass00
salass00's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-02-03 11:27
@Yogi37 Generally you do not

@Yogi37

Generally you do not want to use console.device directly in a program. Pretty much the only reason for doing so is if you are writing a replacement/custom con-handler. If you just want to interact with the shell from your shell-launched program then you should stick to access uing Input() and Output() filehandles. For more advanced input you can always use the SetMode() function to switch the Shell to RAW mode:


dos.library/SetMode dos.library/SetMode
NAME
SetMode - Set the current behavior of a handler. (V36)
SYNOPSIS
int32 success = SetMode(BPTR fh, int32 mode);
FUNCTION
SetMode() sends an ACTION_SCREEN_MODE packet to the handler in
question, normally for changing a CON: handler to raw mode or
vice-versa. For CON:, use 1 to go to RAW: mode, 0 for CON: mode.
Note that 'ACTION_SCREEN_MODE' is a misnomer. What this packet
implies is that the console's mode of operation is switched
between line buffered (mode == 0) and single character (mode == 1)
input mode.
For V50, this packet name is aliased; ACTION_SINGLE_CHARACTER_MODE
(see dosextens.h)
INPUTS
fh - filehandle
mode - The new mode required.
RESULT
success - boolean; (zero or non-zero), zero means failure.
NOTES
This function is now callable from a task.
SetMode(0,...) is now safe, it just returns FALSE,
with IoErr() set to ERROR_REQUIRED_ARGUMENT_MISSING.
(if called from a process).
Previous versions of dos.lirary did NOT check for fh==0
and would cause an illegal memory access, if attempted.

If you still want to try using console.device there is some old code (from 2006) that I've written for command-line style calculator that I never finished. The commandline part using console.device is there, just not the calculating part. It even has some menus that are generated from a xml-like file format.

The source code for it is available here if you're interested:
https://dl.dropbox.com/u/26599983/clcalc-wip-src.7z

Yogi37 (not verified)
Anonymous's picture
Thanks alot for the help, and

Thanks alot for the help, and what I wanted to do with the console.device doesn't make sense after reading your post. But I appreciate the example code and it was very helpful. Thanks.

Yogi

PJS
PJS's picture
Offline
Last seen: 4 years 2 months ago
Joined: 2012-12-09 18:38
Hi Yogi, While I'm still

Hi Yogi,

While I'm still learning all this too, I can pass on some things I've
encountered...

To start with, I believe OS4 will automatically open a console window for an app
started from the Workbench (in Workbench mode) as soon as it starts calling
printf's.

By "Workbench mode", I mean that in the app's WBInfo second page, it is set to
"Start from" the Workbench. Of course, you can also set that to start from Shell
and turn off the prompting.

When your application does rely on the OS to automatically open the console for
it, you can define what kind of console window is opened for your app by
making a variable declaration like this at the start of your app:

const char* __stdiowin UNUSED = "CON:100/100/600/350/MyAppConsole/CLOSE";

The OS will find that defintion and open the console accordingly. When your
app closes, the window is closed.

Finally, you should also be able to "manually" open a console window for your
app by using the standard file open/read/write/close commands and a filename
string like the one above. This is a "high level" CON: access, as opposed to
the "low-level" console.device access Salass00 mentioned.

While I haven't gone down the route of opening the CON: too much, it's been
around forever and should be well documented elsewhere.

Good luck,

PJS

Log in or register to post comments