Transcription

OptiSystemTutorials - C ComponentOptical Communication System Design SoftwareVersion 14

OptiSystemTutorials - C ComponentOptical Communication System Design SoftwareCopyright 2016 OptiwaveAll rights reserved.All OptiSystem documents, including this one, and the information contained therein, is copyright material.No part of this document may be reproduced, stored in a retrieval system, or transmitted in any form or by any means whatsoever,including recording, photocopying, or faxing, without prior written approval of Optiwave.DisclaimerOptiwave makes no representation or warranty with respect to the adequacy of this documentation or the programs which itdescribes for any particular purpose or with respect to its adequacy to produce any particular result. In no event shall Optiwave, itsemployees, its contractors or the authors of this documentation, be liable for special, direct, indirect, or consequential damages,losses, costs, charges, claims, demands, or claim for lost profits, fees, or expenses of any nature or kind.

Technical supportIf you purchased Optiwave software from a distributor that is not listed here, please send technicalquestions to your distributor.OptiwaveCanada/USTel(613) [email protected](613) 224-4706URLwww.optiwave.comOptiwave JapanJapanTel [email protected] 81.43.375.2644URLwww.optiwave.jpOptiwave EuropeEuropeTel 33 (0) 494 08 27 [email protected] 33 (0) 494 33 65 76URLwww.optiwave.eu

Table of contentsIntroduction . 1C Component Tutorials . 5Tutorial 1: Release and Debug modes, Basic manipulation of a Binary Signal .7Tutorial 2: Basic Manipulation of Mary Signals .23Tutorial 3: Basic Manipulation of Electrical Signals.37Tutorial 4: Electrical pulse shaper with M-ary input.43Tutorial 5: Binary controlled optical switch. .49Tutorial 6: Optical transverse mode converter .55Tutorial 7: Working with optical parameterized signals and noise bins.61Appendix 1: Overview of signal types .67Appendix 2: Debugging tips (release mode) .77

IntroductionIMPORTANT!To create and compile the C code for the Cpp Component you must have eitherMicrosoft Visual Studio 2013 Community or Professional installed on your computer.(Note: The Cpp Component is not currently compatible with Microsoft Visual Studio2015!).OptiSystem's Cpp Component, similar in operation to the MATLAB Component,allows users to create their own custom components, written directly in C , for usein OptiSystem projects. The user can also create their own internal graphs and resultsthat can be displayed within OptiSystem.The component can be configured in two modes:Release mode - The component project is compiled as a dynamic link library (.dll) inrelease mode. OptiSystem will load the “dll” during runtime. The signal data is passeddirectly from OptiSystem to the “dll” and then, after processing, from the “dll” back toOptiSystem. This is the mode to use when you wish to run OptiSystem and your C component within it.Debug mode - The component project is compiled as a stand-alone application (.exe)in debug mode. Running the component project from within the developerenvironment will allow the user to enter the code and set breakpoints. OptiSystemcreates copies of the signal data in various text files which will be loaded by theproject. The project knows where to obtain these files and their formatting by an XMLdata file it loads at runtime.The full documentation and a pre-configured project is available at the Optiwave C Component Home PageThe project is large with many classes available to the user. Due to the number ofconfiguration settings involved, it is recommended to create a copy of this defaultproject and add code to it for each component the user wishes to define. The usermay add as many classes as they wish to this project but it is not recommended thatthe user removes or alters the classes already provided other than at the defined entrypoint: Calculate API() in class DS SystemManager.cpp.The project has been set up so that very little changes must be made to switchbetween the Release and Debug modes. The user will not need to alter any of their1

