Sensorian
1.0
C API Reference Guide Library
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
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
SerialPuts
void SerialPuts(int fd, char *s)
Send a string to the serial port.
Definition:
Serial.c:157
SerialOpen
int SerialOpen(int baud)
Open and initialise the serial port with a specific baud rate.
Definition:
Serial.c:51
SerialClose
void SerialClose(int fd)
Closes the serial port characterized by device number fd.
Definition:
Serial.c:135
SerialPrintf
void SerialPrintf(int fd, char const *message,...)
Printf over Serial Port.
Definition:
Serial.c:168
SerialDataAvail
int SerialDataAvail(int fd)
Return the number of bytes of data avalable to be read from the serial port.
Definition:
Serial.c:185
SerialGetchar
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.h
Serial port driver header.
main
int main(int argc, char **argv)
Definition:
main.c:34
SerialFlush
void SerialFlush(int fd)
Flush the serial buffers (both tx & rx)
Definition:
Serial.c:125
FT230
Example2
main.c
Generated on Sun Jul 12 2015 20:25:27 for Sensorian by
1.8.9.1