1

MAC OS X (10.10) プログラムで、RS-485 シリアル通信用に termios を正しく設定するのに苦労しています (FTDI チップを搭載した starcom USB → RS-485 を使用しています)。

以下を設定する必要があります。

  • 1 開始ビット (0 ビット)
  • 8 データビット
  • 1 奇数パリティ ビット
  • 1 ストップ ビット (1 ビット)
  • 19200 ボー

通信はバイナリなのでストップキャラクタはありません。

現在、ほとんどの設定を行う方法を見つけましたが (以下のコードを参照)、開始ビットが必要であることを termios に伝える場所が見つかりませんでした。

@property(readwrite) int                   fileDescriptor;

_fileDescriptor = open(bsdPath, O_RDWR | O_NOCTTY | O_NONBLOCK);
ioctl(_fileDescriptor, TIOCEXCL)
fcntl(_fileDescriptor, F_SETFL, 0)
tcgetattr(_fileDescriptor, &gOriginalTTYAttrs)

struct termios options = gOriginalTTYAttrs;
cfmakeraw(&options);
struct termios* rawOptions = &options;

// Timeout 100 ms
rawOptions->c_cc[VTIME] = 1;
rawOptions->c_cc[VMIN] = 0;

// 8 bits
rawOptions->c_cflag |= CS8;

// Parity ODD
rawOptions->c_cflag |= PARENB;
rawOptions->c_cflag |= PARODD;

// Stop bit (I hope it means one stop bit)
rawOptions->c_cflag = rawOptions->c_cflag & ~CSTOPB;

// Flow control none 
rawOptions->c_cflag = rawOptions->c_cflag & ~CRTSCTS;
rawOptions->c_cflag = rawOptions->c_cflag & ~(CDTR_IFLOW | CDSR_OFLOW);
rawOptions->c_cflag = rawOptions->c_cflag & ~CCAR_OFLOW;

// Turn on hangup on close (NO IDEA WHAT IT DOES)
rawOptions->c_cflag |= HUPCL;
// Set local mode on (NO IDEA WHAT IT DOES)
rawOptions->c_cflag |= CLOCAL;
// Enable receiver (USEFUL, I GUESS)
rawOptions->c_cflag |= CREAD;
// Turn off canonical mode and signals (NO IDEA WHAT IT DOES)
rawOptions->c_lflag &= ~(ICANON /*| ECHO*/ | ISIG);

// Raw (binary output)
rawOptions->c_oflag &= ~OPOST;

// 19200 baud
cfsetspeed(rawOptions, 19200);

// Applying settings
tcsetattr(_fileDescriptor, TCSANOW, rawOptions);
4

0 に答える 0