Skip to content

Commit 311223c

Browse files
committed
FEAT: added possibility to set/clear BREAK, DATA-TERMINAL-READY and REQUEST-TO-SEND serial signals (on Windows so far)
1 parent 083c0de commit 311223c

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

src/boot/modes.reb

+7
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ REBOL [
2828
line
2929
error
3030
]
31+
32+
*serial-modes* [
33+
brk ;break
34+
dtr ;data-terminal-ready
35+
rts ;request-to-send
36+
]
37+

src/boot/words.reb

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ owner
257257

258258
*port-modes* ;@@ modes are defined in modes.r file and these
259259
*console-modes* ;@@ placeholders are replaced here by make-boot.r script
260+
*serial-modes*
260261

261262
local-ip
262263
local-port

src/core/p-serial.c

+16
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@
226226
SET_CLOSED(req);
227227
}
228228
break;
229+
case A_MODIFY:
230+
arg = D_ARG(2);
231+
if (IS_WORD(arg)) {
232+
switch (VAL_WORD_CANON(arg)) {
233+
case SYM_BRK: req->modify.mode = 1; break;
234+
case SYM_RTS: req->modify.mode = 2; break;
235+
case SYM_DTR: req->modify.mode = 3; break;
236+
default: Trap1(RE_BAD_FILE_MODE, arg);
237+
}
238+
spec = D_ARG(3);
239+
if (!IS_LOGIC(spec)) Trap2(RE_INVALID_VALUE_FOR, spec, arg);
240+
req->modify.value = VAL_LOGIC(spec);
241+
OS_DO_DEVICE(req, RDC_MODIFY);
242+
}
243+
else Trap1(RE_BAD_FILE_MODE, arg);
244+
return R_ARG3;
229245

230246
default:
231247
Trap_Action(REB_PORT, action);

src/os/win32/dev-serial.c

+19-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static REBINT Set_Serial_Settings(HANDLE h, REBREQ *req)
129129
return DR_ERROR;
130130
}
131131

132-
JOIN_STR(fullpath,req->serial.path,MAX_SERIAL_DEV_PATH);
132+
JOIN_STR(fullpath,req->serial.path,MAX_SERIAL_DEV_PATH-5); // 5 because of "\\.\" and terminating byte
133133

134134
h = CreateFile(fullpath, GENERIC_READ|GENERIC_WRITE, 0, NULL,OPEN_EXISTING, 0, NULL );
135135
if (h == INVALID_HANDLE_VALUE) {
@@ -232,7 +232,7 @@ static REBINT Set_Serial_Settings(HANDLE h, REBREQ *req)
232232
}
233233

234234
#ifdef DEBUG_SERIAL
235-
printf("write %d ret: %d\n", req->length, req->actual);
235+
printf("write %d wrote: %lu ret: %d\n", req->length, result, req->actual);
236236
#endif
237237

238238
if (result < 0) {
@@ -241,7 +241,7 @@ static REBINT Set_Serial_Settings(HANDLE h, REBREQ *req)
241241
return DR_ERROR;
242242
}
243243
req->actual += result;
244-
req->data += result;
244+
//req->data += result;
245245
if (req->actual >= req->length) {
246246
Signal_Device(req, EVT_WROTE);
247247
return DR_DONE;
@@ -270,6 +270,21 @@ static REBINT Set_Serial_Settings(HANDLE h, REBREQ *req)
270270
return DR_DONE;
271271
}
272272

273+
/***********************************************************************
274+
**
275+
*/ DEVICE_CMD Modify_Serial(REBREQ *req)
276+
/*
277+
***********************************************************************/
278+
{
279+
boolean value = req->modify.value;
280+
switch (req->modify.mode) {
281+
case 1: EscapeCommFunction(req->handle, value ? SETBREAK : CLRBREAK); break;
282+
case 2: EscapeCommFunction(req->handle, value ? SETRTS : CLRRTS); break; // (request-to-send) signal
283+
case 3: EscapeCommFunction(req->handle, value ? SETDTR : CLRDTR); break; // (data-terminal-ready) signal
284+
}
285+
return DR_DONE;
286+
}
287+
273288

274289
/***********************************************************************
275290
**
@@ -287,7 +302,7 @@ static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] = {
287302
0, // poll
288303
0, // connect
289304
Query_Serial,
290-
0, // modify
305+
Modify_Serial,
291306
0, // create
292307
0, // delete
293308
0 // rename

0 commit comments

Comments
 (0)