srsinst.qcm


Namesrsinst.qcm JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryInstrument driver package for the Quartz Crystal Microbalance, QCM200 from Stanford Research Systems (SRS)
upload_time2024-08-31 00:57:54
maintainerNone
docs_urlNone
authorChulhoon Kim
requires_python>=3.7
licenseMIT license
keywords qcm200 quartz crystal microbalanace srs stanford research systems
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # srsinst.qcm

`srsinst.qcm` is a Python package to provide serial communication with the 
[Quartz Crystal Microbalance, QCM200](https://thinksrs.com/products/qcm200.html)
from [Stanford Research Systems (SRS)](https://thinksrs.com/).

`srsinst.qcm` uses [srsgui](https://pypi.org/project/srsgui/) package for the support of instrument communication and graphic user interface (GUI). 

![screenshot](https://github.com/thinkSRS/srsinst.qcm/blob/main/docs/_static/image/QCM200_screenshot.png?raw=true " ").

## Installation
You need a working Python 3.7 or later with `pip` (Python package installer) installed. 
If you don't, [install Python](https://www.python.org/) to your system.

To install `srsinst.qcm` as an instrument driver , use Python package installer `pip` from the command line.

    python -m pip install srsinst.qcm

To use it as a GUI application, create a virtual environment, 
if necessary, and install:

    python -m pip install srsinst.qcm[full]


## Run `srsinst.qcm` as GUI application
If the Python Scripts directory is in your PATH environment variable,
start the application by typing from the command line:

    qcm

If not,

    python -m srsinst.qcm

will start the GUI application.

Once running the GUI, you can:
- Connect to a QCM200 from the Instruments menu.
- Select a task from the Task menu.
- Press the green arrow to run the selected task. 

You can write your own task(s) or modify an existing one and run it 
from the GUI application, too. For writing a task for the GUI application, 
refer the document on [srsgui package](https://thinksrs.github.io/srsgui/index.html).

## Use `srsinst.qcm` as instrument driver
* Start a Python interpreter, a Jupyter notebook, or an editor of your choice 
to write a Python script.
* Import the **QCM200** class from `srsinst.qcm` package.
* Create an instance of the **QCM200** and connect for the serial communication.

|


    C:\>python
    Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    >>> from srsinst.qcm import QCM200
    >>> qcm = QCM200('serial', 'COM3', 9600)
    >>> qcm.check_id()
    ('QCM200', '136058', 'Rev0.91')


If you get the reply with *check_id()* method as shown above, 
you are ready to configure and acquire data from your QCM200.

The remote control and data acquisition of of QCM200 is simple: 
Select the gate time you want to use among 0.1s, 1.0s, and 10.0s;
check if a new set of frequency and resistance data is available; 
and read data.


    >>>  # Query the current date time
    >>> qcm.cmd.gate_time
    0.1
    >>>  # Change the gate time to 1.0 s
    >>> qcm.cmd.gate_time = 1.0
    >>> Check if the gate time is changed
    >>> qcm.cmd.gate_time
    1.0
    >>>  # Query frequency 
    >>> qcm.cmd.frequency
    4999699.7
    >>>  # Query resistance 
    >>> qcm.cmd.resistance
    13.756
    >>>

You can view all the commands available in the `cmd` component as following. 


    >>> qcm.cmd.dir
      {'components': {}, 
       'commands': {
           'id_string': ('QCMGetCommand', 'I'), 
           'display_mode': ('DictCommand', 'D'),  
           'frequency_scale': ('DictCommand', 'V'), 
           'gate_time': ('DictCommand', 'P'), 
           'frequency': ('QCMFloatGetCommand', 'F'), 
           'frequency_offset': ('FloatGetCommand', 'G'), 
           'resistance': ('QCMFloatGetCommand', 'R'), 
           'resistance_offset': ('FloatGetCommand', 'S'), 
           'status': ('QCMIntGetCommand', 'B'), 
           'timebase': ('DictCommand', 'T')}, 
       'methods': [
            'reset_frequency_offset', 
            'reset_resistance_offset']
       }
    >>>

For remote command details, refer to the
[QCM200 manual appendix B](https://www.thinksrs.com/downloads/pdfs/manuals/QCM200m.pdf#page=117).

Here is a simple, yet complete python script to acquire data from a QCM200
using `srsinst.qcm` package.


    import time
    from srsinst.qcm import QCM200
    
    GateTime = 1.0                             # Select among 0.1 s, 1.0 s, or 10 s
    DataAcquisitionTime = 600                  # Data collection time in seconds
                                               # Connect to a QCM. Change the address for the COM port used 
    qcm = QCM200('serial', 'COM3', 9600)       # For Linux systems, 'COM3' will be like '/dev/ttyUSB1'.
    qcm.cmd.gate_time = GateTime               # Set the gate time
    
    output_file = open('qcm-data.txt', 'wt')   # Open a file to write data
    
    time_elapsed = 0.0
    initial_time = time.time()
    
    while time_elapsed < DataAcquisitionTime:  
        time_elapsed = time.time() - initial_time
        new_data = qcm.get_data_if_both_new()  # Data available when Both F and R data are new.
        if new_data:
            data_format = f'{time_elapsed:7.2f} {new_data[0]:10.2f} {new_data[1]:7.3f}\n'
            output_file.write(data_format)
            print(data_format, end='')
            time.sleep(GateTime - 0.1)
            
    output_file.close()
    qcm.disconnect()        

The above Python script generates a series of (time, frequency, resistance) data tuples,
printed on the screen and saved into a file named 'qcm-data.txt'.


    0.00 4996689.10  13.861
    0.97 4996689.10  13.861
    2.03 4996689.10  13.859
    3.10 4996688.90  13.857
            .
            .
            .

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "srsinst.qcm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "QCM200, quartz crystal microbalanace, SRS, Stanford Research Systems",
    "author": "Chulhoon Kim",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/c8/89/12dcd7133a166f3cac6e57e3e9d55124f4935293125c4123352662538445/srsinst_qcm-0.1.0.tar.gz",
    "platform": null,
    "description": "# srsinst.qcm\r\n\r\n`srsinst.qcm` is a Python package to provide serial communication with the \r\n[Quartz Crystal Microbalance, QCM200](https://thinksrs.com/products/qcm200.html)\r\nfrom [Stanford Research Systems (SRS)](https://thinksrs.com/).\r\n\r\n`srsinst.qcm` uses [srsgui](https://pypi.org/project/srsgui/) package for the support of instrument communication and graphic user interface (GUI). \r\n\r\n![screenshot](https://github.com/thinkSRS/srsinst.qcm/blob/main/docs/_static/image/QCM200_screenshot.png?raw=true \" \").\r\n\r\n## Installation\r\nYou need a working Python 3.7 or later with `pip` (Python package installer) installed. \r\nIf you don't, [install Python](https://www.python.org/) to your system.\r\n\r\nTo install `srsinst.qcm` as an instrument driver , use Python package installer `pip` from the command line.\r\n\r\n    python -m pip install srsinst.qcm\r\n\r\nTo use it as a GUI application, create a virtual environment, \r\nif necessary, and install:\r\n\r\n    python -m pip install srsinst.qcm[full]\r\n\r\n\r\n## Run `srsinst.qcm` as GUI application\r\nIf the Python Scripts directory is in your PATH environment variable,\r\nstart the application by typing from the command line:\r\n\r\n    qcm\r\n\r\nIf not,\r\n\r\n    python -m srsinst.qcm\r\n\r\nwill start the GUI application.\r\n\r\nOnce running the GUI, you can:\r\n- Connect to a QCM200 from the Instruments menu.\r\n- Select a task from the Task menu.\r\n- Press the green arrow to run the selected task. \r\n\r\nYou can write your own task(s) or modify an existing one and run it \r\nfrom the GUI application, too. For writing a task for the GUI application, \r\nrefer the document on [srsgui package](https://thinksrs.github.io/srsgui/index.html).\r\n\r\n## Use `srsinst.qcm` as instrument driver\r\n* Start a Python interpreter, a Jupyter notebook, or an editor of your choice \r\nto write a Python script.\r\n* Import the **QCM200** class from `srsinst.qcm` package.\r\n* Create an instance of the **QCM200** and connect for the serial communication.\r\n\r\n|\r\n\r\n\r\n    C:\\>python\r\n    Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32\r\n    Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n    >>> \r\n    >>> from srsinst.qcm import QCM200\r\n    >>> qcm = QCM200('serial', 'COM3', 9600)\r\n    >>> qcm.check_id()\r\n    ('QCM200', '136058', 'Rev0.91')\r\n\r\n\r\nIf you get the reply with *check_id()* method as shown above, \r\nyou are ready to configure and acquire data from your QCM200.\r\n\r\nThe remote control and data acquisition of of QCM200 is simple: \r\nSelect the gate time you want to use among 0.1s, 1.0s, and 10.0s;\r\ncheck if a new set of frequency and resistance data is available; \r\nand read data.\r\n\r\n\r\n    >>>  # Query the current date time\r\n    >>> qcm.cmd.gate_time\r\n    0.1\r\n    >>>  # Change the gate time to 1.0 s\r\n    >>> qcm.cmd.gate_time = 1.0\r\n    >>> Check if the gate time is changed\r\n    >>> qcm.cmd.gate_time\r\n    1.0\r\n    >>>  # Query frequency \r\n    >>> qcm.cmd.frequency\r\n    4999699.7\r\n    >>>  # Query resistance \r\n    >>> qcm.cmd.resistance\r\n    13.756\r\n    >>>\r\n\r\nYou can view all the commands available in the `cmd` component as following. \r\n\r\n\r\n    >>> qcm.cmd.dir\r\n      {'components': {}, \r\n       'commands': {\r\n           'id_string': ('QCMGetCommand', 'I'), \r\n           'display_mode': ('DictCommand', 'D'),  \r\n           'frequency_scale': ('DictCommand', 'V'), \r\n           'gate_time': ('DictCommand', 'P'), \r\n           'frequency': ('QCMFloatGetCommand', 'F'), \r\n           'frequency_offset': ('FloatGetCommand', 'G'), \r\n           'resistance': ('QCMFloatGetCommand', 'R'), \r\n           'resistance_offset': ('FloatGetCommand', 'S'), \r\n           'status': ('QCMIntGetCommand', 'B'), \r\n           'timebase': ('DictCommand', 'T')}, \r\n       'methods': [\r\n            'reset_frequency_offset', \r\n            'reset_resistance_offset']\r\n       }\r\n    >>>\r\n\r\nFor remote command details, refer to the\r\n[QCM200 manual appendix B](https://www.thinksrs.com/downloads/pdfs/manuals/QCM200m.pdf#page=117).\r\n\r\nHere is a simple, yet complete python script to acquire data from a QCM200\r\nusing `srsinst.qcm` package.\r\n\r\n\r\n    import time\r\n    from srsinst.qcm import QCM200\r\n    \r\n    GateTime = 1.0                             # Select among 0.1 s, 1.0 s, or 10 s\r\n    DataAcquisitionTime = 600                  # Data collection time in seconds\r\n                                               # Connect to a QCM. Change the address for the COM port used \r\n    qcm = QCM200('serial', 'COM3', 9600)       # For Linux systems, 'COM3' will be like '/dev/ttyUSB1'.\r\n    qcm.cmd.gate_time = GateTime               # Set the gate time\r\n    \r\n    output_file = open('qcm-data.txt', 'wt')   # Open a file to write data\r\n    \r\n    time_elapsed = 0.0\r\n    initial_time = time.time()\r\n    \r\n    while time_elapsed < DataAcquisitionTime:  \r\n        time_elapsed = time.time() - initial_time\r\n        new_data = qcm.get_data_if_both_new()  # Data available when Both F and R data are new.\r\n        if new_data:\r\n            data_format = f'{time_elapsed:7.2f} {new_data[0]:10.2f} {new_data[1]:7.3f}\\n'\r\n            output_file.write(data_format)\r\n            print(data_format, end='')\r\n            time.sleep(GateTime - 0.1)\r\n            \r\n    output_file.close()\r\n    qcm.disconnect()        \r\n\r\nThe above Python script generates a series of (time, frequency, resistance) data tuples,\r\nprinted on the screen and saved into a file named 'qcm-data.txt'.\r\n\r\n\r\n    0.00 4996689.10  13.861\r\n    0.97 4996689.10  13.861\r\n    2.03 4996689.10  13.859\r\n    3.10 4996688.90  13.857\r\n            .\r\n            .\r\n            .\r\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Instrument driver package for the Quartz Crystal Microbalance, QCM200 from Stanford Research Systems (SRS)",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [
        "qcm200",
        " quartz crystal microbalanace",
        " srs",
        " stanford research systems"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ce4fb078d0df41cb8a1e2fbdb3504d00d31c1ca59260035d6545a6088410e84",
                "md5": "536bab6a8cdf0b44d85ce1fa68474612",
                "sha256": "60e305bbdefcee968045f5355cdb56da54198507a2f3efbfcefb7864338b9875"
            },
            "downloads": -1,
            "filename": "srsinst.qcm-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "536bab6a8cdf0b44d85ce1fa68474612",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10690,
            "upload_time": "2024-08-31T00:57:52",
            "upload_time_iso_8601": "2024-08-31T00:57:52.755196Z",
            "url": "https://files.pythonhosted.org/packages/8c/e4/fb078d0df41cb8a1e2fbdb3504d00d31c1ca59260035d6545a6088410e84/srsinst.qcm-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c88912dcd7133a166f3cac6e57e3e9d55124f4935293125c4123352662538445",
                "md5": "2aa1129ccbb40bc0e90bb312ba1d7f66",
                "sha256": "977a60459fe417255775cf3976feb2104e26218aa7d7cd59b9095b9ab3285a19"
            },
            "downloads": -1,
            "filename": "srsinst_qcm-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2aa1129ccbb40bc0e90bb312ba1d7f66",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 103105,
            "upload_time": "2024-08-31T00:57:54",
            "upload_time_iso_8601": "2024-08-31T00:57:54.263829Z",
            "url": "https://files.pythonhosted.org/packages/c8/89/12dcd7133a166f3cac6e57e3e9d55124f4935293125c4123352662538445/srsinst_qcm-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-31 00:57:54",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "srsinst.qcm"
}
        
Elapsed time: 0.35827s