MAC und serielle Schnittstelle mit FDTI

OP #4559307
Lesenswert?
• ▲
▼
ich habe einen FDTI Wandler der unter Linux und MACOS Yosemite 10.10.4 
funktioniert, unter 10.10.5 nicht :-(
Hardwaremäßig ist einfach RXD und TXD gebrückt und im PC-Programm sende 
ich in einer Schleife mittels write die Zeichen A bis Z und versuche sie 
wieder zu empfangen mit read. Unter 10.10.5 kommt leider nichts zurück 
(timeout).
Das Öffnen mittels des untenstehenden Programms openCDC bringt keine 
Fehlermeldungen, ich habe sowohl ...tty.usbserial... als auch 
...cu.usbserial... probiert,
was könnte das Problem sein?
Interessanterweise funktioniert das Zeichensenden/Empfangen mit screen 
einwandfrei
1
// Return: <0 bei Fehler sonst handle
2
int openCDC(char *device, int baud, char stopbits)
3
{
4
  int fdser=0;
5

6
  /* das Device öffnen */
7
  if( (fdser = open(device, O_RDWR | O_NOCTTY | O_NDELAY)) < 0 )
8
  {
9
    if ( CDCverbose )
10
      printf("Fehler: Serielles Device %s kann nicht geoeffnet werden:%04x.\n", device, fdser);
11
    return -2;
12
  }
13

14
  if ( CDCverbose )
15
    printf("Serielles Device %s geöffnet:%04x.\n", device, fdser);
16

17
  //fcntl(fd, F_SETFL, 0);    // Set the file status flags
18
  fcntl(fdser, F_SETFL, FNDELAY);   // return imediate if no input available
19

20
  if ( tcgetattr(fdser,&oldtios)!=0 && CDCverbose )
21
    printf("tcgetattr failed\n");
22

23
  if (tcgetattr(fdser, &options) != 0)
24
    return -1;
25

26
  if ( CDCverbose )
27
  {
28
    printf("cflag:%x\n", options.c_cflag);
29
    printf("lflag:%x\n", options.c_lflag);
30
    printf("oflag:%x\n", options.c_oflag);
31
    printf("iflag:%x\n", options.c_iflag);
32
    printf("Serielles Device %s initialisiert.\n", device);
33
  }
34

35
  switch ( baud )
36
  {
37
    case 2400: baud = B2400; break;
38
    case 4800: baud = B4800; break;
39
    case 9600: baud = B9600; break;
40
    default: baud = B19200;
41
  }
42
  cfsetispeed(&options, baud);            /* setze baudrates */
43
  cfsetospeed(&options, baud);
44

45
  options.c_cflag &= ~PARENB;                /* Paritybit */
46
  if ( stopbits==1 )
47
    options.c_cflag &= ~CSTOPB;               /* 1 Stopbit */
48
  else
49
    options.c_cflag |= CSTOPB;               /* 2 Stopbits */
50
  options.c_cflag &= ~CSIZE;                /* 8 Datenbits */
51
  options.c_cflag |= CS8;
52
  options.c_cflag |= (CLOCAL | CREAD);      /* CD-Signal ignorieren */
53
  /* Kein Echo, keine Steuerzeichen, keine Interrupts */
54
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
55
  options.c_oflag &= ~OPOST;                /* setze "raw" output */
56
  options.c_iflag &= ~ICRNL;                /* CR nicht auf LF setzen */
57
  options.c_cc[VMIN]  = 0;                  /* warten auf min. 0 Zeichen */
58
  options.c_cc[VTIME] = 10;                 /* Timeout 10 Sekunden */
59

60
  tcflush(fdser,TCIOFLUSH);
61
  if (tcsetattr(fdser, TCSAFLUSH, &options) != 0)
62
  {
63
    if ( CDCverbose )
64
      printf("Fehler bei tcsetattr.\n");
65
    fdser = -1;
66
  }
67

68
  if ( CDCverbose )
69
  {
70
    printf("cflag:%x\n", options.c_cflag);
71
    printf("lflag:%x\n", options.c_lflag);
72
    printf("oflag:%x\n", options.c_oflag);
73
    printf("iflag:%x\n", options.c_iflag);
74
  }
75

76
  return fdser;
77
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren