Labels

Android (1) Apache (1) bash (2) boost (2) C (36) C++ (4) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (3) Dreamweaver (2) Eclipse (3) fail2ban (5) git (6) GitHub (5) Hacking (4) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (33) javascript (3) Linux (178) Mac (21) Machine Learning (1) mySQL (52) Netbeans (6) Networking (1) Nexus (1) OpenVMS (6) Oracle (2) Pandas (3) php (17) Postgresql (8) Python (9) raid (1) RedHat (15) Samba (2) Slackware (50) SQL (14) svn (1) tar (1) ThinkPad (1) Virtualbox (4) Visual Basic (2) Visual Studio (1) Windows (5)

Saturday, 20 January 2024

Serial ports

Serial port pinouts

Fig's 1&2 show the more common 9 pin serial pinouts, on both the computer side and also the device side respectively. Fig.3 gives a more visual representation of the male variant, most commonly found non the PC side. I think this was historically due to a male being more prone to damage, hence the female end being more commonly used on cables, but I may be wrong.

Fig.5 is particularly useful when testing cables, although I have only really connected pints 2&3 for this purpose. The idea here is that you make a plug that connects the pins together and then you can open the port and whatever you type should be echoed back exactly. 

Fig's 6-10 provide details about Null Modem connectivity.

Fig.11 provides more pinout details for the DB25 connectors


Fig.1 [source]
Fig.2 [source]

Fig.3 [source]

Fig.4 [source]

Fig.5 [source]

Fig.6 [source]

Fig.7 [source]

Fig.8 [source]

Fig.9 [source]

Fig.10 [source]

Fig.11 [source]

 

Fig.12 below shows the 15 pin programmer port on the GEM/400

Fig.12

20mA Connection

1 - Rx+
2 - Rx-
3 - Tx+
4 - Tx-
5 - ST+
6 - ST-
7 - SR+
8 - SR-

[1,2,3,4] - External current source required.

Do not use GEM80 current source except when connecting to a local programming tool, otherwise isolation will be compromised.

RS232 Connections

9   - RXD
10 - TXD
11 - CTS
12 - RTS
13 - (make no connection)
14 - 0v
15 - 5v 
 
[10,11] - The RS232 port is not isolated from the Controller 0v.
[14,15] -Non Isolated.
 
To connect a 9 pin serial to 15 pin as per Fig.12, we would connect as below:
 
Pin 2 (RXD) PC <- - Pin 10 (TXD) PLC Transmit to PC Receive.
Pin 3 (TXD) PC <- - Pin 9 (RXD) PC Transmit to PLC Receive.
Pin 5 (GND) PC <-> Pin 14 (0V) Common Signal Ground.
 
For Full Hardware pass through;
Connect PC Pin 7 (RTS) -> PLC Pin 11 (CTS)

Connect PC Pin 8 (CTS) -> PLC Pin 12 (RTS)

Alternatively;
On the PC 9-pin connector: Solder a tiny jumper wire bridging Pin 7 to Pin 8. 
On the PLC 15-pin connector: Solder a tiny jumper wire bridging Pin 11 to Pin 12. 

 

 

What follows is some more information on terminal settings.

stty -F /dev/ttyS0 -a can be used to view terminal settings, while stty is used to change settings.

The output of stty -F /dev/ttyS0 -a could be;
 
speed 2400 baud; rows 0; columns 0; line = 0;
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>;
flush = <undef>; min = 0; time = 1;
parenb -parodd cs7 -hupcl -cstopb cread clocal crtscts
-ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke
 
 with some explanations;
  • crtscts: Hardware flow control (RTS/CTS) is enabled.
  • -ixon: Software flow control (IXON) is disabled.
  • -ixoff: Software flow control (IXOFF) is disabled.
  • parenb: If present, it indicates that parity is enabled. If absent, parity is disabled.
  • parodd: If present, it indicates that odd parity is used. If absent, even parity is used.
  • rows: This typically indicates the number of rows or lines that are available on the terminal screen.
  • columns: This usually indicates the number of columns that are available on the terminal screen.
  • line: This refers to the number of lines per page.
The setting of a terminal with stty, for example;
stty crtscts -ixon -echo cs7 parenb -icrnl -inlcr -ocrnl onlcr speed 2400 -F /dev/ttyS0

  • crtscts: Enables hardware flow control using RTS/CTS (Request to Send/Clear to Send).
  • -ixon: Disables software flow control (IXON).
  • -echo: Disables echoing of input characters.
  • cs7: Sets the character size to 7 bits per byte.
  • parenb: Enables parity generation on output and parity checking for input.
  • -icrnl: Disables mapping of CR (Carriage Return) to NL (Newline) on input.
  • -inlcr: Disables mapping of NL to CR on input.
  • -ocrnl: Disables mapping of CR to NL on output.
  • onlcr: Enables mapping of NL to CR-NL on output.
  • speed 2400: Sets the baud rate to 2400 bps (bits per second).
  • -F /dev/ttyS0: Specifies the serial port device file, in this case, /dev/ttyS0
  • Hardware Flow Control (crtscts): Enables hardware-based flow control, which uses the RTS and CTS signals to control data transmission between devices.

  • Software Flow Control (-ixon): Disables software-based flow control. This is important when hardware flow control is used.

  • Echo (-echo): Disables the echoing of input characters back to the terminal.

  • Character Size (cs7): Sets the character size to 7 bits.

  • Parity (parenb): Enables parity generation on output and parity checking for input.

  • Input Carriage Return (-icrnl): Disables mapping of CR to NL on input.

  • Input Newline (-inlcr): Disables mapping of NL to CR on input.

  • Output Carriage Return (-ocrnl): Disables mapping of CR to NL on output.

  • Output Newline (onlcr): Enables mapping of NL to CR-NL on output.

  • Baud Rate (speed 2400): Sets the baud rate to 2400 bps.

  • Serial Port (-F /dev/ttyS0): Specifies the serial port device file, in this case, /dev/ttyS0.


To monitor a serial port in linux do;
 
tail -f /dev/ttyUSB0
 
If using a usb to serial cable, plug it in and do dmesg which will show the port, something like;
 
[ 1023.621868] usb 1-1: new full-speed USB device number 6 using xhci_hcd
[ 1023.748515] usb 1-1: New USB device found, idVendor=067b, idProduct=2303, bcdDevice= 4.00
[ 1023.748519] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1023.748520] usb 1-1: Product: USB-Serial Controller D
[ 1023.748521] usb 1-1: Manufacturer: Prolific Technology Inc. 
[ 1023.772505] usbcore: registered new interface driver usbserial_generic
[ 1023.772510] usbserial: USB Serial support registered for generic
[ 1023.773011] usbcore: registered new interface driver pl2303
[ 1023.773015] usbserial: USB Serial support registered for pl2303
[ 1023.773049] pl2303 1-1:1.0: pl2303 converter detected
[ 1023.774155] usb 1-1: pl2303 converter now attached to ttyUSB0
 
The above example shows ttyUSB0 hence tail -f /dev/ttyUSB0
 
To write to the port, do echo "hello" > /dev/ttyUSB0 or date > /dev/ttyUSB0
 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.