|
Edited by krjdev at 2020-5-14 01:38
Okay the following simple code returns the device id string:
- #include <stdio.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <string.h>
- int main(int argc, char *argv[])
- {
- int fd;
- unsigned char buf[1024];
- int ret;
- int flags;
-
- fd = open("/dev/usbtmc0", O_RDWR);
-
- if (fd == -1) {
- printf("Could not open device\n");
- return 1;
- }
-
- flags = fcntl(fd, F_GETFL, 0);
- fcntl(fd, F_SETFL, flags | O_NONBLOCK);
-
- ret = write(fd, "*IDN?\n", strlen("*IDN?\n"));
-
- if (ret == -1) {
- printf("Could not write to device\n");
- close(fd);
- return 1;
- }
-
- sleep(1);
-
- ret = read(fd, buf, 1024);
-
- if (ret == -1) {
- printf("Could not read from device\n");
- close(fd);
- return 1;
- }
-
- buf[ret] = '\0';
- printf("%s\n", buf);
- close(fd);
- return 0;
- }
Copy the Code
The output:
- $ ./dso
- Hantek, DSO4254C, CN1830002001956, 1.1.2(191026.0)
- $
Copy the Code
|
|