Управление lpt портом linux

LPT programming example in C for ubuntu linux

A while back I wanted to try out LPT printer port programming for upcoming project. After hours of learning, testing and searching, I came up with fallowing piece of code what finally worked for me. This example code makes LED blink in rate of 2 blinks per second wich is soldered between ground and any of the data pins.

#include #include #include #include #include #include #define BASEPORT 0x378 /* lp1 */ int main() < char c; int n, tem; printf("Hit any key to stop\n"); //set permissions to access port if (ioperm(BASEPORT, 3, 1)) tem = fcntl(0, F_GETFL, 0); fcntl (0, F_SETFL, (tem | O_NDELAY)); //main loop where actual blinking is done while (1) < //if some key is pressed, break out from loop n = read(0, &c, 1); if (n >0) break; //write 'on' bit on all data pins and wait 1/4 second outb(255, BASEPORT); usleep(250000); //write 'off' bit on all data pins and wait 1/4 second outb(0, BASEPORT); usleep(250000); > fcntl(0, F_SETFL, tem); outb(0, BASEPORT); //take away permissions to access port if (ioperm(BASEPORT, 3, 0)) exit(0); >

I compiled it with command where lpt.c is source code and lpt is program name compiled.

gcc lpt.c -O2 -o lpt

After that check that program has excecute permissions and run it with command.

I used LED with 550 ohms resistor in series and soldered them between pin 2 and 20 to test out this program. It worked fine.

Читайте также:  Linux service permission denied

Источник

Работа с портом LPT в линуксе

Как управлять портом /dev/lp0 в линуксе (например, если карта на CH382 или динамодовская )? Как обеспечить управление направлением , ввод и вывод байта данных , чтение регистров адрес+1, адрес +2 , визуализировать их состояние ?

Работа с LPT портом
Здравствуйте, не могу разобраться(нагуглить) инфо по работе с lpt портом. Нужно отправлять данные.

Работа с LPT портом
Добрый день форумчане, столкнулся с проблемой. Печатающее устройство получает информацию через.

Работа с LPT портом.
Добрый день. Необходимо написать программу которая бы поочередно посылала импульсы на 2 (D0) 3(D1).

Работа с LPT портом
Доброго времени суток. Имеется матричный принтер. Для вывода текста использую рулонную бумагу. При.

Как написать на лазарусе и C++ GCC ( с LX Terminal , gcc — . ) функциональный аналог программы LPTstatus для Линукса (можно, консольный )?

Добавлено через 6 минут

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/* * 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 /* lp0 */ 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 (100 ms) */ usleep(100000); /* 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 */

Как читать биты 0x379h ,0x37Ah , как управлять направлением для ECP+EPP , как читать 0x378h ?

Как использовать ReadFile , WriteFile, CreateFile , GetCommState для LPT? А в линуксе для CH382 ? Когда будут драйвера ?

ЦитатаСообщение от USERPC01 Посмотреть сообщение

Вот описание по работе с LPT-портом в трёх режимах (через raw IO, через /dev/lp и через /dev/parport) https://mockmoon-cybernetics.c. rport.html

А в стиле Access via /dev/lp, Full access via /dev/parport только для /dev/usblp0 , /dev/usb/lp0 для PL2305 (VEN11,VEN12)

Добавлено через 47 секунд
067B:2305 по lsusb

The port BASE+0 (Data port) controls the data signals of the port (D0 to D7 for bits 0 to 7, respectively;
states: 0 = low (0 V), 1 = high (5 V)). A write to this port latches the data on the pins. A read returns the data
last written in standard or extended write mode, or the data in the pins from another device in extended read
mode.
The port BASE+1 (Status port) is read−only, and returns the state of the following input signals:
• Bits 0 and 1 are reserved.
• Bit 2 IRQ status (not a pin, I don’t know how this works)
• Bit 3 ERROR (1=high)
• Bit 4 SLCT (1=high)
• Bit 5 PE (1=high)
• Bit 6 ACK (1=high)
• Bit 7 −BUSY (0=high)
The port BASE+2 (Control port) is write−only (a read returns the data last written), and controls the
following status signals:
• Bit 0 −STROBE (0=high)
• Bit 1 −AUTO_FD_XT (0=high)
• Bit 2 INIT (1=high)
• Bit 3 −SLCT_IN (0=high)
• Bit 4 enables the parallel port IRQ (which occurs on the low−to−high transition of ACK) when set to
1.
• Bit 5 controls the extended mode direction (0 = write, 1 = read), and is completely write−only (a read
returns nothing useful for this bit).
• Bits 6 and 7 are reserved.
Pinout (a 25−pin female D−shell connector on the port) (i=input, o=output):
1io −STROBE, 2io D0, 3io D1, 4io D2, 5io D3, 6io D4, 7io D5, 8io D6,
9io D7, 10i ACK, 11i −BUSY, 12i PE, 13i SLCT, 14o −AUTO_FD_XT,
15i ERROR, 16o INIT, 17o −SLCT_IN, 18−25 Ground

Добавлено через 1 минуту
Для примера кода

gcc -O2 -o example.c ./example.c

Работа с LPT портом в С++Builder
Народ помагите разобратся как работать в билдере с lpt портом :umnik:

Работа с LPT- портом на CH382L
Как в Dev-C++ управлять портом LPT1 на CH382L читать, записывать данные методом.

Работа с LPT- портом в Win32Forth
Добрый день. не знаю, в правильном ли разделе разместил тему. Среда программирования Win32Forth.

Работа с LPT-портом из ВСВ 6
Произвольные чтение и запись в LPT-порт. Builder не видит практически ни одной функции из DOS.H;.

Источник

Оцените статью
Adblock
detector