Sensorian  1.0
C API Reference Guide Library
main.c
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include "Serial.h"
31 
32 int main(int argc, char* argv[])
33 {
34  unsigned int ser = SerialOpen(115200); //Open serial port with a 115200 baud rate
35  int a = 0;
36  SerialFlush(ser); //Clear TX and RX buffer, can be called periodically
37 
38  SerialPuts(ser,"Serial communication using the Sensorian Shield.\r\n");
39  SerialPrintf(ser,"You are using device number %d.\r\n",ser);
40  SerialFlush(ser);
41 
42  while(1)
43  { if(SerialDataAvail(ser))
44  {
45  a = SerialGetchar(ser);
46  SerialPrintf(ser,"You sent %c.\r\n",(char)(a));
47  if(a == 'b') break;
48  }
49  }
50  SerialPrintf(ser,"Closing serial port ...");
51  SerialClose(ser); //Close serial port
52 
53  return 0;
54 }
55 
void SerialPuts(int fd, char *s)
Send a string to the serial port.
Definition: Serial.c:157
int SerialOpen(int baud)
Open and initialise the serial port with a specific baud rate.
Definition: Serial.c:51
void SerialClose(int fd)
Closes the serial port characterized by device number fd.
Definition: Serial.c:135
void SerialPrintf(int fd, char const *message,...)
Printf over Serial Port.
Definition: Serial.c:168
int SerialDataAvail(int fd)
Return the number of bytes of data avalable to be read from the serial port.
Definition: Serial.c:185
int SerialGetchar(int fd)
Get a single character from the serial device. Note: Zero is a valid character and this function will...
Definition: Serial.c:201
Serial port driver header.
int main(int argc, char **argv)
Definition: main.c:34
void SerialFlush(int fd)
Flush the serial buffers (both tx & rx)
Definition: Serial.c:125