I have a test case where I need to read text coming across a serial Bus (RS-232). This text is actually the text output by an embedded PC when it boots up. I then need to parse that text output for certain tokens. I am trying to develop a general approach to this problem. Here is my approach:
Configure COM port Open/create the file to write the text to Write bytes read from port to the file Any pointers here to help me along, or anything you think is missing? For the function ComToFile, I'm not sure what to use for the parameter "termination byte" because I don't know yet what the text looks like in its entirety. Is there a default value to feed into that function to not use that method?
NOTE: A UI is not required, this is for an automated test. Also, I'm debating whether I should write the boot text to a file and then parse the tokens from that file as I've done, Or is it best to just store it in a large buffer within the program and parse that buffer?
#include <formatio.h>
#include<stdio.h>
#include<string.h>
#include<rs232.h>
#define PORT_NUMBER 1
#define BUFFER_SIZE 10000
int main (void)
{
char buffer[BUFFER_SIZE];
int bytes = 100;
int fileHandle;
int status;
if (0 > (OpenComConfig(PORT_NUMBER, "COM1", 115200, 0, 7, 1, 5000, 512))) //Opens connection to COM port, closes program if error code returned
{
printf("Error: COM port could not be opened\n");
return -1;
}
fileHandle = OpenFile ("BootText.txt", VAL_READ_WRITE, VAL_TRUNCATE, VAL_ASCII);
status = SetComTime(PORT_NUMBER, 10);
bytes = ComToFile(PORT_NUMBER, fileHandle, 2000, 0x0D);
return 0;
}