SW_DevCH340TTY - fablab-wue/piTelex GitHub Wiki
Device Module "CH340TTY"
Description
Using an adapter board (or adapter cable - for V.10) based on the chip CH340 the device is detected as normal (virtual) serial interface. In Windows the device is shown as COMx:
. In Linux it is often shown as /dev/ttyUSBx
(may vary depending on the OS version...). With the Python library "PySerial" all necessary settings can be done to handle 50 baud, 5 data-bits and 1.5 stop-bits. Also, the handshake pins RTS and DTR can be set by this library.
TTL output signals of the CH340 PCB can drive some interface hardware for a TW39 / TWM / V.10 / EDS teleprinter. Examples can be found here.
[!CAUTION]
There are several USB/Serial adapters that use different chips. Be aware that ONLY adapters with CH340 chip are compatible with this project. Only the CH340 chip supports a baud rate of 50 Bd!
System
System | Comments |
---|---|
RPi | OK |
PC Linux | OK |
PC Windows | OK |
Mac | OK |
Dependencies
PythonModule | Install | Anaconda |
---|---|---|
pyserial | pip install pyserial | conda install pyserial |
Command Line Arguments
USB-Serial-Adapter (CH340-chip) with base teletype (without dialing device):
-Y TTY
--tty TTY
USB-Serial-Adapter (CH340-chip) with TW39 teletype (pulse dial):
--ttyTW39 TTY
USB-Serial-Adapter (CH340-chip) with TWM teletype (keypad dial):
-M TTY
--ttyTWM TTY
USB-Serial-Adapter (CH340-chip) with V.10 teletype (FS200, FS220):
-V TTY
--ttyV10 TTY
Example Windows:
./telex.py -W COM3
Example Linux:
$ ./telex.py -W /dev/ttyUSB0
Config File Parameter
Param | Default | type/range | Description |
---|---|---|---|
mode | "TW39" | "TW39", "TWM", "V10", "EDS" | "TW39": current loop / Number Switch Dial"TWM" : keypad Dial, "V10" : FS200/FS220 mode"EDS" : |
portname | "/dev/ttyUSB0" | string | serial port used (COMx: in Windows) |
baudrate | 50 | 50, 75, 100 | Baud rate |
bytesize | 5 | 5 … 8 | # of Databits |
stopbits | 1.5 | 1, 1.5, 2 | # of stopbits |
coding | 0 | 0,1,2,3 | 0:ITA2=CCITT2, 1:US, 2:MKT2, 3:ZUSE (see txCode.md) |
loopback | true | false / true | if true, sent characters are removed from receive buffer |
loc_echo | false | false / true | if true, echo back all characters received from teleprinter |
inverse_dtr | false | false / true | If true, use inverted signal |
inverse_rts | false | false / true | If true, use inverted signal |
Example config file section:
# Module type "CH340TTY"
# requirements: pyserial (Linux: sudo apt install python3-serial)
# TW39 or V10 teletype over USB-serial-adapter with CH340 chip or UART which supports 50 Baud
"CH340TTY": {
"type": "CH340TTY",
"enable": false,
"portname": "COM5", # Windows:"COMx" Linux:"/dev/ttyUSBx"
"baudrate": 50, # 50, 75, 100, 110, 200
"mode": "EDS", # modes: "TW39", "TWM", "V10", "EDS"
"coding": 0, # 0=ITA2
"loopback": false
},
RTS/CTS Hack for TW39
To decode the TW39 protocol correctly, it is necessary to detect a permanent low and high level on the RXD pin. Neither the CH340 chip nor the drivers drivers can handle that. The hack is to use a separate input pin (CTS) to detect the state of the line.
Therefore the pin RXD has to be connected to pin CTS of the CH340 chip.
Most PCBs with the CH340 chip do not route the CTS pin to a connector. Use a thin wire to connect the pins 3 and 9 directly on the chip. Some adapter boards provide a soldering point for the signals RTS and CTS, so you don't have to solder directly at the chip