Serial Port - Receive Packet
Hi guys,
I have a program that currently opens a serial com port on WinXP machine and sends data in a packet to an LCD screen. But some of the commands for the LCD screen require the program to receive packets from the LCD to WinXP.
Here is my send_packet() code. It store relevant data such as command, data_length, data, crc. The packet is called outgoing_response, as defined by the LCD screen manufacturers
Code:
void send_packet(COMMAND_PACKET *packet)
{
ubyte i;
unsigned char buffer[20];
int index;
index = 0;
buffer[index++] = packet->command;
buffer[index++] = packet->data_length;
for(i = 0 ; i < packet->data_length ; i++)
buffer[index++] = packet->data[i];
packet->CRC.as_word =
get_crc((ubyte *)&outgoing_response,outgoing_response.data_length+2,0xFFFF);
buffer[index++] = packet->CRC.as_bytes[0];
buffer[index++] = packet->CRC.as_bytes[1];
DWORD bytes_written;
bytes_written = 0;
if(handle)
if(TRUE != WriteFile(handle,
buffer,
index,
&bytes_written,
NULL))
printf("WriteFile() failed!\n");
}
With this information can anyone help me to write afunction to receive packets from the LCD screen. the receive packet name is incoming_command as defined by the LCD manufacturer.
Thanks