Opening, closing & sending serial data on the BB-400

The serial port on the BB-400 port is /dev/ttySC0. This is basically the same as a COM port in windows. You can reference this in your application if you wish to put your application on the BB-400.
Below there is a python script which opens /dev/ttySC0, sends data out, receives it back, prints it out to the console then closes the port.
To run this program copy this code onto your BB-400 into a .py file then call your .py file from python e.g
python serial_test.py

#!/usr/env python -*- coding: utf-8 -*-
import threading
import time
import serial
ser = serial.Serial(
	port='/dev/ttySC0',
	baudrate = 115200,
	parity = serial.PARITY_NONE,
	stopbits = serial.STOPBITS_ONE,
	rtscts=True,
	timeout=None
)

def main():
	print 'Sending data Hello World'
	ser.write('Hello world');
	print ser.read();
main()

Below is the same program as above but written in C#. You will need mono on your BB-400 if you wish to run this program. You can install mono on your BB-400 by following the instructions here: https://www.mono-project.com/download/stable/#download-lin-raspbian
Once you have built your C# project, copy everything from your build onto your pi. You can then call your .exe file from mono e.g (you may need to do sudo for this)

sudo mono LinuxTest.exe

using System;
using System.IO.Ports;

namespace LinuxTest
{
    class Program
    {
        public static SerialPort port;
        static void Main(string[] args)
        {
            
            Console.WriteLine("Opening port");
            port = new SerialPort
            {
                PortName = "/dev/ttySC0",
                BaudRate = 115200,
                Parity = Parity.None,
                StopBits = StopBits.One,
                DataBits = 8,
                DtrEnable = true,
                
            };
            port.Open();
            Console.WriteLine("Sending data Hello World");
            port.Write("Hello World");
            port.ReadLine();
        }
    }
}

You can also use a terminal program to send/receive data with the serial port on the BB-400. Examples of these are minicom & screen.
Minicom:
- sudo apt-get install minicom
- minicom -s
This will take you into the set up of minicom. Here you can use the arrow keys and enter to get around the menus. Make sure your serial port is set to /dev/ttySC0. When you have set up all of your parameters then you can press exit and it will open your serial port.
Screen:
- sudo apt-get install screen
- screen /dev/ttySC0 115200
This opens the serial port at baud rate 115200.

This FAQ Applies to the following Brainboxes Product Ranges: