X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcem-dt-885x%2Fprotocol.c;h=5f2972f68fd3b2fe05307c1a5565f01bd0feac23;hb=4c22355f046fefff812042ef9764199df17fb809;hp=3ae43a7042a51f322b115e4db1ecb76e16b34fec;hpb=32de50b7f3f0155589d90b273cac6b0c3dcfeec6;p=libsigrok.git diff --git a/hardware/cem-dt-885x/protocol.c b/hardware/cem-dt-885x/protocol.c index 3ae43a70..5f2972f6 100644 --- a/hardware/cem-dt-885x/protocol.c +++ b/hardware/cem-dt-885x/protocol.c @@ -685,3 +685,36 @@ SR_PRIV int cem_dt_885x_meas_range_set(const struct sr_dev_inst *sdi, return ret; } + +SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi) +{ + struct sr_serial_dev_inst *serial; + char c, cmd; + + serial = sdi->conn; + + /* Reopen the port in non-blocking mode, so we can properly + * detect when the device stops communicating. */ + serial_close(serial); + if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) + return SR_ERR; + + cmd = CMD_TOGGLE_POWER_OFF; + while (TRUE) { + serial_flush(serial); + if (serial_write(serial, (const void *)&cmd, 1) != 1) + return SR_ERR; + /* It never takes more than 23ms for the next token to arrive. */ + g_usleep(25 * 1000); + if (serial_read(serial, &c, 1) != 1) + /* Device is no longer responding. Good! */ + break; + } + + /* In case the user manually turns on the device again, reset + * the port back to blocking. */ + serial_close(serial); + serial_open(serial, SERIAL_RDWR); + + return SR_OK; +}