{"id":16190688,"url":"https://github.com/tiagocoutinho/cryocon","last_synced_at":"2025-03-19T03:30:58.012Z","repository":{"id":41874859,"uuid":"226092098","full_name":"tiagocoutinho/cryocon","owner":"tiagocoutinho","description":"CryoCon temperature controller: python library + simulator + tango server ","archived":false,"fork":false,"pushed_at":"2024-03-11T06:33:28.000Z","size":8281,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-17T03:21:25.091Z","etag":null,"topics":["cryocon","eth","library","python","serial","simulator","tango-server"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tiagocoutinho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-05T11:59:20.000Z","updated_at":"2022-10-21T18:12:06.000Z","dependencies_parsed_at":"2024-10-27T19:40:01.321Z","dependency_job_id":"ce6f0181-76f3-4a42-82d9-34af8e219bc1","html_url":"https://github.com/tiagocoutinho/cryocon","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocoutinho%2Fcryocon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocoutinho%2Fcryocon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocoutinho%2Fcryocon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagocoutinho%2Fcryocon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiagocoutinho","download_url":"https://codeload.github.com/tiagocoutinho/cryocon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244350936,"owners_count":20439290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryocon","eth","library","python","serial","simulator","tango-server"],"created_at":"2024-10-10T07:43:54.860Z","updated_at":"2025-03-19T03:30:57.465Z","avatar_url":"https://github.com/tiagocoutinho.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CryoCon library\n\n\u003cimg align=\"right\" alt=\"CryoCon M24C\" width=\"350\" src=\"docs/cryocon_M24C.png\" /\u003e\n\nThis library is used to control basic features of a CryoCon temperature\ncontroller. It is composed of a core library, an optional simulator and\nan optional [tango](https://tango-controls.org/) device server.\n\nIt has been tested with M32 and M24C models, but should work with other models.\n\nIt can be used with either the ETH or the serial line connection (read below\non the recommended way to setup a serial line connection)\n\n## Installation\n\nFrom within your favorite python environment type:\n\n`$ pip install cryocon`\n\n\n## Library\n\nThe core of the cryocon library consists of CryoCon object.\nTo create a CryoCon object you need to pass a communication object.\n\nThe communication object can be any object that supports a simple API\nconsisting of two methods (either the sync or async version is supported):\n\n* `write_readline(buff: bytes) -\u003e bytes` *or*\n\n  `async write_readline(buff: bytes) -\u003e bytes`\n\n* `write(buff: bytes) -\u003e None` *or*\n\n  `async write(buff: bytes) -\u003e None`\n\nA library that supports this API is [sockio](https://pypi.org/project/sockio/)\n(cryocon comes pre-installed so you don't have to worry about installing it).\n\nThis library includes both async and sync versions of the TCP object. It also\nsupports a set of features like reconnection and timeout handling.\n\nHere is how to connect to a cryocon controller:\n\n```python\nimport asyncio\n\nfrom sockio.aio import TCP\nfrom cryocon import CryoCon\n\n\nasync def main():\n    tcp = TCP(\"192.168.1.123\", 5000)  # use host name or IP\n    cryo = CryoCon(tcp)\n\n    idn = await cryo.idn()\n    name = await cryo.name()\n    print(\"Connected to {} ({})\".format(idn, name))\n\n    # channel access:\n    temp_A = await cryo['A'].temperature()\n    unit = await cryo['A'].unit()\n    print(\"Channel A temperature: {}{}\".format(temp_A, unit))\n\n    # loop access:\n    source_1 = await cryo[1].source()\n    print(\"Loop 1 source: {}\".format(source_1))\n\n    # activate control\n    await cryo.control(True)\n\n    # hardware only accepts queries every 100ms. Yo can, however,\n    # group queries in single request:\n    async with cryo as group:\n        cryo.idn()\n        cryo.control()\n        cryo['A'].temperature()\n    idn, ctrl, temp_A = group.replies\n\n\nasyncio.run(main())\n```\n\n#### Serial line\n\nTo access a serial line based CryoCon device it is strongly recommended you spawn\na serial to tcp bridge using [ser2net](https://linux.die.net/man/8/ser2net), [ser2sock](https://github.com/tiagocoutinho/ser2sock) or\n[socat](https://linux.die.net/man/1/socat)\n\nAssuming your device is connected to `/dev/ttyS0` and the baudrate is set to 19200,\nhere is how you could use socat to expose your device on the machine port 5000:\n\n`socat -v TCP-LISTEN:5000,reuseaddr,fork file:/dev/ttyS0,rawer,b19200,cs8,eol=10,icanon=1`\n\nIt might be worth considering starting socat or ser2net as a service using\n[supervisor](http://supervisord.org/) or [circus](https://circus.rtfd.io/).\n\n### Simulator\n\nA CryoCon simulator is provided.\n\nBefore using it, make sure everything is installed with:\n\n`$ pip install cryocon[simulator]`\n\nThe [sinstruments](https://pypi.org/project/sinstruments/) engine is used.\n\nTo start a simulator you need to write a YAML config file where you define\nhow many devices you want to simulate and which properties they hold.\n\nThe following example exports 2 hardware devices. The first is a minimal\nconfiguration using default values and the second defines some initial values\nexplicitly:\n\n```yaml\n# config.yml\n\ndevices:\n- class: CryoCon\n  name: cryo1\n  transports:\n  - type: tcp\n    url: :5000\n\n- class: CryoCon\n  name: cryo2\n  transports:\n    - type: tcp\n      url: :5001\n  channels:\n    A:\n      unit: K\n    B:\n      unit: K\n  loops:\n    1:\n      source: A\n      type: MAN\n  distc: 4\n  lockout: OFF\n  remled: ON\n  control: OFF\n```\n\nTo start the simulator type:\n\n```terminal\n$ sinstruments-server -c ./config.yml --log-level=DEBUG\n2020-05-14 16:02:35,004 INFO  simulator: Bootstraping server\n2020-05-14 16:02:35,004 INFO  simulator: no backdoor declared\n2020-05-14 16:02:35,004 INFO  simulator: Creating device CryoCon ('CryoCon')\n2020-05-14 16:02:35,080 INFO  simulator.CryoCon[('', 5000)]: listening on ('', 5000) (newline='\\n') (baudrate=None)\n2020-05-14 16:02:35,080 INFO  simulator: Creating device CryoCon ('CryoCon')\n2020-05-14 16:02:35,081 INFO  simulator.CryoCon[('', 5001)]: listening on ('', 5001) (newline='\\n') (baudrate=None)\n```\n\n(To see the full list of options type `sinstruments-server --help`)\n\nYou can access it as you would a real hardware:\n\n```terminal\n$ nc localhost 5000\n*IDN?\nCryo-con,24C,204683,1.01A\n```\n\nor using the library:\n```python\n$ python\n\u003e\u003e\u003e from sockio.sio import TCP   # use synchronous socket in the CLI!\n\u003e\u003e\u003e from cryocon import CryoCon\n\u003e\u003e\u003e cryo = CryoCon(TCP('localhost', 5000))\n\u003e\u003e\u003e print(cryo.idn())\nCryo-con,24C,204683,1.01A\n```\n\nor, since python 3.8, it is possible to launch a natively async REPL:\n```python\n$ python -m asyncio\n\u003e\u003e\u003e from sockio.aio import TCP\n\u003e\u003e\u003e from cryocon import CryoCon\n\u003e\u003e\u003e cryo = CryoCon(TCP('localhost', 5000))\n\u003e\u003e\u003e print(await cryo.idn())\n```\n\n### Tango server\n\nA [tango](https://tango-controls.org/) device server is also provided.\n\nMake sure everything is installed with:\n\n`$ pip install cryocon[tango-ds]`\n\nRegister a cryocon tango server in the tango database:\n```\n$ tangoctl server add -s CryoCon/test -d CryoCon test/cryocon/1\n$ tangoctl device property write -d test/cryocon/1 -p url -v \"tcp://192.168.123:5000\"\n```\n\n(the above example uses [tangoctl](https://pypi.org/project/tangoctl/). You would need\nto install it with `pip install tangoctl` before using it. You are free to use any other\ntango tool like [fandango](https://pypi.org/project/fandango/) or Jive)\n\nLaunch the server with:\n\n```terminal\n$ CryoCon test\n```\n\n## TODO\n\n* Add `on_connection_made` callback to initialize controller with:\n  * unit=`K`\n  * cache IDN, fw revision, hw revision\n  * should we cache system:name? and input:name? in theory in could be modified\n    directly with the hardware front panel\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagocoutinho%2Fcryocon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiagocoutinho%2Fcryocon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagocoutinho%2Fcryocon/lists"}