-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoding camera
More file actions
63 lines (49 loc) · 1.87 KB
/
Copy pathCoding camera
File metadata and controls
63 lines (49 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
int main() {
// The path to the serial device might be different on your machine
const char *serial_port_path = "/dev/ttyUSB0";
double sensor_clock_frequency_hz = ...; // You need to fill in the actual clock frequency here
double exposure_time_microseconds = 0.33;
int serial_port;
// Open the serial port
serial_port = open(serial_port_path, O_RDWR);
if (serial_port < 0) {
fprintf(stderr, "Error opening %s: %s\n", serial_port_path, strerror(errno));
return EXIT_FAILURE;
}
// Configure the serial port
struct termios tty;
memset(&tty, 0, sizeof tty);
// Error Handling
if (tcgetattr(serial_port, &tty) != 0) {
fprintf(stderr, "Error %d from tcgetattr: %s\n", errno, strerror(errno));
return EXIT_FAILURE;
}
// Set baud rate to 115200 bps
cfsetospeed(&tty, B115200);
cfsetispeed(&tty, B115200);
// ... (rest of serial port configuration)
// Save TTY settings
if (tcsetattr(serial_port, TCSANOW, &tty) != 0) {
fprintf(stderr, "Error %d from tcsetattr: %s\n", errno, strerror(errno));
return EXIT_FAILURE;
}
// Calculate the number of clock cycles for the desired exposure time
int clock_cycles = (int)(exposure_time_microseconds * sensor_clock_frequency_hz);
// Construct and send the command to set the exposure time
char command[256];
sprintf(command, "SENS:EXPPER %d\r\n", clock_cycles);
write(serial_port, command, strlen(command));
// ... (You would need to implement reading the response here)
// Send the command to save the SOC settings
write(serial_port, "SOC:SAVE\r\n", strlen("SOC:SAVE\r\n"));
// Close the serial port
close(serial_port);
return EXIT_SUCCESS;
}