Re: pl2303.c and the pin status

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23/03/2012 5:03 PM, Dan Williams wrote:
On Fri, 2012-03-23 at 21:57 +0100, Søren holm wrote:
Hi

On Wintendo it is possible to specify the state of DTR/RTS in conjuction with
opening the port. How about using O_DIRECT or add a new openmode to tell the
driver to leave DTR/RTS as they are. That way it would not imply any change.

Actually when I first started, I assumed was doing it wrong, there must be a way to open the port without altering it, I thought. Google-ling around trying to find just the right parameter to pass along with open()

In the end I used:
    fd = open(comPort,O_RDWR|O_NOCTTY|O_NDELAY)
Which unfortunately prevents me from knowing the original state of the DTR/RTS.

I'd rather see sysfs attributes for the pin states in the tty's sysfs
dir instead of munging open() to do it.

Dan

Simply put I see 3 ways to resolve this:

1. Add a new parameter to the open() call so you can open the device file like:
    fd = open(comPort,O_NO_ALTER_DTR_RTS)

Pros: Would open access to elaborate programs written in C
Cons: Using TIOCMGET and TIOCMSET is outside the reach of a simple shell script. I guess I could write a small wrapper in C to make it available to script writers but this is not in keeping with the Unix/Linux philosophy.

2.  Add a single file in sysfs something like:
  /sys/class/tty/ttyUSB0/device/TIOCM

Pros: Access to all pins with a single read from a shell script.
Cons: The script needs to parse out the individual bits from the 1 byte read. You would also need to read the state of DTR/RTS before you can write a new value to /sys/class/tty/ttyUSB0/device/TIOCM if you want to change only one of the two. Actualy this is currently the case with TIOCMGET and TIOCMSET.

3. Add multiple files to sysfs something like this:
  /sys/class/tty/ttyUSB0/device/RTS (rw, Request To Send)
  /sys/class/tty/ttyUSB0/device/CTS (r,  Clear To Send)
  /sys/class/tty/ttyUSB0/device/DSR (r,  Data Set Ready)
  /sys/class/tty/ttyUSB0/device/DCD (r,  Data Carrier Detect)
  /sys/class/tty/ttyUSB0/device/DTR (rw, Data Terminal Ready)
  /sys/class/tty/ttyUSB0/device/RI  (r,  Ring Indicator)

Pros: Very easy to script. Ability to set DTR directly without any prior read.
Cons: Could have race conditions when needing to read multiple pins.

Being greedy, I would like to see all three solution implemented, but I could live with just one.

Gérald





--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux