On 13.01.2008, at 03:58, Dave Pfaltzgraff wrote:

> I'm fairly new to the FLTK environment and thus am rather clumsy at  
> it. Are there any simple examples showing how to set up the  
> F1io_Serial_Port class?
>
> Anything that helps get me off dead center is greatly appreciated!  
> Even a basic window that opens the port woul do.

Flio_Serial_Port is not part of the official FLTK distibution, so  
there is no real support via this site. I contributed this class  
independently, so if there are any questions beyond the example below,  
you may contact me under my EMail address: [EMAIL PROTECTED] . There  
comes some HTML documentation with the archive, explaining every  
function.



Short sending and receiving example:

#include <FL/Fl_Button.H>
#include <FL/Fl_Window.H>
#include <FL/Flio_Serial_Port.H>

Fl_Window *win;
Fl_Button *btn_open;
Fl_Button *btn_send;
Flio_Serial_Port *ser;

void open_cb(Fl_Button*, void*) {
   ser->open("/dev/ttyS0", 38400); // on Unix/Linux/OS X
   // ser->open("\\.\COM1", 38400); // on MSWindows
}

void send_cb(Fl_Button*, void*) {
   ser->write("Hello Serial Port\n", 18);
}

void recv_cb(Flio_Serial_Port*, void*) {
   int n = ser->available();
   unsigned char *buffer = (unsigned char*)malloc(n+1);
   ser->read(buffer, n);
   buffer[n] = 0;
   fprintf(stdout, "Received test: <%s>\n", buffer);
}

int main(...) {
   win = new Fl_Window(400, 400);
   btn_open = new Fl_Button(10, 10, 250, 25, "Open");
   btn_open->callback(open_cb);
   btn_send = new Fl_Button(10, 45, 250, 25, "Send");
   btn_send->callback(send_cb);
   ser = new Flio_Serial_Port(160, 80, 100, 25, "Ser:");
   ser->callback(recv_cb);
   win->end();
   Fl::run();
}





----
http://robowerk.com/


_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to