Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Copyright (C) 2011 Associated Universities, Inc. Washington DC, USA.
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Correspondence concerning GBT software should be addressed as follows:
# GBT Operations
# National Radio Astronomy Observatory
Expand All @@ -24,7 +24,7 @@ CC = g++
AR = ar
DOXY = doxygen
CFLAGS = -c -Wall -fPIC -DLINUX
LDFLAGS =
LDFLAGS =
SOURCES = ValonSynth.cc Serial.cc
OBJECTS = $(SOURCES:.cc=.o)
PLATFORM = LINUX
Expand Down Expand Up @@ -52,4 +52,4 @@ clean:

.PHONY: clobber
clobber: clean
rm -rf $(STARGET) $(DTARGET)
rm -rf $(STARGET) $(DTARGET)
52 changes: 52 additions & 0 deletions README-Python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Valon Synth

## Installation

In order to use the Python code, it is necessary to build the C++
library first:

$ make

This should create a `libValonSynth.so` shared object.

The Python software can now be installed for development use. As a
first step, create a Python virtual environment.

$ virtualenv venv

Optionally, activate it; the steps below assumes that the virtual
environment has not been activated.

Use the virtual environment to setup the package:

$ ./venv/bin/pip install -r requirements.txt

To be able to use the package, we also need to be able to import it.
Normally the source directory name matches the package name, but
unfortunately in this instance it doesn't. We create a symbolic link to
fudge it.

$ ln -s src valon_synth

## Communication checks

We provide a example script that tests basic communications. It
requires knowledge of the (USB-connected) serial port the Valon is
connected to. In Linux, plug in both USB plugs on the Valon, and do

$ dmesg

The last lines in the log should be similar to the following:

usb 5-1: FTDI USB Serial Device converter now attached to ttyUSB0

This indicates the port we are interested in is `/dev/ttyUSB0`, which
coincidentally is the default port in the communications test example
script.

To run the communications check, simply do:

$ ./venv/bin/python example/commtest.py --port /dev/ttyUSB0

Feel free to replace `/dev/ttyUSB0` in the command shown above with your
locally identified port.
40 changes: 20 additions & 20 deletions Serial.cc
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//# Copyright (C) 2011 Associated Universities, Inc. Washington DC, USA.
//#
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//#
//# This program is distributed in the hope that it will be useful, but
//# WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//# General Public License for more details.
//#
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//#
//#
//# Correspondence concerning GBT software should be addressed as follows:
//# GBT Operations
//# National Radio Astronomy Observatory
Expand Down Expand Up @@ -121,7 +121,7 @@ int Serial::serial_write(const unsigned char *output_buffer,
}


