Communicating with SCRAMNet

From Lehigh RTMD Wiki
Jump to: navigation, search

The following sections describe how to use the RTMD Java package with MATLAB.

Contents

Creating the SCRAMNet object

%% Create a SCRAMNet reference called 'scr'
scr = edu.lehigh.nees.scramnet.ScramNetIO;

%% Initialize the SCRAMNet 
scr.initScramnet;  

%% Clear the memory
scr.clearSCR;   

%% Unmap the SCRAMNet
scr.unmapScramnet; 

Read and Write to SCRAMNet

%% Read a floating point value from address 1
address = 1;
result = scr.readSCR(address);

%% Read a floating point value from address 5 and scale it by 500
address = 5;
result = scr.readSCRscaled(address,500);

%% Read a fixed point integer value from address 1
address = 1;
result = scr.readSCRint(address);

%% Write a floating point value to address 1
address = 1;
value = 15;
scr.writeSCR(address,value);

%% Write a floating point value to address 7 and scale by 2000
address = 7;
value = 23.4;
scr.writeSCR(address,value,2000);

%% Write a fixed point integer value to address 1
address = 1;
value = 5;
scr.writeSCRint(address,value);

Communicating the the DAQ

%% Read in DAQ configuration from the Metadata Generator
daqxmlfile = java.io.File('daq.xml');

%% Parse the DAQ XML file
daqxml = edu.lehigh.nees.xml.ReadDAQXMLConfig(daqxmlfile); 

%% Retrieve the configuration
daq = daqxml.getDAQConfig;

%% Read a value from the DAQ and convert to engineering units
index = 5;
value = scr.readDAQ(daq.getDaqOffset(index),daq.getDaqGain(index),daq.getDaqVoffset(index),daq.getDaqVslope(index),daq.getDaqEUoffset(index),daq.getDaqEUslope(index));

%% Read counts from the DAQ
index = 10;
value = scr.readDAQ(daq.getDaqOffset(offset));

Create CSV Writer to log data

%% Create CSV Writer
csv = edu.lehigh.nees.util.CSVWriter;

%% Create the Date format to timestamp the file name
dateFormat = java.text.SimpleDateFormat('MM-dd-yyyy--HH-mm-ss');
theDate = java.util.Date;
theDateNow = dateFormat.format(theDate);
csvFilename = ['Output_' datestr(now,'yyyy-mm-dd--HH-MM-SS') '.csv'];
csv.open(csvFilename);

%% Create a header
header = {'Value1', 'Value2'};            
csv.writeHeader(header);

%% Write a new row
data = [value1, value2];
csv.write(data);

%% Close the file
csv.close;
Personal tools