Today s Outline. Computer Communications. Java Communications uses Streams. Wrapping Streams. Stream Conventions 2/13/2016 CSE 132



Similar documents
CS 1302 Ch 19, Binary I/O

Principles of Software Construction: Objects, Design, and Concurrency. Design Case Study: Stream I/O Some answers. Charlie Garrod Jonathan Aldrich

INPUT AND OUTPUT STREAMS

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

WRITING DATA TO A BINARY FILE

READING DATA FROM KEYBOARD USING DATAINPUTSTREAM, BUFFEREDREADER AND SCANNER

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

Readings and References. Topic #10: Java Input / Output. "Streams" are the basic I/O objects. Input & Output. Streams. The stream model A-1.

The Answer to the 14 Most Frequently Asked Modbus Questions

What is an I/O Stream?

Decorator Pattern [GoF]

Java Interview Questions and Answers

Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.

AVRO - SERIALIZATION

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files

Programming in Java

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

JAVA - FILES AND I/O

D06 PROGRAMMING with JAVA

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Logging. Working with the POCO logging framework.

Number Representation

AP Computer Science Java Subset

1 of 1 24/05/ :23 AM

Instruction Set Architecture (ISA)

Agenda. Network Programming and Java Sockets. Introduction. Internet Applications Serving Local and Remote Users

ROC Protocol Specifications Manual

C++ Wrapper Library for Firebird Embedded SQL

Software Architectures

Nemo 96HD/HD+ MODBUS

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Moven Studio realtime. streaming

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

Socket Programming. Srinidhi Varadarajan

RTP / RTCP. Announcements. Today s Lecture. RTP Info RTP (RFC 3550) I. Final Exam study guide online. Signup for project demos

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Java CPD (I) Frans Coenen Department of Computer Science

BLUETOOTH SERIAL PORT PROFILE. iwrap APPLICATION NOTE

MCI-Java: A Modified Java Virtual Machine Approach to Multiple Code Inheritance

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Arduino Lesson 5. The Serial Monitor

Select Correct USB Driver

Modern Robotics, Inc Core Device Discovery Utility. Modern Robotics Inc, 2015

Basic Programming and PC Skills: Basic Programming and PC Skills:

public static void main(string[] args) { System.out.println("hello, world"); } }

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Variables, Constants, and Data Types

Different Ways of Connecting to. 3DLevelScanner II. A.P.M Automation Solutions LTD. Version 3.0

Chapter 10. A stream is an object that enables the flow of data between a program and some I/O device or file. File I/O

Chapter One Introduction to Programming

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

1 The Java Virtual Machine

Lecture 22: C Programming 4 Embedded Systems

How To Write Portable Programs In C

Computing Concepts with Java Essentials

C++ INTERVIEW QUESTIONS

labs Attacking JAVA Serialized Communication By: Manish S. Saindane

MODBUS APPLICATION PROTOCOL SPECIFICATION V1.1b3 CONTENTS

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Caml Virtual Machine File & data formats Document version: 1.4

Advantech WebAccess Device Driver Guide. BwSNMP Advantech WebAccess to SNMP Agent (Simple Network Management Protocol) Device Driver Guide

ResellerPlus - Bulk Http API Specification. (This Document gives details on how to send messages via the Bulk HTTP API for the RouteSms SMPP System)

Java (12 Weeks) Introduction to Java Programming Language

Programming Methods & Java Examples

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Servo Motor API nxt_motor_get_count nxt_motor_set_count nxt_motor_set_speed

Additional Setup Instructions for Modbus: RTU, ASCII, TCP, Omni & Enron

CENTRONICS interface and Parallel Printer Port LPT

Transparent Redirection of Network Sockets 1

Programming Languages CIS 443

ND48-RS ASCII A2.04 Communication Protocol

The Hexadecimal Number System and Memory Addressing

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Files and Streams. Writeappropriatecodetoread,writeandupdatefilesusingFileInputStream, FileOutputStream and RandomAccessFile objects.

encoding compression encryption

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Introduction to Web Services

JavaPOS TM Introduction: 1

USER GUIDE EDBG. Description

CS 111 Classes I 1. Software Organization View to this point:

Signalling Control System Serial Train Information Interface

The Java Sound Internet Phone

Integrating the Internet into Your Measurement System. DataSocket Technical Overview

Consult protocol, Nissan Technical egroup, Issue 6

But for compatibility reasons the basic structure of the data area or the addressing mechanism of the protocol retained.

Core Java+ J2EE+Struts+Hibernate+Spring

Java the UML Way: Integrating Object-Oriented Design and Programming

DSX-Soft I/O Integration Software

BlueTooth RealTrace Terminal

URI and UUID. Identifying things on the Web.

Member Functions of the istream Class

IR Communication a learn.sparkfun.com tutorial

Introduction to Data Structures

Character Translation Methods

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Transcription:

