[Gambas-user] Serial Port Problem
Alex Schaller
gambas at ...1077...
Sat Aug 13 11:05:06 CEST 2005
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
More information about the User
mailing list