Parallel Port ECP IO using open/read/write

Hi everybody :laughing: ,

[Objective]
a) To communicate with the parallel port using open/read/write.

[Problem]
//I coded the following
ThreadCtl(_NTO_TCTL_IO,0)

fd=open("/dev/par1",O_RDONLY);

ByteRead=read(fd, buffer, BytesToRead)

However, when i printf the content of the buffer, i do not get what i expect (eg there are nothing inside the buffer).

I check the fd and it is returning a positive value.
Having been trying hard to debug but failed.
I tried to check the linux website for examples, but it did not work in QNX
:frowning:

Need advice and help in this.

[Remark]

Not to use interrupt.
multi-threaded environment, therefore approach should not consume too much CPU resource, in the event when the port is empty.
Hence, this implies that the command should have BLOCKING feature.

[What i have done]
1)Successfully tried using in32 & out32.
However, these approach consume CPU resources and i have to keep
polling to check if there are any incomming data.

issachar

Paralle driver doesn`t support input.

If you can`t/don"t want to use interrupt you have no other choice but to poll. Option would be to write your own parallel port driver that would be interrupt based for minimal CPU usage and possible use some of them DMA mode.

Input on parallel port is kind of tricking because there are various method for inputing data depending on the type of protocol used.

The devc-par is really just designed for talking to a printer - not a generic i/o capability. I thought it did support some limited input, but I could be wrong. In any case, I have always gone to the hardware and used in()/out() calls when I needed simple i/o bits.

I always thought that interrupt driver i/o on the printer port because the irq generally assigned is also the same one used for unknown interrupts on the PIC. - that info is probably way out of date.

Usually what you end up having to do is poll in a delayed loop with sleeps short enough so you don’t miss the data - if you know the pulse width of the data coming in, you can ensure you poll often enough not to miss anything.

Hope this helps…

Thanks for enriching me. I have been trying for days using “fd=open(”/dev/par1",O_RDONLY); "
This is because i have success in communicating with the serial port using
-“fd=open(”/dev/ser1",O_RDONLY); ", so i thought i can do the same for the parallel port.

[Confusing thoughts]
But i have this question here…I understand from QNX that all devices can be accessed using the open/read/write command.By looking at the qnx help file, i tried using the devctl command with various options under the /usr/include/sys/dcmd_*.h files , esp the _DCMD_CHR.
It failed.

[Question]
Is it possible then to use open/read/write command to access the parallel port, with either ioctl /devctl ?
Beside in/out command, what other commands can i use to access the parallel port?

issachar

Sorry, in()/out() is your best friend in this case. The docs for devc-par say, “Reading from devc-par works the same as reading from /dev/null.”

If you want performance, then using ECP mode can give buffering or even DMA. But I imagine the external device also has to support ECP.

Data on parallel port can come in very fast, at over 1Meg sec, doing a ioctl/devdl for each byte would be very heavy on the CPU. Unless you use some sort of DMA mode, parallel port and real-time don’t mix very well

The open/read/write or devctl talk to the driver. The driver which ships is for talking to a printer and won’t work for you. If you want to write your own driver which works for what you are trying to od, it is not that hard and you could then use open/read/write with it.

If you don’t want to write your own driver, then you need to talk to the hardware directly (in/out). No other choices are available.

Rick…