--- In "sholling3" <> wrote:
>
> Hi,
>
> I'm trying to dig up the low-level C/C++ code (C# or Java would be
> helpful, too) to interface with the TS-7260 RS-485 port (we have
> requested full-duplex). So far, I have not found much
documentation on
> the subject, and very little sample code. Any suggestions on where
to
> start would be helpful. We're using TS-LINUX. Our objective is
driving
> a controller board.
>
> Thanks,
>
> Steve
>
Steve,
I tried to send you an email, but after a few days I got it back from
my server with a "delivery issue report", therefore let me post some
code here:
/* Code to setup your RS-485 port
************************************/
#define BAUDRATE_485 B115200
/* Variables */
int fd_485;
struct termios oldtio_485, newtio_485;
volatile unsigned long *rs485, *rs485_ck, *format;
/* RS-485 */
/* File descriptor opening */
fd_485 = open("/dev/ttyAM1", O_RDWR | O_NOCTTY);
if (fd_485 < 0) {
printf("Error opening ttyAM1 port\n");
return -1;
}
printf("Opening ttyAM1 port done\n");
/* Termios structure opening */
tcgetattr(fd_485, &oldtio_485);
bzero(&newtio_485, sizeof(newtio_485));
/* Memory assignments */
rs485 = (unsigned long *)mmap(0,4,PROT_READ|PROT_WRITE,
MAP_SHARED,fd_mem,0x22C00000);
rs485_ck = (unsigned long *)mmap(0,4,PROT_READ,
MAP_SHARED,fd_mem,0x22400000);
format = (unsigned char *)mmap(0,4,PROT_READ|PROT_WRITE,
MAP_SHARED,fd_mem,0x23000000);
/* RS-485 activation (0x01 = full duplex, 0x04-0x07 = half duplex) */
*rs485 = 0x00000007;
*format = 0x00000001;
/* Setting termios serial port parameters */
newtio_485.c_cflag = BAUDRATE_485 | CS8 | CLOCAL | CREAD | PARENB;
newtio_485.c_iflag = IGNPAR | IGNBRK;
newtio_485.c_oflag = OPOST;
newtio_485.c_lflag = 0;
newtio_485.c_cc[VTIME] = 1; /* max wait time from first
byte, in 0.1s units */
newtio_485.c_cc[VMIN] = 11; /* max bytes to wait for */
/* Flushing data on buffer */
tcflush(fd_485, TCIFLUSH);
/* Writing parameters */
tcsetattr(fd_485,TCSANOW,&newtio_485);
/* RS-485 PLD full-duplex enable */
mcr = AUTO485HD;
ioctl(fd_485, TIOC_SBCS485, &mcr);
printf("RS-485 configuration done\n");
/* Code to send bytes through RS-485
************************************/
/* use this function where you need it */
/* fd_485 is the file descriptor, buf_out_485 is the buffer with you
data, num_bytes is its length */
write(fd_485, buf_out_485, num_bytes);
Ciao,
Marco
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|