code, just change some configuration settings and add a line of code to tell the projectwhere to find the XML file mentioned above. The two different modes are explainedin detail in Tutorial 1: Binary Signal Manipulation.The most effective method to learn the usage of OptiSystem's C component is tofollow the tutorials below. They will teach the user how to access and manipulate thebasic data structures, configure the project for release and debug mode, and usemany of the convenience functions built into the project.It is recommended that the user create a copy of the default project available at theOptiwave C Component Home Page for each tutorial, then follow along for themanipulations of the C code and the creation of the OptiSystem project.This document contains the following sections.Tutorials2 Tutorial 1: Release and Debug modes, Basic manipulation of a Binary Signal Tutorial 2: Basic Manipulation of Mary Signals Tutorial 3: Basic Manipulation of Electrical Signals Tutorial 4: Electrical pulse shaper with M-ary input Tutorial 5: Binary controlled optical switch. Tutorial 6: Optical transverse mode converter Tutorial 7: Working with optical parameterized signals and noise bins Appendix 1: Overview of signal types Appendix 2: Debugging tips (release mode)

3

4

C Component TutorialsThis section contains the following introductory tutorials for the Cpp (C ) Component. Tutorial 1: Release and Debug modes, Basic manipulation of a Binary Signal Tutorial 2: Basic Manipulation of Mary Signals Tutorial 3: Basic Manipulation of Electrical Signals Tutorial 4: Electrical pulse shaper with M-ary input Tutorial 5: Binary controlled optical switch. Tutorial 6: Optical transverse mode converter Tutorial 7: Working with optical parameterized signals and noise bins Appendix 1: Overview of signal types Appendix 2: Debugging tips (release mode)5

