home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
dev
/
c
/
cmanual
/
devices
/
serialdevice
/
example4.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-12
|
34KB
|
758 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Devices Amiga C Club */
/* Chapter: Serial Device Tulevagen 22 */
/* File: Example4.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-04-26 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This example does not do anything, but it consists of */
/* several useful functions that you can use yourself after */
/* small modifications. The functions demonstrates all */
/* commands there exist for the serial device, so if you */
/* had problems in understanding how a command was used you */
/* can look here. */
#include <exec/types.h>
#include <exec/errors.h>
#include <devices/serial.h>
/* Declare the functions: */
UBYTE SetSerParams(
struct IOExtSer *ioreq, /* Pointer to our serial request block. */
ULONG buffer_length, /* Size of the Serial Device's own input buffer. */
ULONG baud_rate, /* Baud rate (read and write). [110 - 292000] */
ULONG break_time, /* Break time in microseconds. */
UBYTE read_length, /* Nr of bits, read (1-8). Parity not included. */
UBYTE write_length, /* Nr of bits, write (1-8). Parity not included. */
UBYTE stop_length, /* Nr of bits, stop (1 or 2). */
UBYTE serial_flags, /* Serial flags. */
ULONG extended_flags, /* Additional serial flags. */
UBYTE *eof_chars /* Pointer to an array containing eight end-of- */
/* file characters. */
);
void SerError( UBYTE error );
UBYTE SerWrite(
struct IOExtSer *ioreq, /* Pointer to our serial request block. */
BYTE *data, /* Pointer to the data you want to send. */
ULONG length /* The length of the data you want to send. */
);
UBYTE SerRead(
struct IOExtSer *ioreq, /* Pointer to our serial request block. */
BYTE *data, /* Where the data should be placed. */
ULONG length /* How many bytes you want to read. */
);
void SerWriteNoWait(
struct IOExtSer *ioreq, /* Pointer to our serial request block. */
BYTE *data, /* Pointer to the data you want to send. */
ULONG length /* The length of the data you want to send. */
);
void SerReadNoWait(
struct IOExtSer *ioreq, /* Pointer to our serial request block. */
BYTE *data, /* Where the data should be placed. */
ULONG length /* How many bytes you want to read. */
);
UBYTE SerBreak( struct IOExtSer *ioreq );
UBYTE SerClear( struct IOExtSer *ioreq );
UBYTE SerFlush( struct IOExtSer *ioreq );
UBYTE SerQuery( struct IOExtSer *ioreq );
UBYTE SerReset( struct IOExtSer *ioreq );
UBYTE SerStop( struct IOExtSer *ioreq );
UBYTE SerStart( struct IOExtSer *ioreq );
/* Very short main() module: */
void main();
void main()
{
printf( "See source code for more information..." );
}
/*************************************/
/* SERIAL DEVICE - SUPPORT FUNCTIONS */
/*************************************/
/* SetSerParams() sets the serial parameters. It initializes a IOExtSer */
/* structure, and does a SDCMD_SETPARAMS commad. If everything is OK it */
/* returns NULL, else an error number is returned. */
/* */
/* Synopsis: er = SetSerParams( io, bl, br, bt, rl, wl, sl, sf, ef, chr ); */
/* */
/* er: (UBYTE) SetSerParams() returns 0 if everything was OK, else */
/* an error value is returned. See function SerError() for more */
/* information. */
/* */
/* io: (struct IOExtSer *) Pointer to the serial request block you */
/* want to initialize. */
/* */
/* bl: (ULONG) Size of the internal serial buffer which will be used */
/* when you read data. Must be at least 512 (bytes), but more is */
/* recommended. The faster and more data you want to read, the */
/* bigger should the internal buffer be. Some recommended sizes: */
/* 512, 1024, 2048, 4096, 8192 or 16384. */
/* */
/* br: (ULONG) Baud rate. Can be anything between 110 and 292000. */
/* (Up to 292000 is all right for the hardware, but the software */
/* can not cope with this, especially since other tasks may be */
/* running at the same time. You should therefore not use baud */
/* rates above 31250.) Some recommended values: 110, 300, 1200, */
/* 2400, 4800, 9600, 19200 or 31250 (the last is a bit though). */
/* */
/* bt: (ULONG) Break time in micro seconds. All break requests will */
/* be set to this time. */
/* */
/* rl: (UBYTE) How many bits chould be read for each character. */
/* Usually 7 or 8 bits. */
/* */
/* wl: (UBYTE) How many bits chould be written for each character. */
/* Usually 7 or 8 bits. */
/* */
/* sl: (UBYTE) How many stop bits shoud be written or expected. */
/* Normally set to 1, but you may set it to 2 if rl/wl = 7. */
/* */
/* sf: (UBYTE) You may use the following serial flags: */
/* */
/* SERF_PARTY_ON Parity checking/writing is turned on. (The */
/* sum of all data bits are divided by two, and */
/* the remainder is the parity bit. If even */
/* parity is used the bit will be set to 1 if */
/* the remainder is even. If odd parity is used */
/* the parity bit will be set to 0 if the */
/* remainder is even. */
/* */
/* SERF_PARTY_ODD Set this flag if you want to use odd parity. */
/* (The default setting is even parity.) */
/* */
/* SERF_7WIRE This flag should only be used when you call */
/* the OpenDevice(), and not by this function. */
/* If the flag is set,