Hallo in die Gemeinde,
ich habe da ein Problem mit einem Gerät. Es ist von der Seite: http://www.horter.de/i2c/i2c-usb-mod...b-modem_1.html
Ich wollte jetzt ein Programm schreiben, mit dem ich das Ding ansprechen kann, um dann per scripts in Linux die daran angeschlossenen gerät zu bedienen. Doch leider immer noch ohne erfolg, ich hoffe, dass mir hier jemand helfen kann.
es sollte zum ersten test mal die Version abgefragt werden.
Zeichenfolge ist: 0x11, 0x00, 0x04
0x04 ist auch das EOF auch bei der Rückgabe, und als Antwort solte:
0x1A, 0x03, 0x02, 0x00, 0x00, 0x04
erscheinen.
Schittstelle sollte auf 115200, 8N1, keine Flusskontrolle eingestellt sein.
ich habe das Programm von http://www.coding-board.de/board/showthread.php?t=18571
verwendet und modifiziert.
doch ohne erfolg!
bitte um Hilfe:
mein Code:
Code:
//*****************************************************************************
// Kontrollprogramm für die I2C HorterModem
//
// g++ -o {prog} {prog.c} && ./prog /dev/ttyUSB0
//*****************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/cdrom.h>
#include <signal.h>
#include <termios.h>
#include <string.h>
#include <stdbool.h>
int fd = 0;
int main(int argc, char** argv)
{
struct termios oldtios,options;
int currstat = 0;
if((argc < 2)||(argc > 3))
{
printf("Fehler: Ungültige Parameter-Anzahl.\n");
printf("Aufruf:\n");
printf(" %s <device>\n",argv[0]);
return 1;
}
/* Das Device öffnen */
if((fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY)) < 0)
{
printf("Fehler: Device \"%s\" kann nicht geöffnet werden.\n", argv[1]);
return 2;
}
tcgetattr(fd,&oldtios);
fcntl(fd, F_SETFL, 0);
if (tcgetattr(fd, &options) != 0) return(-1);
cfsetispeed(&options, B115200); /* setze 115200 bps */
cfsetospeed(&options, B115200);
options.c_cflag |= ~PARENB; /* kein Paritybit */
options.c_cflag &= ~CSTOPB; /* 1 Stopbit */
options.c_cflag &= ~CSIZE; /* 8 Datenbits */
options.c_cflag |= CS8;
options.c_cflag |= (CLOCAL | CREAD); /* CD-Signal ignorieren */
/* Kein Echo, keine Steuerzeichen, keine Interrupts */
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_oflag &= ~OPOST; /* setze "raw" Input */
options.c_cc[VMIN] = 0; /* warten auf min. 0 Zeichen */
options.c_cc[VTIME] = 10; /* Timeout 10 Sekunden */
tcflush(fd,TCIOFLUSH);
if (tcsetattr(fd, TCSAFLUSH, &options) != 0) return(-1);
char buffer[8];
// Version
buffer[0]=0x11;
buffer[1]=0x00;
buffer[2]=0x04;
printf("-Eingabe---------------------\n");
int i;
for (i=0; i<3; i++ )
{
printf("0x%02x ",buffer[i]);
}
printf("\n");
printf("-----------------------------\n");
// buffer schreiben
i = write(fd,buffer,3); //ist das OK?
printf("geschrieben: %i\n",i);
printf("-----------------------------\n");
int bb = 0;
int x = 0;
bool cmdOK=false;
char marr[10];
/*
ABHIER?
Lese des Gerätes, antwort solte sein:
0x1A, 0x03, 0x02, 0x00, 0x00, 0x04 (0x04 sollte EOT sein)
aber was ist da falsch?
*/
do
{
printf("\n");
printf("x=%d\n",x);
//if((bb = read( fd, &marr[x], sizeof( marr )-x )) > 0)
if((bb = read( fd, &marr, 5 )) > 0)
{
for (i=x;i<x+bb;i++)
{
printf("0x%02x ",marr[i]);
if (marr[i]==0x04) cmdOK=true;
}
x+=bb;
printf("\n");
printf("x=%d\n",x);
}
printf("bb=%d\n",bb);
}while(!cmdOK);
printf("-Ausgabe---------------------\n");
for (i=0; i<x; i++ )
{
printf("0x%02x ",marr[i]);
}
printf("\n");
printf("-----------------------------\n");
close(fd);
// TTYS0 auf alten Wert setzen
tcflush(fd,TCIOFLUSH);
if (tcsetattr(fd, TCSAFLUSH, &oldtios) != 0) return(-1);
return 0;
}
Lesezeichen