how to talk to the serial and parallel ports through a C program
I was wondering if there was a good place to go to get programing examples on how to talk to the serial and parallel ports. I have looked in the developers handbook but have not any luck finding what I want. Any pointers would be appreciated Thanks Daniel Malaby voice:(510) 531-6500 Peritek Corp. fax: (510) 530-8563 5550 Redwood Road email: [EMAIL PROTECTED] Oakland, CA 94619 ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: how to talk to the serial and parallel ports through a C
Hi, I also did some programming on serial port to control pins with a c program under linux, but I didn't found any simple way to port it under freebsd. Any hint ? For instance, I need the equivalent of : inb(adr) outb(val,adr) iopl(n) ioperm(adr) from and in linux. Best regard, Bernard Dugas > -- > > Message: 32 > Date: Mon, 09 Jun 2003 09:44:28 -0700 > From: Dan Malaby <[EMAIL PROTECTED]> > Subject: how to talk to the serial and parallel ports through a C > program > To: [EMAIL PROTECTED] > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset="us-ascii"; format=flowed > > I was wondering if there was a good place to go to get programing examples > on how to > talk to the serial and parallel ports. I have looked in the developers > handbook but have not > any luck finding what I want. > > Any pointers would be appreciated > > Thanks > > Daniel Malaby voice:(510) 531-6500 > Peritek Corp. fax: (510) 530-8563 > 5550 Redwood Road email: [EMAIL PROTECTED] > Oakland, CA 94619 > > -- -- __ Bernard DUGAS | | | Technoparc Pays de Gex mailto:[EMAIL PROTECTED] | | 30 Rue Auguste Piccard Tel.: +33 450 205 105 | | FR 01630 St Genis Pouilly Fax : +33 450 205 106 | |_| ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: how to talk to the serial and parallel ports through a C
On Wed, 11 Jun 2003 08:15, Bernard Dugas wrote: > Hi, > > I also did some programming on serial port to control pins with a c > program under linux, but I didn't found any simple way to port it under > freebsd. Any hint ? > > For instance, I need the equivalent of : > inb(adr) > outb(val,adr) > iopl(n) > ioperm(adr) > > from and in linux. > The i/o space in FreeBSD is normally reserved for management by the kernel. In my opinion this makes it a real hosted OS rather than some mickey mouse thing. However if a process run by root opens /dev/io then while it is held open the process can make direct access to i/o ports. Nice for experimenting with software, but for production it is better to write a kernel module for special driver requirements. Are you sure the standard serial driver interfaces are not suitable for your needs -- they are very flexible. Malcolm ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: how to talk to the serial and parallel ports through a C
On 10 June 2003 18:45, Bernard Dugas wrote: > Hi, > > I also did some programming on serial port to control pins with a c > program under linux, but I didn't found any simple way to port it > under freebsd. Any hint ? > > For instance, I need the equivalent of : > inb(adr) > outb(val,adr) > iopl(n) > ioperm(adr) > > from and in linux. Try that: --- #include #include #include #include #include #define porta 0x378 #define portb 0x379 const char *filename; int main(void) { int fd, data; filename = "/dev/io"; fd = open(filename, O_RDWR); if (fd < 0) { printf("Erreur d'accès à %s\n", filename); exit(1); } outb(porta, 0xFF); sleep(1); outb(porta, 0x00); sleep(1); data = (inb(portb)); printf("data = %x\n", data); close(fd); exit(0); } - Works with FreeBSD 5.x, I don't know with 4.x Guillaume > > Best regard, > Bernard Dugas > > > -- > > > > Message: 32 > > Date: Mon, 09 Jun 2003 09:44:28 -0700 > > From: Dan Malaby <[EMAIL PROTECTED]> > > Subject: how to talk to the serial and parallel ports through a C > > program > > To: [EMAIL PROTECTED] > > Message-ID: <[EMAIL PROTECTED]> > > Content-Type: text/plain; charset="us-ascii"; format=flowed > > > > I was wondering if there was a good place to go to get programing > > examples on how to > > talk to the serial and parallel ports. I have looked in the > > developers handbook but have not > > any luck finding what I want. > > > > Any pointers would be appreciated > > > > Thanks > > > > Daniel Malaby voice:(510) 531-6500 > > Peritek Corp. fax: (510) 530-8563 > > 5550 Redwood Road email: [EMAIL PROTECTED] > > Oakland, CA 94619 > > > > -- ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: how to talk to the serial and parallel ports through a C
Hello, Malcolm Kay a écrit : > The i/o space in FreeBSD is normally reserved for management > by the kernel. In my opinion this makes it a real hosted OS rather > than some mickey mouse thing. This is why i'm using FreeBSD :-) > However if a process run by root opens /dev/io then while it is > held open the process can make direct access to i/o ports. Nice > for experimenting with software, but for production it is better to > write a kernel module for special driver requirements. > > Are you sure the standard serial driver interfaces are not suitable > for your needs -- they are very flexible. 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 #include 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 } void setComValues(int adr,unsigned char c_TxdS3,unsigned char TxdS3, unsigned char c_DtrS4, unsigned char DtrS4, unsigned char c_RtsS7, unsigned char RtsS7) { unsigned char pmask3,pmask4,nmask3,nmask4,nnTxdS3,nnDtrS4,nnRtsS7; // Quand c_x est faux, la variable x n'est pas modifiée. //Le OU du pmask est utile quand x est à 1 //Le ET du nmask est utile quand x est à 0 //On fait les 2 opérations à la fois pour éviter une combinatoire //conditionnelle. //Il faut formatter x au cas où il serait strictment supérieur //à 1 //Attention ! ~1=254 alors que !1=0 if(c_TxdS3) { nnTxdS3=!TxdS3; TxdS3=!nnTxdS3; //décalage de TxdS3 en bit 6 pmask3=TxdS3<<6; nmask3=~(nnTxdS3<<6); //on modifie seulement le(s) bit(s) modifié(s) de la valeur //lue immédiatement avant, pour limiter les risques de modification //intermédiaire. outb(((inb(adr+3)|pmask3)&nmask3),adr+3); } //on ne touche pas au registre +3 si c_TxdS3 est faux if(c_DtrS4 || c_RtsS7) { if(c_DtrS4) { nnDtrS4=!DtrS4; DtrS4=!nnDtrS4; } else { //les 2 variables à 0 ne modifient aucun masque nnDtrS4=0; DtrS4=0; } if(c_RtsS7) { nnRtsS7=!RtsS7; RtsS7=!nnRtsS7; } else { //les 2 variables à 0 ne modifient aucun masque RtsS7=0; nnRtsS7=0; } //décalage de RtsS7 en bit 1 pmask4=DtrS4|(RtsS7<<1); nmask4=~(nnDtrS4|(nnRtsS7<<1)); //on modifie seulement le(s) bit(s) modifié(s) de la valeur //lue immédiatement avant, pour limiter les risques de modification //intermédiaire. outb(((inb(adr+4)|pmask4)&nmask4),adr+4); } } Best regards, -- __ Bernard DUGAS | | | Technoparc Pays de Gex mailto:[EMAIL PROTECTED] | | 30 Rue Auguste Piccard Tel.: +33 450 205 105 | | FR 01630 St Genis Pouilly Fax : +33 450 205 106 | |_| ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: how to talk to the serial and parallel ports through a C
I'll reply on the parallel port: fd_relay=open("/dev/ppi0", O_WRONLY); ioctl(fd_relay, PPISDATA, value) Value being an 8 bits value. That works wonders with the relay card from Quality Kits http://www.qkits.com/serv/qkits/diy/pages/QK74.asp As for the entry, as I only needed 2 contacts, I used mouse button (plus it provides a nice testing interface, just click on your mouse buttons :) Olivier ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: how to talk to the serial and parallel ports through a C
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 > #include > > 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 [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"