summaryrefslogtreecommitdiff
path: root/macros/Hardware/RasberryPi/Serial
diff options
context:
space:
mode:
authorJorawar Singh2017-07-16 22:17:43 +0530
committerJorawar Singh2017-07-16 22:36:51 +0530
commitd9d92203ea349d5eb44c0edc5565d827322caabe (patch)
tree9bf874443e6e5a8ccd8fba3f5918297d95a194e8 /macros/Hardware/RasberryPi/Serial
parentce5c0f9d407d533364e9e7adc81e4d338e031383 (diff)
downloadScilab2C_fossee_old-d9d92203ea349d5eb44c0edc5565d827322caabe.tar.gz
Scilab2C_fossee_old-d9d92203ea349d5eb44c0edc5565d827322caabe.tar.bz2
Scilab2C_fossee_old-d9d92203ea349d5eb44c0edc5565d827322caabe.zip
Toolbox merge, RPI demos and structured demos
Diffstat (limited to 'macros/Hardware/RasberryPi/Serial')
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/RPI_serialClose.sci40
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/RPI_serialDataAvail.sci40
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/RPI_serialFlush.sci40
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/RPI_serialGetchar.sci40
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/RPI_serialOpen.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/RPI_serialPrintf.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/RPI_serialPutchar.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/RPI_serialPuts.sci41
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/buildmacros.sce14
-rwxr-xr-xmacros/Hardware/RasberryPi/Serial/names8
10 files changed, 346 insertions, 0 deletions
diff --git a/macros/Hardware/RasberryPi/Serial/RPI_serialClose.sci b/macros/Hardware/RasberryPi/Serial/RPI_serialClose.sci
new file mode 100755
index 0000000..6f54b65
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/RPI_serialClose.sci
@@ -0,0 +1,40 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function out=RPI_serialClose(fd)
+// Function to close and open serial device
+//
+// Calling Sequence
+// RPI_serialClose(fd)
+//
+// Parameters
+// fd: file-descriptor obtained from RPI_serialOpen function
+//
+// Description
+// This function closes the device identified by the file descriptor given.
+//
+// Examples
+// RPI_serialClose(13)
+// See also
+// RPI_serialOpen, RPI_serialFlush, RPI_serialPutchar, RPI_serialPuts, RPI_serialPrintf, RPI_serialDataAvail, RPI_serialGetchar
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="sCl#1#"+string(fd)+"#";
+ if getos()=="Linux" then
+ out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos()=="Windows" then
+ [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/Serial/RPI_serialDataAvail.sci b/macros/Hardware/RasberryPi/Serial/RPI_serialDataAvail.sci
new file mode 100755
index 0000000..9421e5b
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/RPI_serialDataAvail.sci
@@ -0,0 +1,40 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function out=RPI_serialDataAvail(fd)
+// Function to get number of readable character from the serial device
+//
+// Calling Sequence
+// RPI_serialDataAvail(fd)
+//
+// Parameters
+// fd: file-descriptor obtained from RPI_serialOpen function
+//
+// Description
+// Returns the number of characters available for reading, or -1 for any error condition, in which case error number will be set appropriately.
+//
+// Examples
+// RPI_serialDataAvail(13)
+// See also
+// RPI_serialOpen, RPI_serialClose, RPI_serialFlush, RPI_serialPutchar, RPI_serialPuts, RPI_serialPrintf, RPI_serialGetchar
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="sDA#1#"+string(fd)+"#";
+ if getos()=="Linux" then
+ out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos()=="Windows" then
+ [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/Serial/RPI_serialFlush.sci b/macros/Hardware/RasberryPi/Serial/RPI_serialFlush.sci
new file mode 100755
index 0000000..845f70b
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/RPI_serialFlush.sci
@@ -0,0 +1,40 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function out=RPI_serialFlush(fd)
+// Function to discard all data to/from the serial device
+//
+// Calling Sequence
+// RPI_serialFlush(fd)
+//
+// Parameters
+// fd: file-descriptor obtained from RPI_serialOpen function
+//
+// Description
+// This function discards all data received, or waiting to be send down the given device.
+//
+// Examples
+// RPI_serialFlush(13)
+// See also
+// RPI_serialOpen, RPI_serialClose, RPI_serialPutchar, RPI_serialPuts, RPI_serialPrintf, RPI_serialDataAvail, RPI_serialGetchar
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="sFl#1#"+string(fd)+"#";
+ if getos()=="Linux" then
+ out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos()=="Windows" then
+ [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/Serial/RPI_serialGetchar.sci b/macros/Hardware/RasberryPi/Serial/RPI_serialGetchar.sci
new file mode 100755
index 0000000..327fe35
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/RPI_serialGetchar.sci
@@ -0,0 +1,40 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function out=RPI_serialGetchar(fd)
+// Function to get next character from serial device
+//
+// Calling Sequence
+// RPI_serialGetchar(fd)
+//
+// Parameters
+// fd: file-descriptor obtained from RPI_serialOpen function
+//
+// Description
+// This function returns the next character available on the serial device. This call will block for up to 10 seconds if no data is available (when it will return -1).
+//
+// Examples
+// RPI_serialGetchar(13)
+// See also
+// RPI_serialOpen, RPI_serialClose, RPI_serialFlush, RPI_serialPutchar, RPI_serialPuts, RPI_serialPrintf, RPI_serialDataAvail
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="sGc#1#"+string(fd)+"#";
+ if getos()=="Linux" then
+ out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos()=="Windows" then
+ [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/Serial/RPI_serialOpen.sci b/macros/Hardware/RasberryPi/Serial/RPI_serialOpen.sci
new file mode 100755
index 0000000..684a6f2
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/RPI_serialOpen.sci
@@ -0,0 +1,41 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function out=RPI_serialOpen(device,baud)
+// Function to initialize a serial device
+//
+// Calling Sequence
+// RPI_serialOpen(device,baud)
+//
+// Parameters
+// device: device to connect to
+// baud : the baud rate for communication
+//
+// Description
+// This function opens and initialises the serial device and sets the baud rate. It sets the port into “raw” mode (character at a time and no translations), and sets the read timeout to 10 seconds. The return value is the file descriptor or -1 for any error, in which case errno will be set as appropriate.
+//
+// Examples
+// RPI_serialOpen("/dev/ttyAMA0", 9600)
+// See also
+// RPI_serialClose, RPI_serialFlush, RPI_serialPutchar, RPI_serialPuts, RPI_serialPrintf, RPI_serialDataAvail, RPI_serialGetchar
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="sOp#2#"+string(device)+"#"+string(baud)+"#";
+ if getos()=="Linux" then
+ out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos()=="Windows" then
+ [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/Serial/RPI_serialPrintf.sci b/macros/Hardware/RasberryPi/Serial/RPI_serialPrintf.sci
new file mode 100755
index 0000000..668a9ff
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/RPI_serialPrintf.sci
@@ -0,0 +1,41 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function out=RPI_serialPrintf(fd,msg)
+// Function to print to serial device
+//
+// Calling Sequence
+// RPI_serialPrintf(fd,msg)
+//
+// Parameters
+// fd : file-descriptor obtained from RPI_serialOpen function
+// msg: message to print
+//
+// Description
+// This function emulates the system printf function to the serial device.
+//
+// Examples
+// RPI_serialPrintf(13,'White Collar rocks')
+// See also
+// RPI_serialOpen, RPI_serialClose, RPI_serialFlush, RPI_serialPutchar, RPI_serialPuts, RPI_serialDataAvail, RPI_serialGetchar
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="sPf#2#"+string(fd)+"#"+string(msg)+"#";
+ if getos()=="Linux" then
+ out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos()=="Windows" then
+ [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/Serial/RPI_serialPutchar.sci b/macros/Hardware/RasberryPi/Serial/RPI_serialPutchar.sci
new file mode 100755
index 0000000..ceea556
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/RPI_serialPutchar.sci
@@ -0,0 +1,41 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function out=RPI_serialPutchar(fd,character)
+// Function to send a single byte to the serial device
+//
+// Calling Sequence
+// RPI_serialPutchar(fd,character)
+//
+// Parameters
+// fd : file-descriptor obtained from RPI_serialOpen function
+// character: character to send to the serial device
+//
+// Description
+// This function sends the single byte to the serial device identified by the given file descriptor.
+//
+// Examples
+// RPI_serialPutchar(113,'s')
+// See also
+// RPI_serialOpen, RPI_serialClose, RPI_serialFlush, RPI_serialPuts, RPI_serialPrintf, RPI_serialDataAvail, RPI_serialGetchar
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="sPc#2#"+string(fd)+"#"+string(character)+"#";
+ if getos()=="Linux" then
+ out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos()=="Windows" then
+ [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/Serial/RPI_serialPuts.sci b/macros/Hardware/RasberryPi/Serial/RPI_serialPuts.sci
new file mode 100755
index 0000000..ecbbe05
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/RPI_serialPuts.sci
@@ -0,0 +1,41 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+function out=RPI_serialPuts(fd,s)
+// Function to send a null-terminalted string
+//
+// Calling Sequence
+// RPI_serialPuts(fd,s)
+//
+// Parameters
+// fd: file-descriptor obtained from RPI_serialOpen function
+// s : string to send
+//
+// Description
+// Sends the nul-terminated string to the serial device identified by the given file descriptor.
+//
+// Examples
+// RPI_serialPuts(13,'Believe it, Dattebayo!\0')
+// See also
+// RPI_serialOpen, RPI_serialClose, RPI_serialFlush, RPI_serialPutchar, RPI_serialPrintf, RPI_serialDataAvail, RPI_serialGetchar
+//
+// Authors
+// Jorawar Singh
+//
+// Bibliography
+// http://wiringpi.com/reference/
+
+ commande="sPs#2#"+string(fd)+"#"+string(s)+"#";
+ if getos()=="Linux" then
+ out=unix_g("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ elseif getos()=="Windows" then
+ [out,RPI_winR]=dos("python -c ""import socket;s=socket.socket();s.connect((''"+RPI_piAdress+"'',9077));s.send(''"+commande+"'');print(s.recv(1024));s.close()""");
+ end
+endfunction
diff --git a/macros/Hardware/RasberryPi/Serial/buildmacros.sce b/macros/Hardware/RasberryPi/Serial/buildmacros.sce
new file mode 100755
index 0000000..7d533f7
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/buildmacros.sce
@@ -0,0 +1,14 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author: Jorawar Singh
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+tbx_build_macros(TOOLBOX_NAME, get_absolute_file_path('buildmacros.sce'));
+
+clear tbx_build_macros;
diff --git a/macros/Hardware/RasberryPi/Serial/names b/macros/Hardware/RasberryPi/Serial/names
new file mode 100755
index 0000000..a652727
--- /dev/null
+++ b/macros/Hardware/RasberryPi/Serial/names
@@ -0,0 +1,8 @@
+RPI_serialClose
+RPI_serialDataAvail
+RPI_serialFlush
+RPI_serialGetchar
+RPI_serialOpen
+RPI_serialPrintf
+RPI_serialPutchar
+RPI_serialPuts