Monday, May 9, 2011

Serial Comm RS232 port Interface (Gambas2)


Introductions:

Serial communication is very important tools required in programming, its serial functions must be learned by a programmer too. In some electronic interfacing we frequently use serial interfacing RS232,RS485 and etc.

Requirements:
Gambas 2 interpreter/compiler
gb.net project component

Objectives:
1) To discuss the use of serial communications
2) To discuss the function of serial interface using gambas2
3) To demonstrate a simple program in gambas2


Methodology:
0) check the availability of serial port device " ls -l /dev/ttyS* "
1) check the ownership of "uccp" -default is owned by "root"
2) Open Gambas2
3) Add gb.net in the project component
3) Create a form
4) Specify setting in COM port:
Data bits
Flow control
Parity
Portname
Speed
Stopbits


Detail(1) Project properties to choose serial components


Detail(2) Icon for serial component


Detail(3) Serial Comm properties


Detail(4) Cut and paste source code
PRIVATE SComm AS SerialPort CONST None AS Integer = 0

PRIVATE Rx AS String  PUBLIC SUB Form_Open()
SComm = NEW SerialPort AS "SComm"
SComm.PortName = "/dev/ttyUSB0"
SComm.Speed = "19200"
SComm.Parity = 0
SComm.DataBits = "8"
SComm.StopBits = "1"
SComm.FlowControl = 0
TRY
SComm.Open()

IF ERROR THEN

TRY
SComm.PortName = "/dev/ttyS0"
SComm.Speed = "19200"
SComm.Parity = 0
SComm.DataBits = "8"
SComm.StopBits = "1"
SComm .FlowControl = 0

SComm.Open()

  IF ERROR THEN    
Message("No Serial Come Exiting...")
QUIT
ENDIF  

ENDIF

END  'Private RX

'******** Incoming serial data ********
PUBLIC SUB SComm _Read()
SLEEP 0.025
TRY READ #SComm , Rx, Lof(SComm )
IF ERROR THEN
Message.info(No received data!)
ENDIF

IF Len(Rx) > 8 THEN
TextBox1.Text= Cstr(Rx)
END IF

END

PUBLIC SUB Form_Close()
SComm.Close()
QUIT
END


Detail(5) Error message if serial port is not available


Detail(6): Checking serial port "ls -l /dev/ttyS*"


Detail(7) chown -R group.user /dev/ttyS0

Detail(8) Running serial interface -gambas2 example





Remarks:
Hints:
Problem: Can't open serial port#

1) Create a user and group to add it uucp(if you don't have a login-name)
root@localhost#groupmod –-add-user user_name uucp

2) change ownership (if you t have a login-name)
root@localhost# chown -R your_group.your_user /dev/ttyS0
Still on evaluations, and we hope that gambas2 developers
would add more features in the serial functions.

Problem: Can't have a faster read via serial port?
1) Try to empty first the buffer before reading the next data
buffer =""
buffer=read_serial()

2) of course you can adjust the faster baud rate your host device is capable too.


Conclusions:
A simple serial interfacing

E^3

Thursday, May 5, 2011

Installing Gambas3 in Fedora 14

Introductions:
There are more and more programmers are using gambas3 as their new VB6 like interpreter in Linux.It is so obvious that the widespread of its applications are being supported in the open community.

In this scratch article I will help you install Gambas3 and its easiest way, hoping 
that this tutorials could help you.
 
Good Luck 
 
 
Requirements:
Fedora OS
PC
Internet
 
Objectives:
1) To install Gambas3 in Fedora as easy as possible
2) To use Gambas3 in Linux programming applications 
 
Methodology:

Install the development tools and libraries 
root@localhost# yum groupinstall "Development Tools" "Development Libraries" 
 
Install the following apps: 
root@localhost# yum install  
cairo-devel libsqlite3x-devel 
sqlite2-devel 
gtk2-devel gtkglext-devel imlib2-devel librsvg2-devel 
poppler-devel qt-devel libv4l-devel 
SDL-devel SDL_sound-devel SDL_ttf-devel SDL_net-devel 
SDL_mixer-devel 
SDL_image-devel 
SDL_gfx-devel 
SDL_Pango-devel firebird-libfbclient unixODBC-devel 
postgresql-devel libXtst-devel 
mysql-devel pcre-devel mesa-libGLU-devel mesa-libGLw-devel 
mesa-libGL-devel glew-devel 
firebird-devel 
dbus-devel libzip libzip-devel 
bzip2-devel 
libcurl-devel qt-webkit-devel

Download Gambas3 from SVN 
root@localhost# mkdir gambas3-sources
root@localhost# cd gambas3-sources
root@localhost# svn checkout
 https://gambas.svn.sourceforge.net/svnroot/gambas/gambas/trunk/ 
 
Install  and configure Gambas3  
root@localhost# cd trunk 
root@localhost# ./reconf-all 
root@localhost# ./configure 
root@localhost# make 
root@localhost# make install  
 
 
Remarks:
Installing tools and libraries should be completed to avoid errors of compiling code in  Gambas3.To make sure you can download the files regardless of its number of versions, you may try doing this in yum: example: Sqlite
root@localhost@ yum install sqlite*

Conclusions:
This procedure of installations really help me for an instant installation of gambas3.This tutorial guides users the easy way of having gambas3 in their programming applications.