![United Electronic Industries DN-SL-514 Series Скачать руководство пользователя страница 23](http://html.mh-extra.com/html/united-electronic-industries/dn-sl-514-series/dn-sl-514-series_user-manual_844925023.webp)
DNx-SL-514 Synchronous Serial Interface Board
Chapter 2
18
Programming with the High-Level API
May 2018
www.ueidaq.com
508.921.4600
© Copyright 2018
United Electronic Industries, Inc.
2.9
Reading Data
Reading data from the SL-514 is done using a
reader
object. As there is no
multiplexing of data (contrary to what’s being done with AI, DI, or CI sessions),
you need to create one reader object per master port to be able to read from
each port in the port list.
NOTE:
The number of bits read in the input word is programmed as
Word size
(3-32 bits) in the
CreateSSIMasterPort()
API.
The following sample code shows how to create a reader object tied to port 1
(
ssi1
) and read up to 10 data words from that
ssi
port.
2.10 Writing Data
Writing data to the SL-514 is done using a
writer
object. As there is no
multiplexing of data (contrary to what’s being done with AO, DO, or CO
sessions), you need to create one writer object per slave port to be able to write
to each port in the port list.
NOTE:
The number of bits written in the output word is programmed as
Word size
(3-32 bits) in the
CreateSSISlavePort()
API.
The following sample code shows how to create a writer object tied to
port 0 (
ssi0
) and send a frame of 128 data words to the SSI port.
2.11 Cleaning-up
the Session
The session object will clean itself up when it goes out of scope or when it is
destroyed. To reuse the object with a different set of channels or parameters,
you can manually clean up the session as follows:
// Create a reader and link it to the session’s stream, port 1
reader = new CUeiSSIReader(ssiSession.GetDataStream(), 1);
// we’ll want to store for 10 data words (uInt32-sized)
uInt32 dwords[10];
// enable grayEncoding (true), read up to 10 data words
reader->Read(true, 10, dwords, &numRead);
// Create a writer and link it to the session’s stream, port 0
writer = new CUeiSSIWriter(ssiSession.GetDataStream(), 0);
// initialize 128 uInt32 data words to 0x34 that we will write out
uInt32 dwords[128];
for(int i=0; i< 128; i++) dwords[i]=0x34;
// enable grayEncoding (true), write 128 data words,
// numWritten contains number of data words actually sent
writer->Write(true, 128, dwords, &numWritten);
// clean up the sessions
ssiSession.CleanUp();