Navigation: Home =>Profil=>SeaTalk=>Part3
Stand: 01.09.2003 |
For bidirectional communication the circuit has to be extended by
a second transistor:
A PC-board may be obtained from Frank Wallenwein.
The following piece of C-code gives an example of how to collect
and process SeaTalk data. It monitors the SeaTalk bus and echoes the SeaTalk
datagrams in hexadecimal notation to the screen.
#include <stdio.h>
/* Set Address of Serial Port: COM1=0x3F8, COM2=0x2F8 */
#define PORT 0x3F8
unsigned int collision_ctr,overrun_ctr;
char buffer[256],in_ptr,out_ptr,limit_ptr;
char line_status_reg,receiver_buf,byte_ctr;
char hex[]="0123456789ABCDEF";
main() {
puts("SeaTalk Monitor Rev. 1.01 (c)2000
by Thomas Knauf\r\n");
/* Serial Port Initialization */
_outb( 0, PORT+1); /*IER Disable Interrupts */
_outb( 1, PORT+2); /*FCR Enable Fifo */
_outb(0x80, PORT+3); /*LCR Enable access to Divisor Latch
*/
_outb( 24, PORT ); /*DLL Set Baud Rate to 4800
LSB*/
_outb( 0, PORT+1); /*DLM Baud Rate Divisor MSB
*/
_outb(0x3B, PORT+3); /*LCR Stick Parity to 0, Enable Parity,
1 Stop bit, 8 bits/char */
_outb(0x0F, PORT+4); /*MCR Disable LOOP Mode */
_outb( 0, PORT+5); /*LSR Clear Error flags */
while(1) { /* Continous data processing loop */
if((line_status_reg= _inb(PORT+5)) & 1) { /* LSR
New SeaTalk Data received ? */
receiver_buf=_inb(PORT); /* RBR
Read SeaTalk Data Byte */
if(line_status_reg & 2) overrun_ctr++;
/* PC too slow, should not happen */
if(line_status_reg & 4) { /* Parity
bit set => Command Byte */
if(byte_ctr) {
/* More characters expected => Collision */
in_ptr=limit_ptr;
/* Discard last datagram, restart from beginning */
collision_ctr++;
/* Count collision events */
}
buffer[in_ptr++]='\r';
/* Put new command on new line */
buffer[in_ptr++]='\n';
byte_ctr=255;
/* Undefined datagram length, wait for next character */
} else
if(byte_ctr==254)
/* Attribute byte ? */
byte_ctr=(receiver_buf
& 0xF) + 2; /* Read expected datagram length */
if(byte_ctr) {
/* Process valid data bytes, should always be true */
buffer[in_ptr++]=hex[receiver_buf
>> 4]; /* Convert Data to hex */
buffer[in_ptr++]=hex[receiver_buf
& 0xF];
buffer[in_ptr++]=' ';
/* Seperate by space */
if(! --byte_ctr) limit_ptr=in_ptr;
/* Complete datagram ready for output */
}
} else
if(out_ptr != limit_ptr)
/* Characters waiting for Output ? */
putc(buffer[out_ptr++],stdout);
/* Copy single character from buffer to screen */
else if(scr_csts()) break;
/* Query keyboard, terminate if any key hit */
}
printf("\r\nSeatalk Collisions : %5u",collision_ctr);
printf("\r\nUART Overrun Errors: %5u",overrun_ctr);
}
Compiled EXE-Files can be downloaded here as SEAMON1.EXE (using COM1:) or SEAMON2.EXE (using COM2:). They run in any MS-DOS environment. Redirecting the output logs data to a file (example: SEAMON1 > LOGFILE). Pressing any key terminates the program.