How to use RS232 Module with FEZ Medusa mini?

I’m trying to set up a communication from Medusa mini to a Gadgeteer Board via RS232 but I have problems to write to RS232 on the Medusa Mini (Arduino newbie).


 #include <Wire.h>
 #include <SPI.h>
 #include <Gadgeteering.h>
 #include <Mainboards/FEZMedusaMini.h>
 #include <Modules/RS232.h>

using namespace gadgeteering;
using namespace gadgeteering::mainboards;
using namespace gadgeteering::modules;

fez_medusa_mini board;
rs_232* my_Rs232;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  my_Rs232 = new rs_232(2);
  my_Rs232.write("Hello World");
}


I get the the errormessage:
Arduino: 1.6.5 (Windows 8.1), Platine: “FEZ Medusa”

Medusa_Mini_RS232_Test.ino: In function ‘void setup()’:
Medusa_Mini_RS232_Test:39: error: request for member ‘write’ in ‘my_Rs232’, which is of pointer type ‘gadgeteering::modules::rs_232*’ (maybe you meant to use ‘->’ ?)
request for member ‘write’ in ‘my_Rs232’, which is of pointer type ‘gadgeteering::modules::rs_232*’ (maybe you meant to use ‘->’ ?)

How can the string be sent?
Another question: how can the RS232 module be configurated different from the defaults:

Thanks in advance, RoSchmi

my_Rs232->write(“Hello World”);

C++ is not C#. :smiley:

Thanks, I’ll try when I’m back at my PC.

It turned out to be:


my_Rs232->serial.write("Hallo World"); 

Does anybody know how to configure the port different from the defaults?

@ RoSchmi - There is a configure method on the RS232 object. You can take a look in the header file of any module to see what is available.

@ John -
Thanks, I could use this method to change the Baudrate


my_Rs232->configure(19200);

but I didn’t find out what to take for the other parameters. Perhaps you can give an example.


 #pragma once
 #include "../Gadgeteering.h"
namespace gadgeteering
{
	namespace modules
	{
		class rs_232
		{
			const socket& sock;

			public:
				devices::serial serial;

				rs_232(unsigned char socket_number);

				void configure(serial_configuration config);
		};
	}
}


 #pragma once

 #include "Types.h"
 #include "Socket.h"
 #include "SoftwareI2C.h"

namespace gadgeteering
{
	namespace devices
	{

class serial
		{
			serial_channel channel;

			public:
				serial_configuration config;

				serial(const socket& sock, serial_configuration configuration);
				serial(serial_channel channel, serial_configuration configuration);
				~serial();

				void change_config(serial_configuration configuration);

				void write(const unsigned char* buffer, unsigned int length);
				void write(const char* buffer, unsigned int length = 0);
				unsigned int read(unsigned char* buffer, unsigned int length);
				unsigned int available();
		};
	}
}


 #pragma once

 #ifndef NULL
 #define NULL 0
 #endif

namespace gadgeteering
{
	typedef unsigned char io_mode;
	typedef unsigned char resistor_mode;

	typedef unsigned char spi_channel;
	typedef unsigned char i2c_channel;
	typedef unsigned char serial_channel;
	typedef unsigned char analog_channel;
	typedef unsigned char analog_out_channel;
	typedef unsigned char pwm_channel;

	typedef unsigned char error_type;

	typedef unsigned char cpu_pin;
	typedef unsigned char socket_pin_number;

	static const cpu_pin UNCONNECTED_PIN = 0xFF;
  /// @ brief Struct containing possible Serial (UART) channels
	struct serial_channels
	{
		static const serial_channel SERIAL_0 = 0;
		static const serial_channel SERIAL_1 = 1;
		static const serial_channel SERIAL_2 = 2;
		static const serial_channel SERIAL_3 = 3;
		static const serial_channel SERIAL_4 = 4;
		static const serial_channel SERIAL_5 = 5;
		static const serial_channel NONE = 0xFF;
	};

 /// @ brief Contains configuration for a Serial (UART) transaction
	struct serial_configuration
	{
		typedef unsigned char parity;
		typedef unsigned char stop_bit;

        /// The speed at which data will be sent (in bits-per-second)
		unsigned int baud_rate;

		/// The parity that will be used to detect erroneous communications
		parity data_parity;

		/// The number of bits that will be used to detect and signify the end of a character
		stop_bit stop_bits;

		/// The number of data bits in each character
		unsigned char data_bits;

        /// @ brief Contains definitions of the available parities
		struct parities
		{
            /// Arrange transmitted data with an even parity
			static const parity EVEN = 0;

            /// Arrange transmitted data with an odd parity
			static const parity ODD = 1;

            /// Arrange transmitted data with parity bit on the mark signal condition
			static const parity MARK = 2;

            /// Arrange transmitted data with parity bit on the space signal condition
			static const parity SPACE = 3;

            /// Arrange transmitted data with no parity
			static const parity NONE = 4;
		};

        /// @ brief Contains definitions of the available stop bit conditions
		struct stop_bits
		{
            /// Uses one bit to signify the end of a character. This is the default for most electronic devices.
			static const stop_bit ONE = 1;

			/// Uses one and a half bits to signify the end of a character.
			static const stop_bit ONE_POINT_FIVE = 2;

			/// Uses two bits to signify the end of a character.
			static const stop_bit TWO = 3;
		};

        /// @ brief The serial_configuration constructor
        /// @ param baud_rate The speed at which data will be sent (in bits-per-second)
        /// @ param parity The parity that will be used to detect erroneous communications (Default: none)
        /// @ param stop_bits The number of bits that will be used to detect and signify the end of a character
        /// @ param data_bits The number of data bits in each character
		serial_configuration(unsigned int baud_rate = 9600, parity parity = parities::NONE, stop_bit stop_bits = stop_bits::ONE, unsigned char data_bits = 8);
	};
	}
}

@ RoSchmi - It depends on how the other end is configured.

@ John - yes, I know. Sorry, if I was not clear enough.
What I do not know is, how to write the arguments without getting an error message of the compiler.

@ RoSchmi - You just need to construct the object and pass it to the method:


serial_configuration config(9600, serial_configuration::parities::NONE, serial_configuration::stop_bits::ONE, 8);

rs232->configure(config);

@ John - thanks a lot. It worked :clap: