beautypg.com

Handling communications – ClearOne Writing StreamNet User Manual

Page 15

background image

4-1

All specifications subject to change without notification. All rights reserved. Copyright © 2007 NetStreams

Main +1 512.977-9393 / fax +1 512.977.9398 / Toll Free Technical Support +1 866-353-3496

3600 W. Parmer Lane, Suite 100; Austin, TX 78727 /

www.netstreams.com.

NOTE

Chapter

4

Handling Communications

Most device drivers will need some mechanism for talking to a controlled device. In
the StreamNet system, that capability is provided by a generalized I/O Stream
mechanism.

A stream can be created using a string-based configuration string, the precise format of
which depends on the details of the connection. Once the stream is created, the details
of the underlying transport mechanism (such as RS-232, TCP/IP, or some other
mechanism) is identical for all streams. This allows the same driver and code to be
used to control a device regardless of the physical connection type.

A stream is created with the createStream function:

stream = createStream(“comm://

0;baud=9600;parity=n”);

Once created, the stream can be read from and written to using the read and write
functions:

input = stream:read()

stream:write(input)

Use the “:” syntax to
pass the stream as an
argument to the read
and write functions.

Many devices have asynchronous outputs, i.e., outputs that are not in direct response
to some command being sent down. The preferred mechanism of dealing with such
responses is to define and enable an asynchronous response handler:

function input(stream, line)

… handle async response in “line”

end

stream:startAsyncInput(input, {endString = “\n”})