6

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALTutorial 1: Release and Debug modes, Basicmanipulation of a Binary SignalThis tutorial describes how to configure a project in either Release mode or Debugmode. It also demonstrates how to manipulate a binary signal.Release mode of operationPart 1: Create the “.dll” for the componentFollow the steps below to ensure that the project is configured properly to create a“dll” in release mode appropriate for OptiSystem.StepActionVerification of project configurations1Open the CppCoSimulation.sln located in the base directory of the providedproject in Visual Studio 2013.2Verify that the whole project is set to Release mode (x64) (see Fig 1).3Right-click on each directory listed in the Solution Explorer and make surethat the following key configuration values are set (the rest may stay asdefault)a. Go to Properties/Configuration Properties/Generalb. Verify that Platform Toolset is set to Visual Studio 2013 (v120) and theConfiguration/Platform is Active(Release)/Active(x64) (see Fig 2)If it is not, your project won't compile and/or link to OptiSystem correctlyFigure 17

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALFigure 2c.Right-click on Solution ‘CppCoSimulation’, selectProperties/Configuration Properties. Verify that the activeconfiguration is release. Verify all projects are configured for release x64and the build boxes are checked (Fig 3)Figure 3d. Right-click on CppCosimulation, select Properties/ConfigurationProperties/General. Verify that Configuration Type is Dynamic Library(Fig 4).If you wish, you may also change the Target Name from the default(which will name the resulting dynamic library as “CppCoSimulation.dll”).8

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALFigure 4e. Under Configuration Properties/Linker/System Verify thatSubSystem is set to Windows (Fig 5).Figure 5Implementation of code4Under CppCoSimulation/Source Files, double-click onDS SystemManager.cpp5Within this file, navigate to the function boolCDS SystemManager:Calculate API(). (Fig 6)This represents the entry point for your code into the project. For all of yourprojects, you will start your code here. You may create your own classes andfunctions which will be called from here.9

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALFigure 6Loading port data6Copy the following lines into the function (make sure to paste directly after“InitializeGlobals();” or the “DO NOT REMOVE” comment //// BINARY SIGNAL ///////CDS SignalBase* pOOSignal1 GetSignalFromOutputPort(1);//create an output portif (pOOSignal1 ! NULL){if (pOOSignal1- GetSignalName() "BinarySignal"){The first line loads the signal from the first (and in this case only) port. If youhad a second port to load, you would add: CDS SignalBase * pIOSignal2 GetSignalFromInputPort(2). The IF conditions have been added as a safetyprecaution. This will ensure that the calculation will only go ahead if the inputport is defined with the proper signal typeGetting binary data7Copy the following lines into the functionCDS BinarySignal binarySignal1 ////////////////////////// BINARY SIGNAL ////////This binary signal class holds both the sequence of bits (vector long binarySignal1.m Bits) and the bit rate (binarySignal1.GetBitRate()).10

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALManipulating data8Now that the data has been placed on a vector, we can manipulate this to ourrequirements. In this case we are simply performing a binary inverseoperation. Copy the following lines into the ////// DATA /////////////for (int i 0; i binarySignal1.m Bits.size(); i ){binarySignal1.m Bits[i] (binarySignal1.m Bits[i] 1) % 2;}//if value 0 - 1, if value 1 - 0//////////////////////////////////////////////// DATA ////////////Create an output port9Copy the following lines into the ////// BINARY SIGNAL ///////CDS SignalBase* pOOSignal1 GetSignalFromOutputPort(1);//create an output portif (pOOSignal1 ! NULL){if (pOOSignal1- GetSignalName() "BinarySignal"){This will create an output port for our data for OptiSystem to access. Checkshave been added to make sure that the calculation will only go ahead if theoutput port on the C component is configured correctlySet the output port signal to the binary signal10Copy the following lines into the functionPutBinarySignal(binarySignal1, pOOSignal1);//put the binary signal onto the output portCode for error checking11Copy the following lines into the functionEnsures that we close all the brackets for our safety precautions}else{return 0; //returns warning to OptiSystem -- output is not set correctly to binary} //if (pOOSignal1- GetSignalName() "BinarySignal")} //if (pOOSignal1 ! NULL)else{return 0; //returns warning to OptiSystem -- output put not created}} //if (pIOSignal1 ! NULL)} //if (pIOSignal1- GetSignalName() "BinarySignal")SaveOutputDataToFiles();//for debugging turn 1; //for successful run11

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALNote: The full code and an OptiSystem project for this function(Tutorial1SupplementaryFiles.zip) is available at the Optiwave C ComponentHome Page. Replace the DS SystemManager.cpp file in your project with theone given in the zip file. If you want to run in debug, you must also change thelocation of the XML given in CppCoSimulation.cpp. In addition change thelocation of the files in the OptiSystem projects to your particular files anddirectoriesNote we have added some code right at the beginning of the routine (as //////////////////////do not //////////////////#ifdef EXE CONSOLEm bInExecutableMode true;#elsem bInExecutableMode false;#endif// this flag can be useful for some parameters to be adjusted depending on the modeInitializeGlobals(); //set some of the key global parameters so they are avaliable in debug //////////////////do not //////////////////This code is not necessary to run this example, but it is a good idea to keep in all futureprojects.The variable m bInExecutableMode will be used in the next example. The commandInitializeGlobals(); is to make sure all global parameters are initialized correctly whenwe are running in debug mode.Build the dll1212The configurations and code are now finished, all that remains is to build thedynamic library. Within Visual Studio's menu, select Build/Build SolutionIf for some reason the dll is locked, you won't be able to build successfully. Ifthis is the case, you will either have to exit OptiSystem in order to release thedll or rename your output dll. The simplest method is to rename the Targetname of the dll, for example by renaming from (ProjectName) to (ProjectName) 1 (you can keep changing this name for each build) (SeeFig 7)

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALFigure 7Note: Make sure to load the appropriate dll in Step 3 (Part 2).13

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALPart 2: Creating an OptiSystem project to use the componentIn part 1 we created a dll for the component, we must now link this to an OptiSystemproject.StepActionVerification of project configurations1Open a session of OptiSystem and create the following system layout (Fig 8)The Cpp Component can be found under Default/External SoftwareTools/CoSimulationLibrary. Your PRBS may not connect to the CppComponent yet as you must first set the appropriate port structureFigure 8 Cpp component setup in OptiSystem2Set the input and output ports to binary (Fig 9)Figure 9 Cpp Component port settings3Load the dll (Fig 10)Note: If you kept your folder name as CppCoSimulation and the target nameas the default, your dll file will be at mulation.dll]14

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALFigure 10 Load Cpp dll4Run the projectThe configuration of the project is now complete. If you now run yoursimulation, you should get results similar to the following where the outputdata is the inverse of the input (see Fig 11)Note: If you receive a calculation warning “Calculating CppComponent.Warning while calculating component Cpp Component” checkto make sure that both the input and output ports are configured correctly tothe binary format.Figure 11Cpp Component simulation results15

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALDebug mode of operationOne cannot directly enter the debugger of their component project from OptiSystembecause OptiSystem is built in release mode (which is why the previous dll was alsobuilt in release mode). OptiSystem provides a solution to this problem by duplicatingonto text files all the signals that are to enter into the Cpp Component. These textfiles can then be loaded into the component project when running in debug mode. Inthis case, no modifications to the code in Calculate API are required. Below weexplain how to create the appropriate data files for the component and how to loadthem through the debugger.Part 1: Creating an OptiSystem project to output dataStepAction1Open a session of OptiSystem and create the following system layout (Fig12)The Cpp Cosimulation Visualizer can be found under Default/VisualizerLibrary/. This special visualizer serves to duplicate the data that would besent to the Cpp Component. We must now configure it appropriately.Figure 122Right-click on Cpp CoSimulation Visualizer and select Properties (Fig 13)Figure 1316

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNAL3Make sure Save Data As CPP XML Load File is checked (Fig 13)4Choose a location and Filename for the XML file by clicking on the grey box.In this example we will call the file testXML.txt and save it at [your Cpp projectlocation]\CppCoSimulation\testXML.txtThe XML file is a text file in XML format that will inform the component aboutall the ports and the locations of the data files.5Set the input and output ports to be exactly the same as the Cpp Component(binary) - Fig 14At the present time, the output port is not necessary, but we have included itfor future functionalityFigure 146On CPP Filename click on the grey box and select a name and location forthe binary signal data.For this example you could choose [your Cpp ote: You won't have to enter this filename in your code explicitly as thisinformation will be recorded in the XML file of step 4.7Run the programIf you double click on the visualizer, you will see the data for the portdisplayed in a format similar to the view signal visualizer. There is an arrowto scroll through the data on each port. The data you see on this visualizer isduplicated in the data file specified above and the XML file holds theinformation about the ports. These data files are shown in Fig 15.Note: Do not manipulate these data files, they are auto generated byOptiSystem17

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNALFigure 15Part 2: Creating a standalone “.exe” for debuggingStepAction1Open CppCoSimulation.sln located in the base directory of the providedproject in Visual Studio 20132Set/Verify that the project is set to Debug x64 mode (Fig 16)Figure 16 Properties/Configuration Properties/General18

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNAL3Right-click on Solution ‘CppCoSimulation’, Select Properties/ConfigurationProperties. Set/Verify all projects are configured for Debug x64 and the buildboxes are checked (Fig 17)Figure 174Right-click on CppCoSimulation. Under Configuration Properties/General,Set/Verify that Configuration Type is Application (see Fig 18). You may alsochange the Target Name from the default (which will name the resultingexecutable as “CppCoSimulationD.exe”).Figure 1819

TUTORIAL 1: RELEASE AND DEBUG MODES, BASIC MANIPULATION OF A BINARY SIGNAL5Under Configuration Properties/Linker/System, Set/Verify that SubSystem isset to Console (See Fig 19).Figure 196Under CppCoSimulation/Source Files, left double click onCppCoSimulation.cppFigure 207CppCoSimulation.cppWithin this file (see Fig 20), navigate to the function “int tmain(int argc,TCHAR* argv[])”. This is the starting point for your stand alone configuration.Add the following line to your code:argv[1] “[your Cpp project location]\\CppCoSimulation\\testXML.txt”;Note: You will have to modify this to your file location. The above would bethe case if a user named “