From 0a40bc26d83fba557dfad1bbb2560fa7849da0ff Mon Sep 17 00:00:00 2001 From: Teuniz Date: Sat, 27 Jun 2015 19:37:06 +0200 Subject: [PATCH] Work in progress. --- global.h | 2 +- tmc_dev.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/global.h b/global.h index 2a9906d..8622c54 100644 --- a/global.h +++ b/global.h @@ -31,7 +31,7 @@ #define PROGRAM_NAME "DSRemote" -#define PROGRAM_VERSION "0.20_1506271641" +#define PROGRAM_VERSION "0.20_1506271933" #define MAX_PATHLEN 4096 diff --git a/tmc_dev.c b/tmc_dev.c index 800dcee..b2cc953 100644 --- a/tmc_dev.c +++ b/tmc_dev.c @@ -96,9 +96,10 @@ void tmcdev_close(struct tmcdev *dev) int tmcdev_write(struct tmcdev *dev, const char *cmd) { - int size; + int i, size, qry; - char buf[MAX_CMD_LEN + 16]; + char buf[MAX_CMD_LEN + 16], + str[256]; if(dev == NULL) { @@ -119,6 +120,11 @@ int tmcdev_write(struct tmcdev *dev, const char *cmd) return -1; } + if(cmd[strlen(cmd) - 1] == '?') + { + qry = 1; + } + strncpy(buf, cmd, MAX_CMD_LEN); buf[MAX_CMD_LEN] = 0; @@ -146,6 +152,24 @@ int tmcdev_write(struct tmcdev *dev, const char *cmd) printf("tmcdev error: device write error"); } + if(!qry) + { + for(i=0; i<20; i++) + { + usleep(50000); + + write(dev->fd, "*OPC?\n", 6); + + if(read(dev->fd, str, 128) == 2) + { + if(str[0] == '1') + { + break; + } + } + } + } + return size - 1; }