Skip to content

Commit 3e830e1

Browse files
committed
First commit of MCC device, after removing from private ExperimentSystem repo.
1 parent 4720cea commit 3e830e1

6 files changed

Lines changed: 236 additions & 1 deletion

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "MCCDaq-libusb-driver"]
2+
path = MCCDaq-libusb-driver
3+
url = https://github.com/SachsLab/MCCDaq-libusb-driver.git

CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
PROJECT(MCCOutlet)
4+
5+
# General settings
6+
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
7+
cmake_policy(SET CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default.
8+
IF(UNIX)
9+
# c++11 for nullptr and others
10+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
11+
ENDIF()
12+
13+
add_subdirectory(MCCDaq-libusb-driver)
14+
15+
# Third party packages
16+
SET(REQUIRED_LIBS)
17+
# LSL
18+
set(LSL_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../labstreaminglayer/LSL/liblsl)
19+
find_package(LSL REQUIRED)
20+
LIST(APPEND REQUIRED_LIBS ${LSL_LIBRARIES})
21+
22+
# Target executable
23+
add_executable(${PROJECT_NAME}
24+
${CMAKE_CURRENT_SOURCE_DIR}/MCCOutlet.cpp
25+
)
26+
27+
target_include_directories(${PROJECT_NAME} PRIVATE
28+
mccdaq
29+
${LSL_INCLUDE_DIRS}
30+
)
31+
32+
target_link_libraries(${PROJECT_NAME}
33+
mccdaq
34+
${REQUIRED_LIBS}
35+
)
36+
37+
IF(WIN32)
38+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
39+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
40+
${LSL_BINARY_RELEASE}
41+
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
42+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
43+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
44+
${LSL_BINARY_DEBUG}
45+
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
46+
ENDIF()

MCCDaq-libusb-driver

Submodule MCCDaq-libusb-driver added at a71dd48

MCCOutlet.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "lsl_cpp.h"
2+
#include <iostream>
3+
#include <time.h>
4+
#include <stdlib.h>
5+
#include "mccdevice.h"
6+
using namespace std;
7+
8+
MCCDevice* device;
9+
const char *channels[] = {"RAW1","SPK1","RAW2","SPK2","RAW3","SPK3","NC1","NC2"};
10+
unsigned short * data;
11+
12+
int main(int argc, char* argv[])
13+
{
14+
string name = "MCCDaq";
15+
string type = "RawBrainSignal";
16+
try {
17+
18+
device = new MCCDevice(USB_1608_FS_PLUS);
19+
device->sendMessage("AISCAN:STOP");
20+
device->flushInputData(); // Flush out any old data from the buffer
21+
device->sendMessage("AISCAN:XFRMODE=BLOCKIO"); // Good for fast acquisitions.
22+
//device->sendMessage("AISCAN:XFRMODE=SINGLEIO"); // Good for slow acquisitions
23+
device->sendMessage("AISCAN:SAMPLES=0"); // Set to continuous scan.
24+
device->sendMessage("AISCAN:RANGE=BIP5V");//Set the voltage range on the device
25+
device->sendMessage("AISCAN:LOWCHAN=0");
26+
device->sendMessage("AISCAN:HIGHCHAN=5");
27+
device->sendMessage("AISCAN:RATE=16384");
28+
//device->mSamplesPerBlock = 512;
29+
//device->mScanParams.samplesPerBlock = 32/8; // nSamples*nChannels must be integer multiple of 32.
30+
device->reconfigure();
31+
32+
33+
lsl::stream_info info(name, type, 6, 16384, lsl::cf_float32, string(name) += type);
34+
35+
// add some description fields
36+
lsl::xml_element info_xml = info.desc();
37+
lsl::xml_element manufac_xml = info_xml.append_child_value("manufacturer", "MeasurementComputing");
38+
lsl::xml_element channels_xml = info.desc().append_child("channels");
39+
int k;
40+
for (k = 0; k < 6; k++)
41+
{
42+
lsl::xml_element chn = channels_xml.append_child("channel");
43+
chn.append_child_value("label", channels[k])
44+
.append_child_value("unit", "V")
45+
.append_child_value("type", "LFP");
46+
}
47+
48+
// make a new outlet
49+
lsl::stream_outlet outlet(info);
50+
51+
int dataLengthSamples = 512 * 6;
52+
std::vector<std::vector<float> > chunk(512, std::vector<float>(6)); // Used by LSL
53+
unsigned short *data = new unsigned short[dataLengthSamples]; // Pulled from the device.
54+
55+
device->sendMessage("AISCAN:START"); // Start the scan on the device
56+
cout << "Now sending data...";
57+
58+
unsigned t;
59+
int c, s;
60+
//double timestamp = lsl::local_clock();
61+
for (t=0; ; t++) {
62+
//device->getBlock();
63+
device->readScanData(data, dataLengthSamples);
64+
for(c=0; c<6; c++)
65+
{
66+
for(s=0; s<512; s++)
67+
{
68+
chunk[s][c] = device->scaleAndCalibrateData( data[(s*6)+c], c);
69+
}
70+
}
71+
outlet.push_chunk(chunk);// , timestamp);
72+
//timestamp += 512.0/16384.0;
73+
//cout << "Pushed chunk at timestamp " << timestamp << " (diff=" << lsl::local_clock()-timestamp << ")." << endl;
74+
}
75+
76+
} catch(std::exception &e) {
77+
cerr << "Got an exception: " << e.what() << endl;
78+
}
79+
cout << "Press any key to exit. " << endl; cin.get();
80+
device->sendMessage("AISCAN:STOP");
81+
delete device;
82+
return 0;
83+
}

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
11
# LSL-MeasurementComputing
2-
(Unsupported) Labstreaminglayer application for Measurement Computing device(s)
2+
(Unsupported) Labstreaminglayer application for Measurement Computing device(s).
3+
4+
This application was pulled out of another private repository (ExperimentSystem).
5+
It is no longer in use and only very limited support is available.
6+
7+
## Build
8+
9+
`mkdir build`
10+
11+
`cd build`
12+
13+
`cmake ..` or, in Windows, `cmake .. -G "Visual Studio 12 Win64"`
14+
15+
`make`
16+
17+
In linux, it will be further necessary to modify the udev rules so that the program can access the device without root permissions. (See Q7 [here](ftp://lx10.tx.ncsu.edu/pub/Linux/drivers/README))
18+
19+
`sudo cp ../61-mcc.rules /etc/udev/rules.d`
20+
21+
`sudo udevadm trigger`
22+
23+
## Use
24+
25+
Run the application (e.g. `./MCCOutlet`)
26+
27+
This will create a LSL stream called MCCDaq.
28+
It has 6 channels.
29+
It is sampling at 16384 Hz.
30+
This stream will push 512 float samples on every frame at 32 frames per second.

cmake/FindLSL.cmake

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# - Try to find the labstreaminglayer library
2+
#
3+
# LSL_FOUND - system has lsl
4+
# LSL_INCLUDE_DIRS - the lsl include directory
5+
# LSL_LIBRARIES - Link these to use lsl
6+
# LSL_BINARIES
7+
8+
set(LSL_ROOT_DIR
9+
"${LSL_ROOT_DIR}"
10+
CACHE
11+
PATH
12+
"Directory to search for LabStreamingLayer API")
13+
14+
15+
IF (LSL_INCLUDE_DIRS AND LSL_LIBRARIES)
16+
17+
# in cache already
18+
set(LSL_FOUND TRUE)
19+
20+
ELSE (LSL_INCLUDE_DIRS AND LSL_LIBRARIES)
21+
IF(NOT LSL_ROOT_DIR)
22+
message(STATUS "LSL_ROOT_DIR not set. Use `cmake [...] -DLSL_ROOT_DIR=<path/to/LSL/liblsl>")
23+
message("\tDefaulting to ${CMAKE_CURRENT_LIST_DIR}/../../../LSL/liblsl")
24+
SET(LSL_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../LSL/liblsl CACHE PATH "Path to local liblsl")
25+
ENDIF()
26+
27+
FIND_PATH(LSL_INCLUDE_DIRS
28+
NAMES
29+
lsl_cpp.h
30+
PATHS
31+
${LSL_ROOT_DIR}/include
32+
)
33+
34+
IF (${CMAKE_C_SIZEOF_DATA_PTR} EQUAL 8)
35+
SET(_arch 64)
36+
ELSE()
37+
SET(_arch 32)
38+
ENDIF()
39+
40+
# LSL prefixes all libs with 'lib'.
41+
# This is expected in UNIX.
42+
SET(MY_PREFIX "")
43+
# But is unusual in Windows.
44+
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
45+
SET(MY_PREFIX lib)
46+
ENDIF()
47+
48+
find_library(LSL_LIBRARY_RELEASE
49+
NAMES ${MY_PREFIX}lsl${_arch}
50+
PATHS ${LSL_ROOT_DIR}/bin
51+
)
52+
53+
find_library(LSL_LIBRARY_DEBUG
54+
NAMES ${MY_PREFIX}lsl${_arch}-debug
55+
PATHS ${LSL_ROOT_DIR}/bin
56+
)
57+
SET(LSL_LIBRARIES
58+
debug ${LSL_LIBRARY_DEBUG}
59+
optimized ${LSL_LIBRARY_RELEASE})
60+
61+
find_file(LSL_BINARY_RELEASE
62+
NAMES liblsl${_arch}${CMAKE_SHARED_LIBRARY_SUFFIX}
63+
PATHS ${LSL_ROOT_DIR}/bin
64+
)
65+
find_file(LSL_BINARY_DEBUG
66+
NAMES liblsl${_arch}-debug${CMAKE_SHARED_LIBRARY_SUFFIX}
67+
PATHS ${LSL_ROOT_DIR}/bin
68+
)
69+
70+
INCLUDE(FindPackageHandleStandardArgs)
71+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LSL DEFAULT_MSG LSL_INCLUDE_DIRS LSL_LIBRARIES LSL_BINARY_DEBUG LSL_BINARY_RELEASE)
72+
MARK_AS_ADVANCED(LSL_INCLUDE_DIRS LSL_LIBRARIES LSL_BINARY_DEBUG LSL_BINARY_RELEASE)
73+
74+
ENDIF (LSL_INCLUDE_DIRS AND LSL_LIBRARIES)

0 commit comments

Comments
 (0)