Question:
parallel port programming in c++?
?
2009-12-21 05:11:05 UTC
can anyone here write me a program which takes data from my parallel port (at address 0x378) every 1 second and saves it to a .txt document somewhere on my computer. I wanted this in c++ or c or anyother programming language that i can instantly use or compile.
Thanks
Four answers:
Paul
2009-12-21 13:20:02 UTC
It depends on what OS you are using.
lucky_flop
2009-12-21 23:36:48 UTC
What you are asking for is a device driver in Unix or Windows. All operating systems have a layer of hardware abstraction called a device driver which is a software equivalent to reading or writing to a file. The difference between a file and an actual device is that the device driver can be controlled by using a call called ioctl(). The parameters to ioctl() depend upon the device capabilities. For example, to force the disk heads to a safe cylinder would make sense to a disk device driver but not a printer device driver.



To program to accept data from a parallel port, I would think some assembly language would need to be written first and installed in the operating system. C++ might be too abstract of a language to use in a device driver.
rebelo
2016-10-17 10:28:47 UTC
What you're requesting is a gadget employing stress in Unix or homestead living house windows. All working systems have a layer of hardware abstraction noted as a gadget employing stress it quite is a application which incorporate interpreting or writing to a checklist. the version between a checklist and an truthfully gadget is that the gadget employing stress may well be controlled by becoming use of a decision noted as ioctl(). The parameters to ioctl() count huge form huge form on the gadget effective factors. as an social gathering, to stress the disk heads to a secure cylinder might make adventure to a disk gadget employing stress yet now not a printer gadget employing stress. To application to settle for documents from a parallel port, i might think of of a few assembly language might opt to be written first and put in indoors the working gadget. C++ may well be too precis of a language to coach in a gadget employing stress.
Ciaron
2009-12-22 11:48:11 UTC
It really depends on if you are using Dos, Windows or Linux the Dos function inport() would be needed -

here is a simple program in C for Linux



/*

* example.c: very simple example of port I/O

*

* This code does nothing useful, just a port write, a pause,

* and a port read. Compile with `gcc -O2 -o example example.c',

* and run as root with `./example'.

*/



#include

#include

#include



#define BASEPORT 0x378 /* lp1 */



int main()

{

/* Get access to the ports */

if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}



/* Set the data signals (D0-7) of the port to all low (0) */

outb(0, BASEPORT);



/* Sleep for a while (1000 ms) 1 second */

usleep(1000000);



/* Read from the status port (BASE+1) and display the result */

printf("status: %d\n", inb(BASEPORT + 1));



/* We don't need the ports anymore */

if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}



exit(0);

}



/* end of example.c */



A Dos program that would take in information from the parallel port would look like this

#include"stdio.h"

#include"conio.h"

#include"dos.h"



#define PORT 0x378



void main()

{

int data;



while(!kbhit())

{

data=inportb(PORT+1);



printf("Data available in status register: %3d (decimal), %3X (hex)\n", data, data);

printf("\n Pin 15: %d",(data & 0x08)/0x08);

printf("\n Pin 13: %d",(data & 0x10)/0x10);

printf("\n Pin 12: %d",(data & 0x20)/0x20);

printf("\n Pin 11: %d",(data & 0x80)/0x80);

printf("\n Pin 10: %d",(data & 0x40)/0x40);

delay(10);

}

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...