{
char LED_Packet[10] = {0, };
unsigned int crc_buf;
unsigned long dwBytes = 0;
LED_Packet[0] = STX; // STX
LED_Packet[1] = MOD_SET; // MOD (get : 0x10, set : 0x11)
LED_Packet[2] = SEL_LED; // SEL (LED : 0x3A)
LED_Packet[5] = DATA_RESERVED; // Data3 (Reserved : 0x20)
LED_Packet[8] = ETX; // ETX
LED_Packet[9] = '\0';
switch(sel) {
case RIGHT_LED1:
LED_Packet[3] = RIGHT_LED1;
break;
case RIGHT_LED2:
LED_Packet[3] = RIGHT_LED2;
break;
case RIGHT_LED3:
LED_Packet[3] = RIGHT_LED3;
break;
case LED_ALL:
LED_Packet[3] = LED_ALL;
}
if (data & 0x1) { // Blue color
LED_Packet[4] = LED_BLUE;
} else if (data & 0x2) { // Red color
LED_Packet[4] = LED_RED;
} else if (data & 0x4) { // All color
LED_Packet[4] = LED_ALL_ON;
} else { // LED Off
LED_Packet[4] = LED_OFF;
}
crc_buf = crc16_append(LED_Packet,6);
LED_Packet[6] = (char)(crc_buf>>8)&0xff;
LED_Packet[7] = (char)crc_buf&0xff;
dwBytes = strlen(LED_Packet);
write( fd, LED_Packet, dwBytes );
usleep(1000);
}
4.2.
Examples using Buzzer
Control the Buzzer of DTP10-L by using serial daemon program provided by Daincube.
-
Serial COM port open
-
Packet buffer create.
-
CRC create and fill in the packet buffer
-
Transmit serial packet
-
Serial COM port close
You can control Buzzer of DTP10-L by transmit serial packet as below.
STX
MOD
SEL
DATA1
DATA2
DATA3
CRC_H
CRC_L
ETX
0x02
0x11
0x3B
0x31
0x20
0x20
0xXX
0xXX
0x03