Tech Note 16 Communications

March 25, 2009

© NSB Corporation. All rights reserved.

This Tech Note gives more information on communications than is contained the Handbook. It concerns itself with Serial, IR, TCP/IP and Bluetooth communications.

If you have notes or tips to add, please send them to support@nsbasic.com.

Contents

    1. Serial Communications - RS-232
    2. IR Communications
    3. TCP/IP
    4. Bluetooth

1. Serial Communications - RS-232

Serial communication over an RS-232 connection is often the easiest way to talk to other devices. Until recently, it was the standard used by almost all devices. You'll need to check whether the device you are using supports serial communication.

The best way to test serial communications is hook your device up to the serial port on your PC. Run HyperTerminal on the PC and set it to 9600 baud, local connection. On your device, run the SerTester sample. You'll be able to send and receive data in both directions.

Have a look at the SerialOpen function in your Handbook or in the Help to get the proper port numbers for opening serial communications. In most cases, you will use 0 as the port number.

Notes and Warnings

a. Using Serial Comms on a device with USB port

To do serial communications with a device that has a USB port, you'll need a usb to serial cable. If you have the right cable, you should be able to open and use the serial port normally.

b. SerialReceiveWithEvents

This useful feature allows an NS Basic program to respond to an incoming message with an event, rather than having to poll the serial port continuously to see if data comes through. However, it does not fire on all devices. It is often better to use SerialReceive with a timer. See SysInfoSet(Timer, x) in the Language Reference for more information.


2. IR Communications There are several different protocols that are used for IR communications. They are:

More on IRComm (IRDA)

To open an IR port for IRComm communications,

   res=SerialOpen(nsbIRCOMM,9600)

IRComm is easy to use. It's not as fast as SIR, but much more reliable and runs on all devices. Baud rate (9600) does not seem to matter: the protocol works out the best rate.

For sample code, simply take the BlueTooth RFCOMM sample and change the port number.


3. TCP/IP

TCP/IP is the communications protocol used by the internet. All Symbian devices have some capability to use TCP/IP. It's a very flexible protocol, but is more trouble to configure.

First, a TCP/IP connection must be established between the device and the system you want to communicate with. From a hardware perspective, this requires a WiFi card (or perhaps a device with built in WiFi) or a USB or serial cable. Next, you need to configure the Network settings in Prefs. The exact settings will depend on the physical connection, then tap Connect.

NS Basic communicates with TCP/IP using the TcpIpLib. This is described in Tech Note 18. Once the connection is established, most standard internet protocols can be used. NS Basic includes the sample TcpClient and TcpServer samples which exchanges messages with a Visual Basic program on the desktop.


4. Bluetooth

To open Bluetooth virtual port for serial communications,

   res=SerialOpen(nsbRFCOMM,9600)

Bluetooth is also easy to use. Baud rate (9600) does not seem to matter. Device discovery is done when the port is opened by prompts to the operator.

For sample code, see the BlueTooth RFCOMM sample. You can test by using HyperTerminal on the desktop and setting up a serial connection. The com port for Hyperterminal will depend on your system. Baud rate and other connection settings can be ignored: the protocal negotiates its own settings.