how to talk to the serial and parallel ports through a C
Dan Nelson
dnelson at allantgroup.com
Wed Jun 11 23:52:06 PDT 2003
In the last episode (Jun 11), Bernard Dugas said:
> Not sure, but i'm using the serial port only to read and write
> electrical values, to command power relays. On mickey systems, serial
> drivers are far to complicated for that.
>
> Did anybody write a simple kernel module doing just that ?
>
> #include <sys/io.h>
> #include <stdio.h>
>
> void getComValues(int adr,unsigned char *p_TxdS3,
> unsigned char *p_DtrS4,unsigned char *p_RtsS7,
> unsigned char *p_CtsE8,unsigned char *p_DsrE6,
> unsigned char *p_RiE9,unsigned char *p_DcdE1)
> {
> unsigned char val3,val4,val6;
>
> val3=inb(adr+3);
> *p_TxdS3=(val3&64)>>6 ; //récupère le bit 6
>
> val4=inb(adr+4);
> *p_DtrS4=val4&1 ; //récupère le bit 0
> *p_RtsS7=(val4&2)>>1 ; //récupère le bit 1
>
> val6=inb(adr+6);
> *p_CtsE8=(val6&16)>>4 ; //récupère le bit 4
> *p_DsrE6=(val6&32)>>5 ; //récupère le bit 5
> *p_RiE9=(val6&64)>>6 ; //récupère le bit 6
> *p_DcdE1=(val6&128)>>7 ; //récupère le bit 7
Take a look at the tty(4) manpage; you should be able to open
/dev/cuaa0 (aka COM1), then use the TIOCMGET and TIOCMSET ioctls to get
and set the appropriate status bits, all from userland. The
comms/sredird port uses this to provide remote virtual serial ports
with perfect control.
--
Dan Nelson
dnelson at allantgroup.com
More information about the freebsd-questions
mailing list