in BusTools/SpiTestTool/main.cpp [178:272]
void ShowPrompt (SpiDevice^ device)
{
while (std::wcin) {
std::wcout << L"> ";
std::wstring line;
if (!std::getline(std::wcin, line)) {
return;
}
std::wistringstream linestream(line);
std::wstring command;
linestream >> command;
if ((command == L"q") || (command == L"quit")) {
return;
} else if ((command == L"h") || (command == L"help")) {
std::wcout << Help;
} else if (command == L"write") {
std::vector<BYTE> writeBuf;
if (!(linestream >> writeBuf)) {
std::wcout << L"Usage: write { 55 a0 ... ff }\n";
continue;
}
device->Write(ArrayReference<BYTE>(
writeBuf.data(),
static_cast<unsigned int>(writeBuf.size())));
} else if (command == L"read") {
// expecting a single int, number of bytes to read
unsigned int bytesToRead;
if (!(linestream >> std::dec >> bytesToRead)) {
std::wcout << L"Expecting integer. e.g: read 4\n";
continue;
}
auto readBuf = ref new Array<BYTE>(bytesToRead);
device->Read(readBuf);
std::wcout << readBuf << L"\n";
} else if (command == L"writeread") {
// get a sequence of bytes, e.g.
// write 0 1 2 3 4 aa bb cc dd
std::vector<BYTE> writeBuf;
if (!(linestream >> writeBuf)) {
std::wcout << L"Usage: writeread { 55 a0 ... ff } 4\n";
continue;
}
unsigned int bytesToRead;
if (!(linestream >> std::dec >> bytesToRead)) {
std::wcout << L"Syntax error: expecting integer\n";
std::wcout << L"Usage: writeread { 55 a0 ... ff } 4\n";
continue;
}
auto readBuf = ref new Array<BYTE>(bytesToRead);
device->TransferSequential(
ArrayReference<BYTE>(
writeBuf.data(),
static_cast<unsigned int>(writeBuf.size())),
readBuf);
std::wcout << readBuf << L"\n";
} else if (command == L"fullduplex") {
std::vector<BYTE> writeBuf;
if (!(linestream >> writeBuf)) {
std::wcout << L"Usage: fullduplex { 55 a0 ... ff }\n";
continue;
}
auto readBuf = ref new Array<BYTE>(
static_cast<unsigned int>(writeBuf.size()));
device->TransferFullDuplex(
ArrayReference<BYTE>(
writeBuf.data(),
static_cast<unsigned int>(writeBuf.size())),
readBuf);
std::wcout << readBuf << L"\n";
} else if (command == L"info") {
auto settings = device->ConnectionSettings;
std::wcout << L" DeviceId: " << device->DeviceId->Data() << "\n";
std::wcout << L" ChipSelectLine: " << std::dec << settings->ChipSelectLine << L"\n";
std::wcout << L" Mode: " << std::dec << int(settings->Mode) << L"\n";
std::wcout << L" DataBitLength: " << std::dec << settings->DataBitLength << L"\n";
std::wcout << L" ClockFrequency: " << std::dec << settings->ClockFrequency << L" Hz\n";
} else if (command.empty()) {
// ignore
} else {
std::wcout << L"Unrecognized command: " << command <<
L". Type 'help' for command usage.\n";
}
}
}