Hejsa.
Jeg forsøger at lave et program i linux til at kommunikere med en ekstern
enhed vha. com-porten.
Ved hjælp af portmon fra
www.sysinternals.com har jeg afluret følgende
IRP_MJ_CREATE Serial1 SUCCESS Options: Open
IOCTL_SERIAL_SET_WAIT_MASK Serial1 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD
BRK ERR RING
IOCTL_SERIAL_SET_QUEUE_SIZE Serial1 SUCCESS InSize: 4096 OutSize: 512
IOCTL_SERIAL_PURGE Serial1 SUCCESS Purge: TXABORT RXABORT TXCLEAR RXCLEAR
IOCTL_SERIAL_SET_TIMEOUTS Serial1 SUCCESS RI:-1 RM:0 RC:0 WM:0 WC:5000
IOCTL_SERIAL_GET_BAUD_RATE Serial1 SUCCESS
IOCTL_SERIAL_GET_LINE_CONTROL Serial1 SUCCESS
IOCTL_SERIAL_GET_CHARS Serial1 SUCCESS
IOCTL_SERIAL_GET_HANDFLOW Serial1 SUCCESS
IOCTL_SERIAL_GET_BAUD_RATE Serial1 SUCCESS
IOCTL_SERIAL_GET_LINE_CONTROL Serial1 SUCCESS
IOCTL_SERIAL_GET_CHARS Serial1 SUCCESS
IOCTL_SERIAL_GET_HANDFLOW Serial1 SUCCESS
IOCTL_SERIAL_SET_BAUD_RATE Serial1 SUCCESS Rate: 9600
IOCTL_SERIAL_CLR_RTS Serial1 SUCCESS
IOCTL_SERIAL_SET_DTR Serial1 SUCCESS
IOCTL_SERIAL_SET_LINE_CONTROL Serial1 SUCCESS StopBits: 1 Parity: NONE
WordLength: 8
IOCTL_SERIAL_SET_CHAR Serial1 SUCCESS EOF:1a ERR:0 BRK:0 EVT:0 XON:11
XOFF:13
IOCTL_SERIAL_SET_HANDFLOW Serial1 SUCCESS Shake:1 Replace:0 XonLimit:1024
XoffLimit:1024
IOCTL_SERIAL_SET_WAIT_MASK Serial1 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD
BRK ERR RING
IOCTL_SERIAL_SET_WAIT_MASK Serial1 SUCCESS Mask: RXCHAR TXEMPTY CTS DSR RLSD
BRK ERR RING
IOCTL_SERIAL_WAIT_ON_MASK Serial1 SUCCESS
IOCTL_SERIAL_GET_COMMSTATUS Serial1 SUCCESS
IOCTL_SERIAL_GET_PROPERTIES Serial1 SUCCESS
Jeg har også afluret kommunikations protokollen, mennår jeg sender noget ud,
får jeg intet svar tilbage, og jeg mistænker min opsætning af com-porten i
linux er skylden hertil. Jeg bruger følgende kode til at sætte porten op. Er
der nogen der har løst til at kommentere? (jeg har trippel tejkket at det er
den rigtige port jeg bruger (com2/ttyS1)
struct termios options;
fd= open(MODEMDEVICE, O_RDWR, O_NOCTTY, O_NDELAY);
if (fd==-1)
{
printf("Unable to open %s\n",MODEMDEVICE);
return fd;
}
printf("Opened %s\n",MODEMDEVICE);
fcntl(fd, F_SETFL,0);
tcgetattr(fd, &options);
tcgetattr(fd, &oldtio);
cfsetispeed(&options, BAUDRATE);
cfsetospeed(&options, BAUDRATE);
/*
* Enable the receiver and set local mode
*/
options.c_cflag |=(CLOCAL|CREAD);
/*
* No parity (8N1)
*/
options.c_cflag &=~PARENB;
options.c_cflag &=~CSTOPB;
options.c_cflag &=~CSIZE;
options.c_cflag |=CS8;
/*
* Line options (Raw Input)
*/
options.c_lflag &=~(ICANON | ISIG | ECHO | ECHOE);
/*
* Input options (disable software flow control)
*/
options.c_iflag &=~(IXON | IXOFF | IXANY);
/*
* Handles the input, ehich means that the characters sent from the
* device can be processed before they are read by read_link
*/
options.c_iflag &=~ICRNL;
/*
* Handles the oputput similarly (Raw output is selected)
*/
options.c_oflag &= ~OPOST;
options.c_cc[VINTR] = 0; /* Ctrl-c */
options.c_cc[VQUIT] = 0; /* Ctrl-\ */
options.c_cc[VERASE] = 0; /* del */
options.c_cc[VKILL] = 0; /* @ */
options.c_cc[VEOF] = 4; /* Ctrl-d */
options.c_cc[VTIME] = 0; /* inter-character timer unused */
options.c_cc[VMIN] = 1; /* blocking read until 1 character
arrives */
options.c_cc[VSWTC] = 0; /* '\0' */
options.c_cc[VSTART] = 0; /* Ctrl-q */
options.c_cc[VSTOP] = 0; /* Ctrl-s */
options.c_cc[VSUSP] = 0; /* Ctrl-z */
options.c_cc[VEOL] = 0; /* '\0' */
options.c_cc[VREPRINT] = 0; /* Ctrl-r */
options.c_cc[VDISCARD] = 0; /* Ctrl-u */
options.c_cc[VWERASE] = 0; /* Ctrl-w */
options.c_cc[VLNEXT] = 0; /* Ctrl-v */
options.c_cc[VEOL2] = 0; /* '\0' */
/*
* Flusshing the reg, and set the new options for the port
*/
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &options);
mvh Hans Odborg