Skip to content

Commit dfc0c01

Browse files
committed
serial init sequence option
1 parent 1315f51 commit dfc0c01

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Source/Device/Serial.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ namespace Device
200200

201201
if (!SetCommTimeouts(serial_handle, &ct))
202202
throw std::runtime_error("Serial: SetCommTimeouts failed. Error: " + GetLastErrorAsString());
203+
204+
if (init_sequence.length())
205+
{
206+
DWORD bytesWritten;
207+
if (!WriteFile(serial_handle, init_sequence.c_str(), init_sequence.length(), &bytesWritten, nullptr))
208+
{
209+
throw std::runtime_error("Serial: failed to send initialization sequence.");
210+
}
211+
}
203212
#else
204213
serial_fd = open(port.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC);
205214
if (serial_fd == -1)
@@ -266,7 +275,16 @@ namespace Device
266275

267276
int flags = fcntl(serial_fd, F_GETFL, 0);
268277
fcntl(serial_fd, F_SETFL, flags | O_NONBLOCK);
278+
279+
if (init_sequence.length())
280+
{
281+
if (write(serial_fd, init_sequence.c_str(), init_sequence.length()) < 0)
282+
{
283+
throw std::runtime_error("Serial: failed to send initialization sequence.");
284+
}
285+
}
269286
#endif
287+
270288
Device::Play();
271289

272290
lost = false;
@@ -305,6 +323,10 @@ namespace Device
305323
{
306324
print = Util::Parse::Switch(arg);
307325
}
326+
else if (option == "INIT_SEQ")
327+
{
328+
init_sequence = arg;
329+
}
308330
else
309331
Device::Set(option, arg);
310332

Source/Device/Serial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace Device
7171

7272
bool lost = false;
7373
bool print = false;
74+
std::string init_sequence;
7475

7576
static const uint32_t BUFFER_SIZE = 16 * 16384;
7677

0 commit comments

Comments
 (0)