Default Configuration of Serial COM Ports

You can set the default configuration for all the serial ports opened in your COBOL application, by setting it in the .NET application configuration file. This file can have a section called “SerialPortDefaultOptions”, where you set the name/value pairs for the required options.

You can override these defaults for a specific output file, by using the SELECT … ASSIGN syntax.

In the following example configuration file, the section "SerialPortDefaultOptions" is declared and, at the end of the file, the options are specified:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
 <configSections>
   <sectionGroup name="MicroFocus.COBOL.Application">
    <section name="Switches"     type="System.Configuration.NameValueSectionHandler" />
    <section name="Environment"  type="System.Configuration.NameValueSectionHandler" />
   </sectionGroup>
        
   <!--The following code declares a section group for run-time configuration -->
   <sectionGroup name="MicroFocus.COBOL.Runtime">
    <section name="Tunables" type="System.Configuration.NameValueSectionHandler" />
     <section name="Switches" type="System.Configuration.NameValueSectionHandler" />
     <section name="SerialPortDefaultOptions"       
              type="System.Configuration.NameValueSectionHandler" />
   </sectionGroup>
 </configSections>

 <MicroFocus.COBOL.Application>
  <Switches/>
  </Switches>
  <Environment/ >
 </MicroFocus.COBOL.Application>
    
 <MicroFocus.COBOL.Runtime>
   <Tunables / >
   <Switches />
   <SerialPortDefaultOptions>
     <add key="BAUD" value="9600" />
     <add key="DATABITS" value="8" />
     <add key="PARITY" value="N" />
     <add key="STOPBITS" value="1" />
     <add key="TIMEOUT" value="2000" />
   </SerialPortDefaultOptions>
 </MicroFocus.COBOL.Runtime>
</configuration

Related Topics: