Ubuntu Pastebin

Paste from Bram at Mon, 9 May 2016 11:07:01 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "lib/rs232.h"
#include <stdio.h>
#include <sys/file.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>


#define Port 22
#define Baudrate 19200
#define Mode {'8','N','2',0}


char OpenComPort (void);

int main()
{
  FILE * pFile;
  long lSize;
  char * buffer;
  if(!OpenComPort())
	{
		printf("Poort geopend");
	}
  
 while(1)
 {
  usleep(1000);
  pFile = fopen ( "var/write/RS232.rbx" , "ab+" );
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);
  buffer = (char*) malloc (sizeof(char)*lSize);
 
  fread (buffer,1,lSize,pFile);
  freopen(NULL,"w+", pFile);
  fclose(pFile);
  char serialdata[lSize + 2];
  serialdata[0] = 'a';
  serialdata[1] = 'b';
  int i = 0;
  for(i = 0; i < lSize; i++)
  {
	  serialdata[i + 2] = buffer[i];
  }
  if(lSize > 0)
  {
  
		RS232_SendBuf(Port,serialdata,sizeof(serialdata));
		
  }

  free (buffer);
 

 }
	
	return 0;
}

char OpenComPort (void)
{
	char mode[] = Mode;
	return RS232_OpenComport(Port,Baudrate,mode);
}
Download as text