Time Saving Programming. John Markham, Janet Albers

Similar documents
Programming Style. Quick Look. Features of an Effective Style. Naming Conventions

Working with JavaScript

Introduction to Modules. Chapter 3. Defining and Calling a Module. Introduction to Modules. 5 Benefits of Modules. Modules CSUS, Spring 2016

The compiler is spewing error messages.

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Introduction to Python Code Quality

Reliable programming

1) Microcom GTX User s Manual 2) Microcom GTX GUI Software 3) Campbel Scientific CR1000 User s Manual 4) Campbell Scientific LoggerNet Software

Text Input and Conditionals

Chapter Goals. Contents LOOPS

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

The Dynamic Typing Interlude

Garbage Collection (1)

Topic 6: A Quick Intro To C

Flowcharts for Picaxe BASIC

This is the basis for the programming concept called a loop statement

Computing and compilers

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

CSE200 Lecture 6: RECURSION

Software Development & Education Center C Programming

Method & Tools for Program Analysis & Design

An Overview of the BLITZ System

Chapter 3: Modules. Starting Out with Programming Logic & Design. Second Edition. by Tony Gaddis

Exercise 6 - Addressing a Message

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define


Quiz 1: Functions and Procedures

Programming II (CS300)

Lesson Seven: Holding Gestures

Implementing an Algorithm for Boomerang Fraction Sequences in Python

The Design Process. General Development Issues. C/C++ and OO Rules of Thumb. Home

LECTURE 0: Introduction and Background

Programming in the Real World. Dr. Baldassano Yu s Elite Education

Repetition Through Recursion

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

This section provides some reminders and some terminology with which you might not be familiar.

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

RCX Tutorial. Commands Sensor Watchers Stack Controllers My Commands

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

Assertions, pre/postconditions

Smaller, simpler, subcomponent of program Provides abstraction

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

Our Strategy for Learning Fortran 90

The SC receives a public IP address from the DHCP client of the ISP. All traffic is automatically sent out through the WAN interface.

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

9.2 Linux Essentials Exam Objectives

Simple AngularJS thanks to Best Practices

Error Code. GO Software Pty Limited Map: 27 Tacoma Blvd, Pasadena SA 5042 ABN: ACN:

CS64 Week 5 Lecture 1. Kyle Dewey

Lesson 1 Python: Interactive Fiction

If you don t, it will return the same thing as == But this may not be what you want... Several different kinds of equality to consider:

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

IT 374 C# and Applications/ IT695 C# Data Structures

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

APPENDIX B. Fortran Hints

Learning vrealize Orchestrator in action V M U G L A B

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Lesson 2 Variables and I/O

PROBLEM SOLVING 11. July 24, 2012

Chapter 4: Writing and Designing a Complete Program. Programming Logic and Design, Third Edition Introductory

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Starting to Program in C++ (Basics & I/O)

Chapter 5 Errors. Bjarne Stroustrup

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Eclipse CDT Tutorial. Eclipse CDT Homepage: Tutorial written by: James D Aniello

CSE 142/143 Unofficial Style Guide

Errors. Lecture 6. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

Iteration. # a and b are now equal # a and b are no longer equal Multiple assignment

(Refer Slide Time: 00:26)

Unit 8: Working with Actions

CS 3 Introduction to Software Engineering. 3: Exceptions


Optimising for the p690 memory system

Process Context & Interrupts. New process can mess up information in old process. (i.e. what if they both use the same register?)

Tips for Reducing Formula Size

COP 1220 Introduction to Programming in C++ Course Justification

Writing to and reading from files

Experiment 3 Introduction to Verilog Programming using Quartus II software Prepared by: Eng. Shatha Awawdeh, Eng.Eman Abu_Zaitoun

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

EV3 Programming Workshop for FLL Coaches

Chapter 4 Introduction to Control Statements

C Functions. 5.2 Program Modules in C

Data paths and control logic

COMP1730/COMP6730 Programming for Scientists. Testing and Debugging.

ME 461 C review Session Fall 2009 S. Keres

a b c d a b c d e 5 e 7

QUIZ Friends class Y;

10 C Language Tips for Hardware Engineers

G. Tardiani RoboCup Rescue. EV3 Workshop Part 1 Introduction to RobotC

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

Debugging with gdb and valgrind

Methods. CSE 114, Computer Science 1 Stony Brook University

The %let is a Macro command, which sets a macro variable to the value specified.

Types and Static Type Checking (Introducing Micro-Haskell)

Call with Current Continuation Patterns

Types and Static Type Checking (Introducing Micro-Haskell)

KAREL JR 3 STUDENT JOURNAL REVISED APRIL 19, 2017 NAME SCHOOL, CLASS, PERIOD

4.2 Variations on a Scheme -- Lazy Evaluation

Transcription:

Time Saving Programming John Markham, Janet Albers

Short Cut

Short Cut Basic Measure and Store Programs Sensor Connections Setting up DataTables Cards and the SC115 are supported Wiring Diagrams copy and paste from *.DEF file All new Edlog programs. If it can t be written and maintained completely in Short Cut use a CRBasic datalogger. Multiplexers Calculations & Control

Custom Sensors

Custom Sensors Article https://www.campbellsci.com/blog/create-customsensors-short-cut

CRBasic Functions and Subroutines

About Subroutines and Functions Independent section of code that performs a specific task and can return a value or modify an argument Use when you need to: Develop and/or debug a large program (500 lines) Reuse code (3 or more times) Share code with others, including customers

