by haydndup » Thu Jul 21, 2011 8:24 pm
by haydndup
Thu Jul 21, 2011 8:24 pm
Hi there, thanks for the reply.
I was not using parity checking, but I updated RoBoIO anyway.
Maybe I missed a setting? In the BIOS I have the following configured:
COM3 -> IRQ10 -> 3E8
COM4 -> IRQ11 -> 2E8
IRQ10 and IRQ11 are set as "Available". I have tried using "Reserved" too. Also, IRQ3 and IRQ4 are reserved. What is the correct setting for this?
Are there any other settings that I need to check to use COM3 and COM4?
The output of "setserial -g /dev/ttyS*" is:
- Code: Select all
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: 16550A, Port: 0x03e8, IRQ: 10
/dev/ttyS3, UART: 16550A, Port: 0x02e8, IRQ: 11
That is identical to the output shown in the set up guide.
Also, I'm not sure if it's normal, but I have to rerun setserial every time the Roboard boots. Does setserial not save the configuration?
In terms of code, I have tried using both RoBoIO and Linux native COM.
The RoBoIO code I am using is this:
- Code: Select all
#include <stdio>
#include <unistd>
#include <string>
#include <stdlib>
#include <roboard>
int main ()
{
roboio_SetRBVer(RB_110);
if (io_Init() == -1)
{
printf("ERR: fail to initialize I/O lib (%s)!\nEnsure that you have root access.\n", roboio_GetErrMsg());
return 1;
}
if (com_Init(COM_PORT3, COM_FDUPLEX) == false)
{
printf("ERR: fail to initialize I/O lib (%s)!\n\n", roboio_GetErrMsg());
return 1;
}
com_SetFormat(COM_PORT3, COM_BYTESIZE8, COM_STOPBIT1, COM_NOPARITY);
com_SetBaud(COM_PORT3, COMBAUD_50BPS);
while(1){
if (com_Write(COM_PORT3, 0x07) == false)
{
printf ("Sending failed\n");
}else {
printf ("Sent: %i\n", 0x07);
}
printf("Received: %i\n", com_Read(COM_PORT3));
}
com_Close(COM_PORT3);
io_close();
return 0;
}
Instead of printing 7 back, it prints 65535 each time.
Then, I also tried to use a modification of acentw's code:
- Code: Select all
#include <stdio>
#include <unistd>
#include <termios>
#include <fcntl>
int main(void) {
unsigned char data[3] = {0xff, 0x00, 0xFE};
unsigned char rec[3] = {0};
int i;
int fp = open("/dev/ttyS2", O_RDWR | O_NOCTTY);
printf("open\n");
if(fp < 0) return 1;
termios term;
term.c_cflag |= CLOCAL | CREAD;
term.c_cflag &= ~(CSIZE);
term.c_cflag |= CS8; // 8 bits
term.c_cflag &= ~(PARENB); // no parity
term.c_cflag &= ~(CSTOPB); // 1 stopbit
cfsetospeed (&term, B9600); // output baudrate = 115200
cfsetispeed (&term, B9600); // input baudrate = 115200
term.c_iflag = IGNPAR; // No detect parity for input data.
term.c_oflag = 0;
term.c_lflag = 0;
term.c_cc[VTIME] = 10; // timeout = 1s
term.c_cc[VMIN] = 0;
tcflush(fp, TCIFLUSH);
tcsetattr(fp, TCSANOW, &term);
while(true) {
printf("%i \n", write(fp, data, 3));
read(fp, rec, 3);
for(i=0; i<3; i++) printf("%X ", rec[i]);
printf("\n");
}
close(fp);
return 0;
}
With this code, the output was always "0 0 0".
For both bits of code I joined COM3's TX and RX lines together, so I should be receiving what I was sending out. I have also tried using COM4 instead of COM3, and that didn't work either.
The only difference I can think of is that I am not using the kernel supplied by Roboard. What kernel options must be enabled for the RB's COM3 and COM4 to work? Could the kernel be causing this? Is there any definite way to test that the COM3 and COM4 ports are even working?
Thanks again.
Hi there, thanks for the reply.
I was not using parity checking, but I updated RoBoIO anyway.
Maybe I missed a setting? In the BIOS I have the following configured:
COM3 -> IRQ10 -> 3E8
COM4 -> IRQ11 -> 2E8
IRQ10 and IRQ11 are set as "Available". I have tried using "Reserved" too. Also, IRQ3 and IRQ4 are reserved. What is the correct setting for this?
Are there any other settings that I need to check to use COM3 and COM4?
The output of "setserial -g /dev/ttyS*" is:
- Code: Select all
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: 16550A, Port: 0x03e8, IRQ: 10
/dev/ttyS3, UART: 16550A, Port: 0x02e8, IRQ: 11
That is identical to the output shown in the set up guide.
Also, I'm not sure if it's normal, but I have to rerun setserial every time the Roboard boots. Does setserial not save the configuration?
In terms of code, I have tried using both RoBoIO and Linux native COM.
The RoBoIO code I am using is this:
- Code: Select all
#include <stdio>
#include <unistd>
#include <string>
#include <stdlib>
#include <roboard>
int main ()
{
roboio_SetRBVer(RB_110);
if (io_Init() == -1)
{
printf("ERR: fail to initialize I/O lib (%s)!\nEnsure that you have root access.\n", roboio_GetErrMsg());
return 1;
}
if (com_Init(COM_PORT3, COM_FDUPLEX) == false)
{
printf("ERR: fail to initialize I/O lib (%s)!\n\n", roboio_GetErrMsg());
return 1;
}
com_SetFormat(COM_PORT3, COM_BYTESIZE8, COM_STOPBIT1, COM_NOPARITY);
com_SetBaud(COM_PORT3, COMBAUD_50BPS);
while(1){
if (com_Write(COM_PORT3, 0x07) == false)
{
printf ("Sending failed\n");
}else {
printf ("Sent: %i\n", 0x07);
}
printf("Received: %i\n", com_Read(COM_PORT3));
}
com_Close(COM_PORT3);
io_close();
return 0;
}
Instead of printing 7 back, it prints 65535 each time.
Then, I also tried to use a modification of acentw's code:
- Code: Select all
#include <stdio>
#include <unistd>
#include <termios>
#include <fcntl>
int main(void) {
unsigned char data[3] = {0xff, 0x00, 0xFE};
unsigned char rec[3] = {0};
int i;
int fp = open("/dev/ttyS2", O_RDWR | O_NOCTTY);
printf("open\n");
if(fp < 0) return 1;
termios term;
term.c_cflag |= CLOCAL | CREAD;
term.c_cflag &= ~(CSIZE);
term.c_cflag |= CS8; // 8 bits
term.c_cflag &= ~(PARENB); // no parity
term.c_cflag &= ~(CSTOPB); // 1 stopbit
cfsetospeed (&term, B9600); // output baudrate = 115200
cfsetispeed (&term, B9600); // input baudrate = 115200
term.c_iflag = IGNPAR; // No detect parity for input data.
term.c_oflag = 0;
term.c_lflag = 0;
term.c_cc[VTIME] = 10; // timeout = 1s
term.c_cc[VMIN] = 0;
tcflush(fp, TCIFLUSH);
tcsetattr(fp, TCSANOW, &term);
while(true) {
printf("%i \n", write(fp, data, 3));
read(fp, rec, 3);
for(i=0; i<3; i++) printf("%X ", rec[i]);
printf("\n");
}
close(fp);
return 0;
}
With this code, the output was always "0 0 0".
For both bits of code I joined COM3's TX and RX lines together, so I should be receiving what I was sending out. I have also tried using COM4 instead of COM3, and that didn't work either.
The only difference I can think of is that I am not using the kernel supplied by Roboard. What kernel options must be enabled for the RB's COM3 and COM4 to work? Could the kernel be causing this? Is there any definite way to test that the COM3 and COM4 ports are even working?
Thanks again.