Path: chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: Ed Federmeyer Newsgroups: scee.yaroze.freetalk.english Subject: Re: Datastream Cowboy Date: Sat, 11 Apr 1998 09:47:26 -0500 Organization: (no organization) Lines: 152 Message-ID: <352F827E.707C@charlie.cns.iit.edu> References: <01bd617f$2bef8420$413b63c3@default> Reply-To: fedeedw@charlie.cns.iit.edu NNTP-Posting-Host: charlie.cns.iit.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.0C-GZone (Win95; I) Pete wrote: > I'd like to create a program that streams data between the PC and the > playstation via the serial port (preferably asynchronously), by firstly > downloading the playstation app via siocons (or PScomUtil), executing it, > then shutting down siocons and taking control of the serial port for my own > use. So far I've not had much luck, I can send and receive data to siocons, > but when I shut it down and run my own PC app I get nothing from the > playstation, nor is any data sent received. If you are using Win95, the DOS window that ran siocons still holds onto the serial port, even after the DOS app exits. (This is true of any program that access any COM port in a DOS window.) I'd be surprised if another DOS program run in the same window didn't work, they always do for me. If you are trying to run another COMPORT program in a different DOS window, you need to exit the first "siocons" window first. (Don't know much about PScomUtil, I don't really use it.) Just to see if it worked, I ran "Win95 hyperterm" to talk to my Net Yaroze, and it worked: I got the prompt and could enter the various commands and get the expected output. > > If someone more knowledgeable than myself could give me a few pointers as > to where to start, and also a few examples of how to use ioctl() I would be > extremely grateful. I posted this to the SCEA newsgroup some time ago, but since there is some disk space problem they are working on, the older posts got removed (only temporarily, I hope!) Anyway, other people wanted to know how to read and write data to the tty port without blocking, so thier game would continue running even if a complete message wasn't received. Below is some sample code that shows this. Notice, it doen't use "ioctl()", but rather just opens the tty device in "non-blocking" mode. There's plenty more to be done with this to make it fully functional and efficient, and I can't remember offhand who was asking for the info, so if they have made progress with it, maybe they can let us know how thier project is coming along. BTW: Since then I've gotten an updated ".h" file that includes the real "isprint()" macro! So I don't need it anymore. :-) --- A code example below --- /* * Demo of NON-BLOCKING serial I/O on the Net Yaroze. * By: Ed Federmeyer */ #include #include #include /* * For some reason, the macros reference _ctype_, which * doesn't exist in the libps.a. So we do this the hard/kludgy way. * If someone knows the trick to making work in the * Yaroze-world, let me know... */ int isprint( char inchar ) { if ( (inchar >= 0x20) && (inchar <= 0x7E) ) { /* The character is 'printable'. */ return( 1 ); } /* The character is NOT 'printable'. */ return( 0 ); } int main( void ) { int ifd; int status; unsigned char inbyte; int toggle = 0; /* * Open the "tty" device in NON-BLOCKING mode, meaning when you * call "read" on it, if there are no characters, it will return * immediatly (with a status of "0", meaning "0" characters read), * instead of waiting for characters. */ ifd = open( "tty", O_RDWR | O_NBLOCK ); if ( ifd < 0 ) { printf( "Cannot open tty\n" ); return( -1 ); } printf( "Type characters (~ to exit):\n" ); while ( 1 ) { /* * Poll the 'tty' device to see if data has arrived. */ status = read( ifd, &inbyte, 1 ); if ( status < 0 ) { printf( "error in read. status=%d\n", status ); close( ifd ); return( -1 ); } if ( status == 1 ) { /* * Yay! Got a byte! Maybe do something cool like * build a protocol packet or something. We'll just * print it out for this demo though. */ printf( "got 0x%02X '%c'\n", inbyte, (isprint(inbyte) ? inbyte : '.') ); if ( inbyte == '~' ) { printf( "Exiting.\n" ); close( ifd ); return( 0 ); } } else if ( status == 0 ) { /* * Normally, do nothing. But for demonstration, * print some stuff so you know we're not blocked * on the 'read'. */ if ( ++toggle > 1000 ) { toggle = 0; printf( "." ); } } else { /* * I don't see how this could ever happen. :-) */ printf( "unexpected status=%d\n", status ); close( ifd ); return( 0 ); } } /* We should never really get here... */ close( ifd ); return( 0 ); }