Function Structure A Function returns a value. Write that value to a variable. Function CtoF_Func(TempC) Return (TempC * 1.8 + 32) EndFunction PTemp_F01 = CtoF_Func(PTemp_C)

Subroutine Structure A Subroutine is Called. Sub Units_Sub(TempC, TempF, TempK) TempF = TempC * 1.8 + 32 TempK = TempC + 273.15 EndSub Call Units_Sub(PTemp_C, PTemp_F02, Ptemp_K01)

Which should I use? Subroutine First choice or you re not sure which to use Multiple values need to be returned An array of values needs to be returned Working with strings holding data containing nulls Function You only want to return a single value, especially inside an expression for ease of use / readability TempF = CtoF(TempC) If CtoF(TempC) > 80 Then ACon = TRUE

Do: Use Subroutine unless Function is needed Structure the Subroutine or Function so that it is easily reusable to those already familiar with CRBasic instructions Use local variables whenever possible Initialize your local variables each call Break up complex processing tasks into several simpler ones Get in the habit of using Call when calling a subroutine

Don t: These probably work but test thoroughly. Put measurements in Functions Put measurements in Subroutines with arguments Put Scan/NextScan inside Subroutines or Functions Use recursive calls or deep nesting

Recycle Code

Only sell one kind of station The Easy Way

Challenges Different sensor combinations Different data collection requirements Different wiring/physical setup Different communication options

Strategies Don t write the same code twice Reduce, Reuse, Recycle Think ahead Start ahead of the game Consolidate settings Make a Master Program Write for everything, use what you need Divide and conquer

Don t Write The Same Code Twice: Modular Programming Write code in discrete pieces that can be moved between programs Keep track of all related code Variables/Data Tables Measurements Processing Update code with configuration details of new station

Don t Write The Same Code Twice: Using Functions and Subroutines Reuse the same code multiple times in the same program More info in the Function and Subroutine section

Think Ahead: CRBasic Templates Generate a cache of basic programs for different station types Establish program structure Create naming conventions

Think Ahead: Constant table ConstTable.EndConstTable Give it a name Reference constants where possible in program Use conditionals to select sections of code to run

Think Ahead: Constant table Change constants from multiple locations Terminal Table Monitor Keypad Watch out for recompile

Make A Master Program: Config File Master program is identical on every station Lock down propriety code Pull constant table out of program Include ( Drive:FileName )

Config File

Make A Master Program: DLD files CRBasic DLD files Edlog DLD files CRBasic.DLD files can be run on any logger. Beware: Some instructions/parameters are logger specific Select a compiler in CRBasic Editor

Make A Master Program: Conditional Compiling Allows only part of a program to be executed at run time #If...#Else...#Endif Allows declaration of parallel variables/constants LoggerType function Combine a DLD program, config file, and conditional compiling to create a Master Program Conditional Compile and Save

Loops and Logic If Then Else

Select Case Basic conditional statements If Then Add additional conditionals with else/else if statements Consolidate similar conditional statements into Select Case statements where possible

Bitwise Logic: AND, OR, NOT Combine nested or multiple If Then statements with AND, OR, and NOT for brevity and clarity Only performed on Integers. Other types converted before evaluated Beware: True (-1) 11111111, False(0) 00000000

For Next Executes a block of code a specified number of times Great for arrays Multi-dimensional arrays can be handled with nested For Next loops

Do.Loop Loops run the same code repeatedly While a condition is true Until a condition is met ExitDo While Wend is still accepted syntax, but not as flexible Watch out for infinite loops

Comments And Documentation

Need I say more? Put Comments in your CRBasic Programs Short Cut puts comments in. Your successor will thank you! Your favorite Support Engineer will thank you! You will thank yourself!

CRBasic Comments Header (Template) Version number Customer/Installation information Author s contact information Date Summary of changes made Wiring (from Short Cut *.DEF file)

CRBasic Comments Use comments to explain WHY you added an instruction or a section of code

CRBasic Comments Document all expressions or equations Use headings for each program section

CRBasic Comments Put comments at the end of Subroutine and Function declarations. They show up in the search.

CRBasic Comments When a sensor returns a group of variables (an Array) document what each value is. (And/or use Alias)

Readable Results

Readable Results

Debugging Tips

Debugging Tips: Hardware Use terminal window to sniff port traffic Check wiring and cabling If it is a serial problem switch Tx and Rx Does the hardware match the software/code

Debugging Tips: Code Use timers around loops Use counters in loops and logic Make all variables Public Slow scan rate or limit the number of runs to see what is happening Create variables to store intermediate values of interest Version programs

Debugging Tips: Code Test each 'module' separately (you did write modular code, right?) Comment out code until you find the offending lines

Debugging Tips: Rethink The Problem Get someone else to look at it Work on something else for a while and come back later Clearly articulate your problem to someone else (even an imaginary friend)

Debugging Tips: Compiler Just because the PC CRBasic compiler says a program can compile OK, doesn't mean it will run, or even compile in a real datalogger. Datalogger may have different (usually older) operating system Timing. PC can t check timing. Check the Status Table Use error line references in compile window Be careful, sometimes the error is precipitated by something going wrong before

Debugging Tips: Compiler Status Table Compile Results gives run-time errors Updated as program runs, not just at compile time Variable out of bounds Watchdog info memory errors

The End