#include <stdio.h>
#include "serialib.h"
#if defined (_WIN32) || defined( _WIN64)
#define DEVICE_PORT "COM1" // COM1 for windows
#endif
#ifdef __linux__
#define DEVICE_PORT "/dev/ttyS0" // ttyS0 for linux
#endif
int main()
{
serialib LS;
int Ret;
char Buffer[128];
Ret=LS.Open(DEVICE_PORT,115200);
if (Ret!=1) {
printf ("Error while opening port. Permission problem ?\n");
return Ret;
}
printf ("Serial port opened successfully !\n");
Ret=LS.WriteString("AT\n");
if (Ret!=1) {
printf ("Error while writing data\n");
return Ret;
}
printf ("Write operation is successful \n");
Ret=LS.ReadString(Buffer,'\n',128,5000);
if (Ret>0)
printf ("String read from serial port : %s",Buffer);
else
printf ("TimeOut reached. No data received !\n");
LS.Close();
return 0;
}