Hi,
i'm working on a driver for the ORGA ECO 5000 cardreader.
But the "serial.c" - file (provided with the CT-skeleton sources) doesn't
seem to work.
I get a handle to "/dev/ttyS0" for example, but other functions (like
tcgetattr(handle, ...)) shutdown with an error (-1).
Where is the problem ??
I changed some part of the sources (eliminated MAC support), but this is (I
hope) not the reason.
I also have to set the RTS-Line off to communicate with the cardreader.
Otherwise i don't get a response. (ACK or NACK) Which parameters do i have to
change or set in the termios-structure.
I attached the modified "serial.c"-file. Please take a look at it.
If there are any questions, please contact me!!
Thank you so much for your support. ;->
Bye, Frank
/*
* NAME:
* serial.c -- Copyright (C) 1998 David Corcoran
*
* DESCRIPTION:
* This provides Unix/Mac serial driver support
*
* AUTHOR:
* David Corcoran, 7/22/98
*
* Modified by Mark Hartman for Macintosh support, 7/15/98
*
* LICENSE: See file LICENSE.
*
*/
#include/* Standard Includes */
#include
#include
#include
#include
#include
#include "serial.h"
#include
#include
#include
#include
struct IO_Specs {
HANDLE handle;
BYTE baud;
BYTE bits;
char parity;
long blocktime;
} ioport;
static char _rcsid[] UNUSED = "$Id$";
/*
* InititalizePort -- initialize a serial port
* This functions opens the serial port specified and sets the
* line parameters baudrate, bits per byte and parity according to the
* parameters. If no serial port is specified, the Communications
* Manager's dialog is invoked to permit the user to select not only
* the port, but all the other (baud/bits/parity) details as well.
* Selections made by the user in this case will override the
* parameters passed.
*/
bool
IO_InitializePort(int baud, int bits, char parity, char* port)
{
/* UNIX SERIAL SUPPORT */
HANDLE handle;
struct termios newtio;
handle = open(port, O_RDWR); /* Try user input depending on port */
if (handle < 0) { /* Problems with /dev/smartcard */
return -1;
}
if(tcgetattr(handle, &newtio)<0) {
close(handle);
return -100;
};
/*
* Set the baudrate
*/
switch (baud) {
case 9600: /* Baudrate 9600 */
newtio.c_cflag = B9600;
break;
case 19200: /* Baudrate 19200 */
newtio.c_cflag = B19200;
break;
default:
close(handle);
return -2;
}
/*
* Set the bits.
*/
switch (bits) {
case 5: /* Five bits */
newtio.c_cflag |= CS5;
break;
case 6: /* Six bits */
newtio.c_cflag |= CS6;
break;
case 7: /* Seven bits*/
newtio.c_cflag |= CS7;
break;
case 8: /* Eight bits*/
newtio.c_cflag |= CS8;
break;
default:
close(handle);
return -3;
}
/*
* Set the parity (Odd Even None)
*/
switch (parity) {
case 'O': /* Odd Parity */
newtio.c_cflag |= PARODD | PARENB | INPCK;
break;
case 'E': /* Even Parity */
newtio.c_cflag &= (~PARODD);
newtio.c_cflag |= PARENB | INPCK;
break;
case 'N': /* No Parity */
break;
default:
close(handle);
return -4;
}
/*
* Setting Raw Input and Defaults
*/
newtio.c_cflag |= CREAD|HUPCL|CLOCAL;
newtio.c_iflag &= ~(IGNPAR|PARMRK|INLCR|IGNCR|ICRNL);
newtio.c_iflag |= BRKINT;
newtio.c_lflag &= ~(ICANON|ECHO|ISTRIP);
newtio.c_cflag |=CRTSCTS;
newtio.c_iflag &= ~(IXON | IXOFF | IXANY);
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VMIN] = 1;
newtio.c_cc[VTIME] = 0;
if (tcflush(handle, TCIFLUSH) < 0) { /* Flush the serial port*/
close(handle);
return -5;
};
if(tcsetattr(handle, TCSANOW, &newtio) < 0) {
close(handle);
return -6;
};
ioport.handle = handle; /* Record the handle */
ioport.baud = baud; /* Record the baudrate */
ioport.bits = bits; /* Record the bits */
ioport.parity = parity; /* Record the parity */
ioport.blocktime = 1;/* Default Beginning Blocktime */
return TRUE;
}
HANDLE
IO_ReturnHandle() {
return ioport.handle; /* Return the current used handle*/
}
int
IO_UpdateReturnBlock(int blocktime) {