Hi.
I'm developing a new pay-machine for a company, but I have a big problem: the magnetic card reader for credit/debit cards.
I'ts a Hitachi-Omrom V4KF with serial-RS232 interface to PC.
C with Linux.
I try to write/read on/from V4KF with no action/response at all.
The manual says its syncs speed with first reset. Configuration is 8 bit data, even pariity. Always from manual, you send commands in ASCII text preceeded by a "C". No action. No response at all. I've changed reader, computer and cables. The same. None of the none.
No information in Google. None.
Anybody with experiencie in this kind of devices? I'm desperated becaus if I cant manage reader I had to left project loosing a lot of money... Help please...
Below is the C code I use...
Anybody knows something about this never-working-impossible-manage devices? Thanks in advance.
C code for send commands:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
int main (int argc,char *argv[]) {
int fd,n;
long baud;
struct termios options,tp;
baud=B38400;
fd=open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);
if (fd>=0) {
fcntl(fd,F_SETFL,FNDELAY);
} else {
printf("Imposible abrir /dev/ttyS0\n");
exit(-1);
}
if (tcgetattr(fd,&tp)<0) {
printf("No puedo leer los atributos del terminal.\n");
exit(-1);
}
printf("Atributos originales del serial:\n");
printf("iflag - 0%o; oflag - 0%o; cflag - 0%o; lflag - 0%o\n",
tp.c_iflag, tp.c_oflag, tp.c_cflag, tp.c_lflag);
options.c_cflag |= (CLOCAL|CREAD|baud);
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
// options.c_cflag|=CRTSCTS;
tcsetattr(fd,TCSAFLUSH,&options);
if (tcsetattr(fd,TCSANOW,&options)<0) {
printf("No puedo poner los atributos al terminal.\n");
exit(-1);
}
cfsetispeed(&options,baud);
cfsetospeed(&options,baud);
if (tcgetattr(fd,&tp)< 0) {
printf("No puedo leer los atributos del terminal.\n");
exit(-1);
}
printf ("Nuevos atributos del terminal:\n");
printf("iflag - 0%o; oflag - 0%o; cflag - 0%o; lflag - 0%o\n",
tp.c_iflag, tp.c_oflag, tp.c_cflag, tp.c_lflag);
printf("Inicializa lector.\n);
n=write(fd,"C00",3);
printf("Sent: %d\n",n);
printf("Sent: %d\n",n);
if (n<0) fputs("Error al escribir en el lector\n",stderr);
printf("Enciende LED.\n");
n=write(fd,"CP7",3);
printf("Sent: %d\n",n);
if (n<0) fputs("Error al escribir en el lector\n",stderr);
sleep(1);
printf("Parpadea LED.\n");
n=write(fd,"CP8",3);
printf("Sent: %d\n",n);
if (n<0) fputs("Error al escribir en el lector\n",stderr);
sleep(1);
printf("Apaga LED.\n");
n=write(fd,"CP6",3);
printf("Sent: %d\n",n);
if (n<0) fputs("Error al escribir en el lector\n",stderr);
close (fd);
return(0);
C code for read responses:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#define FALSE 0
#define TRUE 1
int main (int argc,char *argv[]) {
int fd,n,stop;
long baud;
char buf[255];
struct termios options,tp;
baud=B38400;
stop=FALSE;
fd=open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);
if (fd>=0) {
fcntl(fd,F_SETFL,FNDELAY);
} else {
printf("Imposible abrir /dev/ttyS0\n");
exit(-1);
}
if (tcgetattr(fd,&tp)< 0) {
printf("No puedo leer los atributos del terminal.\n");
exit(-1);
}
printf("Atributos originales del serial:\n");
printf("iflag - 0%o; oflag - 0%o; cflag - 0%o; lflag - 0%o\n",
tp.c_iflag, tp.c_oflag, tp.c_cflag, tp.c_lflag);
options.c_cflag |= (CLOCAL|CREAD|baud);
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
// options.c_cflag|=CRTSCTS;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSAFLUSH,&options);
if (tcsetattr(fd,TCSANOW,&options)<0) {
printf("No puedo poner los atributos al terminal.\n");
exit(-1);
}
cfsetispeed(&options,baud);
cfsetospeed(&options,baud);
if (tcgetattr(fd,&tp)< 0) {
printf("No puedo leer los atributos del terminal.\n");
exit(-1);
}
printf ("Nuevos atributos del terminal:\n");
printf("iflag - 0%o; oflag - 0%o; cflag - 0%o; lflag - 0%o\n",
tp.c_iflag, tp.c_oflag, tp.c_cflag, tp.c_lflag);
while (stop==FALSE) {
n=read(fd,buf,255);
buf[n]=0;
printf(":%s:%d\n",buf,n);
if (buf[0]=='z') stop=TRUE;
}
close(fd);
return(0);
}