/* Flush the input and output */
tcflush ( fd, TCIOFLUSH );
/* Set the new options for the port */
tcsetattr( fd, TCSANOW, &newtio );
notRsRead = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(notRsRead, SIGNAL(activated(int)), this, SLOT(Receive_Event()));
ui->Btn_Open->setEnabled(1);
/* Ring buffer create */
m_abyBuffer.Create(BUFF_MAX);
Open_uinput_port();
}
}
2.2.
Write packet to serial port
The method of writing packet to serial port is as follows. Transmit serial packet through the write function.
Example )
/*
* Function name : on_Btn_LED1_clicked
* Description : This function is control Right LED 1.
*/
void Serial_Daemon::on_Btn_LED1_clicked()
{
char LED_Packet[10] = {0, };
unsigned int crc_buf;
unsigned long dwBytes = 0;
static char i = 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[3] = RIGHT_LED1; // Data1 (SUB ADDRESS)
if ( i == 3 )
LED_Packet[4] = LED_OFF; // Data2 (off : 0x30, blue : 0x31, red : 0x32, all :
0x33)
else
LED_Packet[4] = LE i;
LED_Packet[5] = DATA_RESERVED; // Data3 (Reserved : 0x20)
crc_buf = crc16_append(LED_Packet,6);
LED_Packet[6] = (char)(crc_buf>>8)&0xff;
LED_Packet[7] = (char)crc_buf&0xff;
LED_Packet[8] = ETX; // ETX
LED_Packet[9] = '\0';
dwBytes = strlen(LED_Packet);
write( fd, LED_Packet, dwBytes );
usleep(1000);
switch (i) {
case 0 :
ui->Btn_LED1->setText("BLUE");
i++;
break;
case 1 :
ui->Btn_LED1->setText("RED");
i++;