Examples - Modules - String Serial Protocol

New Version 1.1.4 Available! With support for unique ID's.

String Serial Protocol

String Serial Protocol is a simple protocol to communicate through the Serial Interface. It was designed to facilitate communication between two controller-boards (direct connected or through X-Bee) or between PC/MAC and controller-board.

All data is converted to Ascii-Code. This means if you want to send number values they need to be encoded before sending and decoded after receiving. If your sending just number values, this protocol might be the wrong solution for you, but keep in mind that this protocol is very reliable compared to most binary protocols!

Protocoll

byte 0command
byte 1 to xmessage
last byteCR, LF or CR LF or LF CR

Implementation for Wiring and Arduino

Open a new tab in your Wiring/Arduino - Sketch, name it modStringSerialProtocol and paste the code found below. Note: Encoding and decoding float values is not yet implemented.

Functions

  
  void Serial_Initialize (int boud)
    boud = Boud rate. use 9600

  void Serial_sendMessage (char cmd, char  message)
    Send a string message through serial.
    cmd = a char to seperate different commands. Don't use char with ascii 10 and 13
    message = string message to send

  void Serial_sendMessage (char cmd, int message)
    Send an int number through serial.
    cmd = a char to seperate different commands. Don't use char with ascii 10 and 13
    message = int number to send (-32768 to 32767)

  void Serial_sendMessage (char cmd, long message)
    Send an long number through serial.
    cmd = a char to seperate different commands. Don't use char with ascii 10 and 13
    message = long number to send (-2147483648 to 2147483647)

  void Serial_check () 
    Check if something is coming in. Must be called in LOOP.

  int Serial_parseInteger (char  val)
    Parse string value to int. (-32768 to 32767)

  long Serial_parseLong (char  val)
    Parse string value to long. (-2147483648 to 2147483647)

Source


Implementation for Processing

Open a new tab in your Processing - Sketch, name it modStringSerialProtocol and past the code found below. Note: Encoding and decoding float values is not yet implemented.

Functions

  SerialProtocolLibrary (PApplet parent, String comPort)
    Constructor
    parent = use this when calling
    comPort = COM Port to connect to
  SerialProtocolLibrary (PApplet parent, int iPort) {
    Constructor
    parent = use this when calling
    iPort = ID from COM Port to connect to (-1 means last comPort in list will be selected)
  void send (char cmd, String message)
    Send an long number through serial.
    cmd = a char to seperate different commands. Don't use char with ascii 10 and 13
    message = long number to send (-2147483648 to 2147483647)

  void send (char cmd, int message)
    Send an int number through serial.
    cmd = a char to seperate different commands. Don't use char with ascii 10 and 13
    message = int number to send (-32768 to 32767)

  int parseInteger (String val)
    Parse string value to int. (-2147483648 to 2147483647)

Source

This website has been archived and is no longer maintained.