Last active
December 19, 2023 07:57
-
-
Save tiagocoutinho/de3f8da1bc11943b5ae41fd84aa83ee8 to your computer and use it in GitHub Desktop.
Revisions
-
tiagocoutinho revised this gist
May 13, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ python simulator.py #### Run on terminal 3: ``` python client.py "*IDN?" ``` ### References -
tiagocoutinho revised this gist
May 13, 2020 . 1 changed file with 20 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,26 @@ ## Virtual serial line Virtual serial line on linux with socat, python server & client #### Run on terminal 1: ```terminal socat -d -d pty,raw,echo=0,link=/tmp/cryocon_simulator pty,raw,echo=0,link=/tmp/cryocon ``` #### Run on terminal 2: ``` python simulator.py ``` #### Run on terminal 3: ``` python client "*IDN?" ``` ### References [stack overflow reference](https://stackoverflow.com/questions/52187/virtual-serial-port-for-linux) Alternatives: -
tiagocoutinho revised this gist
May 13, 2020 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ # Virtual serial line Virtual serial line on linux with socat, python server & client [stack overflow reference](https://stackoverflow.com/questions/52187/virtual-serial-port-for-linux) Alternatives: * [example](https://github.com/cymait/virtual-serial-port-example) * [nullmodem](https://github.com/pitti98/nullmodem) * [tty0tty](http://sourceforge.net/projects/tty0tty/) -
tiagocoutinho renamed this gist
May 13, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
tiagocoutinho created this gist
May 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # creates the PTYs socat -d -d pty,raw,echo=0,link=/tmp/cryocon_simulator pty,raw,echo=0,link=/tmp/cryocon This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import sys import serial DEFAULT_ADDR = '/tmp/cryocon' DEFAULT_CMD = '*IDN?' args = len(sys.argv) - 1 if args == 0: addr, cmd = DEFAULT_ADDR, DEFAULT_CMD elif args == 1: addr, cmd = DEFAULT_ADDR, sys.argv[1] else: addr, cmd = sys.argv[1:3] cmd += '\n' s = serial.serial_for_url(addr) s.write(cmd.encode()) print(s.readline()) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import sys import logging import serial DEFAULT_ADDR = '/tmp/cryocon_simulator' logging.basicConfig(level=logging.INFO) addr = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_ADDR conn = serial.serial_for_url(addr) logging.info(f'Ready to receive requests on {addr}') while True: request = conn.readline() logging.info('REQ: %r', request) request = request.strip().decode().lower() reply = 'Cryo-con,24C,305682,1.05A\n' if request == '*idn?' else 'NACK\n' reply = reply.encode() logging.info('REP: %r', reply) conn.write(reply)