int Serial::serial_read(unsigned char *input_buffer, const int &number_of_bytes,
int Serial::serial_read(unsigned char *input_buffer, const int &number_of_bytes,
const int timeo_us)
{
int bytes_received = 0;
Expand Down Expand Up @@ -156,19 +156,19 @@ int Serial::serial_read(unsigned char *input_buffer, const int &number_of_bytes,
&input_buffer[bytes_received],
#endif
(number_of_bytes - bytes_received));
// was an error condition present?

// was an error condition present?
if (read_bytes < 0)
{
// Flush input buffer.
#if defined (SOLARIS) || defined (LINUX)
ioctl(the_serial_port, TCFLSH, 0);
ioctl(the_serial_port, TCIFLUSH, 0);
#else
ioctl(the_serial_port, FIORFLUSH, 0);
#endif
return(read_bytes);
}

bytes_received += read_bytes;

if (the_input_mode == Serial::canonical && bytes_received > 0)
Expand Down Expand Up @@ -207,7 +207,7 @@ int Serial::open_serial_port(const char *port_name)
{
// Flush serial port.
#if defined (SOLARIS) || defined (LINUX)
ioctl(the_serial_port, TCFLSH, 0);
ioctl(the_serial_port, TCIOFLUSH, 0);
#endif
#if defined(VXWORKS)
ioctl(the_serial_port, FIOFLUSH, 0);
Expand All @@ -234,11 +234,11 @@ int Serial::update_parity(const Serial::parity_choices &parity)
switch (parity)
{
case Serial::odd:
the_termios.c_cflag |= (PARODD | PARENB);
the_termios.c_cflag |= (PARODD | PARENB);
break;
case Serial::even:
the_termios.c_cflag |= PARENB;
the_termios.c_cflag &= ~(PARODD);
the_termios.c_cflag |= PARENB;
the_termios.c_cflag &= ~(PARODD);
break;
case Serial::none:
the_termios.c_cflag &= ~PARENB;
Expand Down Expand Up @@ -288,7 +288,7 @@ int Serial::update_baud_rate(const int &baud_rate)
cerr << "Cannot set baud rate" << endl;
return (-1);
}

speed_t speed;

switch (baud_rate)
Expand Down Expand Up @@ -602,7 +602,7 @@ int Serial::set_raw_input_mode()
// as BS-SP-BS.
the_termios.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOE);
the_termios.c_iflag &= ~(INPCK | ISTRIP);

if (tcsetattr(the_serial_port, TCSAFLUSH, &the_termios) != 0)
{
// TBF: Error message
Expand Down Expand Up @@ -646,7 +646,7 @@ int Serial::set_canonical_input_mode()
// Enable canonical mode, enable echoing of input characters, enable
// echoing of erase character as BS-SP-BS.
the_termios.c_lflag |= (ICANON | ECHO | ECHOE);

if (tcsetattr(the_serial_port, TCSAFLUSH, &the_termios) != 0)
{
// TBF: Error message
Expand Down Expand Up @@ -691,19 +691,19 @@ int Serial::set_other_flags()
the_termios.c_lflag &= ~IEXTEN;

// input flags:-
// Send a SIGINT when a break condition is detected, map CR to NL,
// Send a SIGINT when a break condition is detected, map CR to NL,
the_termios.c_iflag &= ~(BRKINT | ICRNL);

// control flags:-
// Setting CLOCAL and CREAD ensures that the program will not become
// the owner of the port and the serial interface driver will read
// incoming data bytes.
the_termios.c_cflag |= (CLOCAL | CREAD);

// output flags:-
// Turn off the output processing
the_termios.c_oflag &= ~(OPOST);

// Set up 0 character minimum with no timeout.
the_termios.c_cc[VMIN] = 0;
the_termios.c_cc[VTIME] = 0;
Expand Down
28 changes: 14 additions & 14 deletions Serial.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//# Copyright (C) 2011 Associated Universities, Inc. Washington DC, USA.
//#
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//#
//# This program is distributed in the hope that it will be useful, but
//# WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//# General Public License for more details.
//#
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//#
//#
//# Correspondence concerning GBT software should be addressed as follows:
//# GBT Operations
//# National Radio Astronomy Observatory
Expand All @@ -26,13 +26,13 @@


// <summary>
// This class provides a vehicle for serial communication on the vxWorks,
// This class provides a vehicle for serial communication on the vxWorks,
// Linux, and Solaris platforms.
// </summary>

// <prerequisite>
// <li> The configuration of the serial port that you wish to use (i.e.
// baud rate, parity, port name, etc).
// <li> The configuration of the serial port that you wish to use (i.e.
// baud rate, parity, port name, etc).
// </li>
// </prerequisite>

Expand All @@ -41,7 +41,7 @@
// </etymology>

// <synopsis>
// This class provides a portable way to use the serial port for
// This class provides a portable way to use the serial port for
// program communication. The two main member functions that enable this
// communication are read and write. Other member functions are provided
// to configure the serial port as needed. The default serial port
Expand Down Expand Up @@ -69,13 +69,13 @@
//
// The valid choices for input mode are raw and canonical. These are
// defined via the enumeration input_choices below. Raw mode processes
// the characters as they are typed. Canonical mode handles the
// the characters as they are typed. Canonical mode handles the
// characters on a line by line basis - i.e. it waits for the '/n'
// character before reading/writing.
// </synopsis>

// <motivation>
// To contain all serial communication needs across multiple platforms
// To contain all serial communication needs across multiple platforms
// within a single class.
// </motivation>

Expand Down Expand Up @@ -134,7 +134,7 @@ class Serial
// -1 on failure.
int set_stop_bits(const int &stop_bits);

// set_hardware_flow_control accepts either 0 = No hardware flow
// set_hardware_flow_control accepts either 0 = No hardware flow
// control or 1 = Hardware flow control. If the input parameter is
// neither 0 nor 1, hardware flow control is disabled. Returns 0 on
// success, -1 on failure.
Expand Down Expand Up @@ -177,7 +177,7 @@ class Serial
input_choices the_input_mode;
// </group>

// These member functions set up parameters for the serial port over
// These member functions set up parameters for the serial port over
// which the user of this class has no control.
// <group>
int open_serial_port(const char *port_name);
Expand All @@ -193,7 +193,7 @@ class Serial
virtual int serial_write(const unsigned char *output_buffer,
const int &number_of_bytes);
virtual int serial_read(unsigned char *input_buffer,
const int &number_of_bytes,
const int &number_of_bytes,
const int timeout_usec = 200000);
virtual int update_parity(const parity_choices &parity);
virtual int update_baud_rate(const int &baud_rate);
Expand All @@ -215,7 +215,7 @@ inline int Serial::write(const unsigned char *output_buffer,
}


inline int Serial::read(unsigned char *input_buffer, const int &number_of_bytes,
inline int Serial::read(unsigned char *input_buffer, const int &number_of_bytes,
const int tmo_usec)
{
return (serial_read(input_buffer, number_of_bytes, tmo_usec));
Expand Down
8 changes: 4 additions & 4 deletions ValonSynth.cc
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//# Copyright (C) 2011 Associated Universities, Inc. Washington DC, USA.
//#
//#
//# This program is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//#
//# This program is distributed in the hope that it will be useful, but
//# WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//# General Public License for more details.
//#
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//#
//#
//# Correspondence concerning GBT software should be addressed as follows:
//# GBT Operations
//# National Radio Astronomy Observatory
Expand Down
Loading