{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define hostname\n",
    "HOSTNAME = \"192.168.1.100\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "\n",
    "pyrpl_folder = os.environ[\"pyrpl_path\"]\n",
    "sys.path.insert(0, pyrpl_folder)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:pyrpl.redpitaya:Successfully connected to Redpitaya with hostname 192.168.178.26.\n"
     ]
    }
   ],
   "source": [
    "import pyrpl\n",
    "\n",
    "p = pyrpl.Pyrpl(\n",
    "    config=\"\",  # do not use a config file\n",
    "    hostname=HOSTNAME,\n",
    ")\n",
    "rp = p.redpitaya  # shortcut for the the redpitaya handler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# setup both asgs\n",
    "for asg in [rp.asg0, rp.asg1]:\n",
    "    asg.setup(\n",
    "        waveform=\"square\",\n",
    "        amplitude=0.5,\n",
    "        offset=0,\n",
    "        frequency=1e6,\n",
    "        output_direct=\"off\",\n",
    "        trigger_source=\"immediately\",\n",
    "    )\n",
    "\n",
    "# make the assertion that signals are not synhronized\n",
    "ch1, ch2 = rp.scope.single()\n",
    "assert ((ch1 - ch2) != 0).any(), \"asg channel outputs are identical\"\n",
    "\n",
    "# manually check on the scope that signals are not synchronized\n",
    "rp.scope.setup(\n",
    "    input1=\"asg0\",\n",
    "    input2=\"asg1\",\n",
    "    duration=1e-6,\n",
    "    average=False,\n",
    "    trigger_source=\"asg0\",\n",
    "    rolling_mode=False,\n",
    "    running_state=\"running_continuous\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# setup the trigger pin\n",
    "rp.hk.expansion_P0_output = True\n",
    "rp.hk.expansion_P0 = False\n",
    "\n",
    "# setup asg trigger\n",
    "for asg in [rp.asg0, rp.asg1]:\n",
    "    asg.trigger_source = \"ext_positive_edge\"\n",
    "\n",
    "# launch the trigger by creating a 0-to-1 transition on trigger pin\n",
    "rp.hk.expansion_P0 = True\n",
    "rp.hk.expansion_P0 = False\n",
    "\n",
    "# make the assertion that signals are synhronized\n",
    "ch1, ch2 = rp.scope.single()\n",
    "assert ((ch1 - ch2) == 0).all(), \"asg channel outputs are not identical\"\n",
    "\n",
    "# now check that the asg signals are synchronized on the scope...\n",
    "rp.scope.setup(running_state=\"running_continuous\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
