[Gambas-user] Serial Port Problem

Daniel Campos danielcampos at ...282...
Sat Aug 13 16:20:50 CEST 2005


Hi:

The SerialPort class is intended to be used in more simple scenarios: as 
you are
using a very low-level control over the serial port, you should perform 
all operations
(including the pauses), using directly "API calls". This is possible 
using Gambas2,
as Gambas1 does not provide that functionallity. Or may be you can open the
port with a SerialPort object, then pass the "Id" or "Handle" property 
to these
"api calls", and then send and receive data using that SerialPort 
object, but I don't
know if the ioctl commands will interference the normal SerialPort 
object work. It is
a try and error matter.

There is some brief information about API calls here: 
http://64.128.110.55/help/lang/extdecl ,
so you can start transfering the C code to Gambas code. You should know 
where the C functions
are placed (I think all that you need is placed at glibc library), and 
the values of the constants
(for example, you can look in the headers included in the C sources, or 
write a little C program
with these headers and then "printf("%d\n",B9600)" and things like this).

Regards,

D. Campos


Alex Schaller escribió:

>Hello!
>
>I am trying to write an IDE for the  Basic Stamp microcontroller.
>This contoller interfaces through the serial port with the PC. Here is the 
>required sequence to interface with it.
>
>1.	Set DTR HIGH
>2.	Set Break condition on TX
>3.	Pause for at least 2ms
>4.	Set DTR LOW
>5.	Pause for at least 36ms
>6.	Clear break condition
>7.	Pause for approximately 20ms and flush receive buffer.
>
>After that you have to send and receive a sequence of characters to identify 
>the actual version of the microcontroller.
>I was using the Wait() function for the pause sequences. What I don't know is 
>how to do the "Set/Clear Break condition on TX". I found some C-Source code 
>on how this is done in C. But I don't understand it enough to make sense of 
>it. Here is the C-Code:
>              
>  //setup serial port
>                tcgetattr(fd,&oldtios);
>                newtios.c_cflag=B9600|CS8|CLOCAL|CREAD;
>                newtios.c_iflag=IGNPAR;
>                newtios.c_oflag=0;
>                newtios.c_lflag=0;
>                newtios.c_line=0;
>                newtios.c_cc[VMIN]=0;
>                newtios.c_cc[VTIME]=5;
>                tcsetattr(fd,TCSANOW,&newtios);
>
>   //init protocol
>                dtr_flag=TIOCM_DTR;
>                ioctl(fd,TIOCMBIS,&dtr_flag);
>                ioctl(fd,TIOCSBRK,4);
>                usleep(2000);
>                dtr_flag=TIOCM_DTR;
>                ioctl(fd,TIOCMBIC,&dtr_flag);
>                usleep(36000);
>                ioctl(fd,TIOCCBRK,4);
>                usleep(2000);
>                tcflush(fd,TCIFLUSH);
> 
>He is using the ioctl() function but I could not find anything like it in 
>Gambas. Hopefully someone can tell me how to do this in Gambas or use the 
>C-Code in Gambas.
>
>
>Thanks!!!!
>
>Alex
>
>
>
>-------------------------------------------------------
>SF.Net email is Sponsored by the Better Software Conference & EXPO
>September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
>Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
>Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
>_______________________________________________
>Gambas-user mailing list
>Gambas-user at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
>  
>





More information about the User mailing list