Today s Outline Computer Communications CSE 132 Communicating between PC and Arduino Java on PC (either Windows or Mac) Streams in Java An aside on class hierarchies Protocol Design Observability Computer Communications Link that provides byte level data delivery Network Serial port Ability to send and receive on each endpoint Must use a protocol to understand anything other that individual bytes Individual data elements (ints, chars, strings, etc.) Higher level, application specific messages The user just pressed button X The pressure in vessel X is Y psi at time Z Needs to work across platforms E.g., Java on PC and C on Arduino Java Communications uses Streams Upstream writer, downstream reader Source Dest. Source writes to stream Destination reads from stream Either endpoint might be a file or some other input/output device, e.g., Dest. could be Arduino connected via serial port Source could be a temperature sensor Stream Conventions FIFO ordering (First In First Out) Protocol must be same at both ends of stream for effective communication to take place Stream of bytes? chars? integers? what is a char? Properties supported by streams that wrap other streams, e.g., InputStream stream = new InputStream( ); DataInputStream datain = new DataInputStream(stream); Wrapping Streams A stream can take another stream as a parameter to its constructor The outer stream adds functionality to the wrapped stream E.g., DataOutputStream out = new DataOutputStream( new BufferedOutputStream( new FileOutputStream( ) ) ); This is called decorator pattern 1

Communications in Java Decorating InputStream Open COM port with both InputStream and OutputStream objects Use SerialComm class, which we provide Works in Windows and Mac Wrap InputStream with BufferedInputStream Wrap BufferedInputStream with ViewInputStream Wrap ViewInputStream with DataInputStream You will write ViewInputStream, extending FilterInputStream readbyte() readint() Authoring ViewInputStream Decorating OutputStream Wrap OutputStream with ViewOutputStream Don t use BufferedOutputStream Wrap ViewOutputStream with DataOutputStream You will write ViewOutputStream, extending FilterOutputStream Aside on Java Class Hierarchies Example Hierarchy Scaling up programs Lots of objects? Use data structures such as: Lists Queues Lots of classes? Group related types Java packages Design hierarchically and exploit structure Object tostring() Ellipse Circle MovingCircle StillCircle Circle extends Ellipse All Circles are Ellipses Circle inherits from Ellipse Instance variables Methods Circle can override methods in Ellipse Circle can add new things 2

Benefits of Class Hierarchy How it relates to today s studio Capture relationships to simplify reasoning Save implementation effort (less code) by inheriting functionality Polymorphism Circle c = any Circle, including subtypes of Circle c.anymethoddefinedoncircle() MovingCircle Ellipse Circle StillCircle You will author ViewInputStream class It extends FilterInputStream class (which already exists) Child can use parent methods super. in child invokes method in parent FilterInputStream ViewInputStream Back to Communications Streams are sequences of bytes We need data at a higher level of abstraction Integers Floats, Doubles Characters Strings More Protocols must be designed to enable this Build bigger things out of streams of bytes Individual Data Elements (in Java Stream) Byte basic network element writebyte(), readbyte() in Data(Input/Output)Stream Character two bytes in Java writechar(), readchar(), high byte first Short Integer two bytes bits can be anything from 0x0000 to 0xffff writeshort(), readshort() Integer four bytes in Java value 2 31 to 2 31 1 writeint(), readint(), most significant byte (MSB) first Communicating Individual Data Elements in Arduino C Byte basic network element Stream., Stream.write() Character two bytes in Java Only 1 byte in C! Read and toss first byte, save second Integer two bytes bits can be anything from 0x0000 to 0xffff Read both bytes value = (first << 8) + second Long Integer four bytes value 2 31 to 2 31 1 Read bytes value = (first<<24) + (sec<<16) + (third<<8) + fourth Strings Not just a sequence of two byte characters! Network communication is language agnostic, so must acknowledge that others do things in different ways UTF 8 is common character encoding String is 2 byte length (of bytes in string), followed by Characters in UTF 8 encoding Supported by writeutf(), readutf() Need to build on Arduino side 3

Protocol Design What do we want to communicate? How do we want to say it? number is anchor of message Always first byte Unlikely in rest of message Reader can ignore bytes until it sees magic number and then receive Key tells what type of message Indicates both size and interpretation E.g., 2 byte temperature value E.g., 4 byte timestamp E.g., UTF 8 encoded error string Table of legal keys must be maintained Actual content of message Key tells how to interpret Observability What is really going on? Option 1: stare at the code until inspired When that doesn t work, make random change Option 2: don t assume the code you actually wrote does what you think it does! Alter code so that you discover what it really does On PC in Java, use the debugger! Or use System.out.print() to display on console On Arduino in C, use Serial.print() Observability in Communications Need to know what is really going across the communication link On sender, receiver, or maybe both: Display what is going out the output stream Display what is coming in the input stream Show the raw data (sequence of bytes) You can build these tools Do a good job and it will help you the rest of the semester! 4

Observability Tools in Java One for InputStream and one for OutputStream Extend FilterInputStream (and its counterpart) as ViewInputStream ViewInputStream s method should: from the provided InputStream Display the byte(s) as a hex values (0x00 to 0xff) This is the studio exercise this week Required for assignment ViewOutputStream will be next week s task This Week Studio Use SerialComm to receive bytes in Java from Arduino Author ViewInputStream Assignment Use protocol to send temperature, potentiometer value, and high alarm string to Java Note: will need to unify analog input reference for the two readings 5