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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
ENTTEC OPEN DMX USB
lsusb | grep FT232
Bus 004 Device 005: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
On peut communiquer avec ce périphérique Série via la libftdi
i libftdi1 - Library to control and program the FTDI USB controller
Dans l'ordre :
#include <time.h>
static const int VID = 0x0403; //! FTDI Vendor ID
static const int PID = 0x6001; //! FTDI Product ID
// One "official" DMX frame can take (1s/44Hz) = 22727272ns
#define DMX_FRAMETIME 22727272
#define DMX_BREAK 110000
#define DMX_MAB 16000
#define DMX_CHANNELS 512
inline void ts_diffadd(struct timespec *res, struct timespec *a, struct timespec *b, struct timespec *c) {
time_t rem;
res.tv_nsec=a.tv_nsec-b.tv_nsec+c.tv_nsec;
rem=res.tv_nsec/1e9
res.tv_nsec=res.tv_nsec%1e9;
res.tv_sec=a.tv_sec-b.tv_sec+c.tv_sec+rem;
if (res.tv_nsec<0 && res.tv_sec>0) res.tv_sec--; res.tv_nsec+=1e9;
if (res.tv_nsec>0 && res.tv_sec<0) res.tv_nsec-=1e9; res.tv_sec++;
}
ftdi_usb_find_all(&ftdi, &list, QLCFTDI::VID, QLCFTDI::PID);
ftdi_usb_open_desc(&m_handle, QLCFTDI::VID, QLCFTDI::PID, name().toAscii(), serial().toAscii())
ftdi_usb_reset(&m_handle)
ftdi_set_baudrate(&m_handle, 250000)
ftdi_set_line_property(&m_handle, BITS_8, STOP_BIT_2, NONE)
ftdi_setflowctrl(&m_handle, SIO_DISABLE_FLOW_CTRL)
ftdi_usb_purge_buffers(&m_handle)
ftdi_setrts(&m_handle, 0)
frame_time.tv_sec=0;
frame_time.tv_nsec=DMX_FRAMETIME;
// Attente initiale (juste après ouverture periph)
to_sleep.tv_sec=0;
to_sleep.tv_nsec=1e6;
nanosleep(to_sleep,NULL);
clock_gettime(CLOCK_MONOTONIC, now);
ts_diffadd(to_sleep,frame_time,now,trame_begin);
nanosleep(to_sleep);
clock_gettime(CLOCK_MONOTONIC, trame_begin);
ftdi_set_line_property2(&m_handle, BITS_8, STOP_BIT_2, NONE, BREAK_ON)
usleep(DMX_BREAK);
ftdi_set_line_property2(&m_handle, BITS_8, STOP_BIT_2, NONE, BREAK_OFF)
usleep(DMX_MAB);
m_ftdi->write(m_universe)
ftdi_write_data(&m_handle, m_universe, sizeof(m_universe))
ftdi_usb_close(&m_handle)
rq : si résultat <0, affichage erreur avec ftdi_get_error_string(&m_handle)
|