简体   繁体   English

将DOS程序移植到linux以通过usb读/写串口

[英]Porting DOS program to linux to read/write serial port over usb

I have old DOS program which works with serial port. 我有旧的DOS程序,它与串口一起使用。 And I need to port it to linux . 我需要将它移植到linux I've connected my serial device to linux via USB (using rs232 cable). 我通过USB将我的串行设备连接到linux(使用rs232电缆)。 It appears as /dev/ttyUSB0. 它显示为/ dev / ttyUSB0。

Can I use functions inb , outb (instead of DOS equivalent inp, outp) for reading or writing in device from my code? 我可以使用功能inboutb (而不是DOS相当于INP,OUTP)来读取或从我的代码在设备写什么呢? ( inb and outb special function for lowlevel reading-writing bytes to specific port address). inboutb为低级读取字节写入特定的端口地址特殊功能)。 I don't understand how to determine proper port number. 我不明白如何确定正确的端口号。

Maybe there is another approach - for example open file '/dev/ttyUSB0'. 也许还有另一种方法 - 例如打开文件'/ dev / ttyUSB0'。 But in this case I have a problem reading device registers such as modem control register (MCR) or line status register (LSR). 但在这种情况下,我在读取设备寄存器时遇到问题,例如调制解调器控制寄存器(MCR)或线路状态寄存器(LSR)。

You can use inb/outb or mmap (eg. devmem, depends on architecture) for onboard standard serial port but it is not recommended in userland. 您可以使用inb / outb或mmap(例如devmem,取决于架构)作为板载标准串行端口,但不建议用户使用。 You need root priviledges, you can cause conflict with kernel's driver and you have to be sure that your hardware (eg. 16C550) is full compatible with your code. 您需要root权限,可能会导致与内核驱动程序冲突,您必须确保您的硬件(例如16C550)与您的代码完全兼容。

To trigger your program when serial port added can use udev rule or old hotplug. 在添加串口时可以使用udev规则或旧的热插拔来触发程序。 To determine port in case of USB serial port converter you can use USB bus id and port id. 要确定USB串口转换器的端口,您可以使用USB总线ID和端口ID。 You can check the numbers via lsusb -t command. 您可以通过lsusb -t命令检查数字。

  • serial port configuration: http://linux.die.net/man/3/termios 串口配置: http//linux.die.net/man/3/termios
  • check if there are received data (LSR): select() 检查是否有接收数据(LSR):select()
  • data inb / outb -> read() / write() data inb / outb - > read()/ write()
  • MSR (DCD, RI, CTS) / MCR (DTR, RTS if hardware flow control disabled) -> ioctl() or tty_ioctl MSR(DCD,RI,CTS)/ MCR(如果禁用硬件流控制,则为DTR,RTS) - > ioctl()或tty_ioctl

You can learn from picocom source code 您可以从picocom源代码中学习

Possible problem for realtime application: delays caused by USB bus polling and process/thread switching. 实时应用可能存在的问题:USB总线轮询和进程/线程切换引起的延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM