Browse files

Reduced incoming data buffer size, added SIGINT cleanup

  • Loading branch information...
1 parent 990d03e commit c9f472ff2bc2b5689aaf966e39b1e4a5cc3c6537 @mstevenson committed Sep 25, 2011
Showing with 15 additions and 2 deletions.
  1. +15 −2 SimpleSerial/SimpleSerial.c
View
17 SimpleSerial/SimpleSerial.c
@@ -26,6 +26,7 @@ void SerialClose(void);
char* SerialRead(void);
void SerialWrite(char *text);
int SerialIsConnected(void);
+void cleanup(int signum);
int serialFileDescriptor = -1;
@@ -36,18 +37,30 @@ unsigned long latency = 3; // microseconds
// For testing
int main ()
{
+ signal(SIGINT, cleanup);
+
SerialOpen ("/dev/master", 9600);
// Main loop
while (1) {
sleep(0.3);
char *input = SerialRead();
printf("%s", input);
+ printf("\n");
+
+ SerialWrite("Serial written\n");
+
fflush(stdout);
- SerialWrite("Success\n");
}
}
+void cleanup (int signum)
+{
+ SerialClose();
+ printf("\nexiting\n");
+ exit(signum);
+}
+
void SerialOpen (const char *port, int baudRate)
{
@@ -116,7 +129,7 @@ void SerialClose ()
char * SerialRead()
{
- char buffer[127]; // buffer for holding incoming data
+ char buffer[100]; // buffer for holding incoming data
size_t bytes = 0;
bytes = read(serialFileDescriptor, buffer, sizeof(buffer));

0 comments on commit c9f472f

Please sign in to comment.