Author: matt
Date: 2012-08-18 03:52:24 -0700 (Sat, 18 Aug 2012)
New Revision: 9674
Log:
Untested implementation of serial port communication for all platforms. 
Started to implement code to install freshly compiled libraries from within 
Fluid (OS X only for now).
The plan is, that Fluid assists in the rapid installation and basic setup of 
FLTK for IDE users. When done, Fluid can be the central service point for FLTK 
users.[Annika-2:~/dev/fltk-3.0.0] matt% Started to implement code to install 
freshly compiled libraries from within Fluid (OS X only for now).


Added:
   branches/branch-3.0/include/fltk3connect/SerialPort.h
   branches/branch-3.0/src/fltk3connect/SerialPort.cxx
Removed:
   branches/branch-3.0/include/fltk3connect/SerialConnection.h
   branches/branch-3.0/src/fltk3connect/SerialConnection.cxx
Modified:
   branches/branch-3.0/fltk.flw
   branches/branch-3.0/fluid/file_xcode.cxx
   branches/branch-3.0/fluid/fluid.cxx
   branches/branch-3.0/ide/VisualC2008/fltk3connect.vcproj
   branches/branch-3.0/ide/VisualC2010/fltk3connect.vcxproj
   branches/branch-3.0/ide/VisualC6/fltk3connect.dsp
   branches/branch-3.0/ide/VisualC6/fltk3connectdll.dsp
   branches/branch-3.0/ide/Xcode4/FLTK.xcodeproj/project.pbxproj
   branches/branch-3.0/include/fltk3connect/all.h
   branches/branch-3.0/src/Makefile
   branches/branch-3.0/src/fltk3/TextDisplay.cxx

Modified: branches/branch-3.0/fltk.flw
===================================================================
--- branches/branch-3.0/fltk.flw        2012-08-18 10:47:48 UTC (rev 9673)
+++ branches/branch-3.0/fltk.flw        2012-08-18 10:52:24 UTC (rev 9674)
@@ -4903,7 +4903,7 @@
       folder Headers {open
         uuid_Xcode4_Group {42734D78-E7BE-416D-8413-29EF99C76424}
       } {
-        file_ref {all.h} {selected
+        file_ref {all.h} {
           uuid_Xcode4_BuildFile {E444F00A-8DE7-4418-BB2A-705BE4A1F662}
           uuid_Xcode4_FileRef {D9E62B89-D8E5-4500-AC4A-E08CC9DE8E49}
           uuid_Xcode4_BuildFileInHeaders {44F55CDB-DF20-4086-8F58-D329F10222AB}
@@ -4927,13 +4927,13 @@
           list_env 124
           filename_and_path {include/fltk3connect/Socket.h}
         }
-        file_ref {SerialConnection.h} {
+        file_ref {SerialPort.h} {
           uuid_Xcode4_BuildFile {0CB96BDB-28E0-440F-A82E-23146EF30D58}
           uuid_Xcode4_FileRef {0ED9DE6E-11F5-487D-B980-DF0CF125B504}
           uuid_Xcode4_BuildFileInHeaders {D7A1DAAC-03DC-4C70-88C8-2EF1AE414B00}
           build_env 96
           list_env 124
-          filename_and_path {include/fltk3connect/SerialConnection.h}
+          filename_and_path {include/fltk3connect/SerialPort.h}
         }
         file_ref {TCPSocket.h} {
           uuid_Xcode4_BuildFile {5DFD6BFF-1E2C-454B-B5B1-8B73B0986C0B}
@@ -4976,10 +4976,10 @@
           uuid_Xcode4_FileRef {B6DC8E80-EB2E-4B92-BDB7-3AF5EB50D6C9}
           filename_and_path {src/fltk3connect/Socket.cxx}
         }
-        file_ref {SerialConnection.cxx} {
+        file_ref {SerialPort.cxx} {selected
           uuid_Xcode4_BuildFileInSources {9944741C-E39A-4372-8847-BCEE4EFCAE9F}
           uuid_Xcode4_FileRef {CE848D00-9304-4454-A495-FC3CAF98D759}
-          filename_and_path {src/fltk3connect/SerialConnection.cxx}
+          filename_and_path {src/fltk3connect/SerialPort.cxx}
         }
         file_ref {TCPSocket.cxx} {
           uuid_Xcode4_BuildFileInSources {2E2339CB-5ACF-4314-BAD6-ED1B41D12738}

Modified: branches/branch-3.0/fluid/file_xcode.cxx
===================================================================
--- branches/branch-3.0/fluid/file_xcode.cxx    2012-08-18 10:47:48 UTC (rev 
9673)
+++ branches/branch-3.0/fluid/file_xcode.cxx    2012-08-18 10:52:24 UTC (rev 
9674)
@@ -1160,6 +1160,180 @@
 }
 
 
+// ------------ install libraries for this environment 
-------------------------
+
+#ifdef __APPLE__
+
+#include <unistd.h>
+#include <copyfile.h>
+
+int filesize(const char *filename)
+{
+  struct stat st;
+  int ret = stat(filename, &st);
+  if (ret==-1) return -1;
+  return st.st_size;
+}
+
+void filename_minimize(char *filename) {
+  if (!filename) return;
+  char *key = strstr(filename, "/../");
+  if (!key) return;
+  *key = 0;
+  char *sep = strrchr(filename, '/');
+  if (!sep) { *key='/'; return; }
+  int n = strlen(key+1);
+  memmove(sep, key+3, n-1);
+  return filename_minimize(filename);
+}
+
+int copyfiles(const char *srcpath, const char *src, const char *dstpath)
+{
+  printf("Copying %s%s to %s\n", srcpath, src, dstpath);
+
+#if 0
+  /* Initialize a state variable */
+  copyfile_state_t s;
+  s = copyfile_state_alloc();
+  /* Copy the data and extended attributes of one file to another */
+  copyfile("/tmp/f1", "/tmp/f2", s, COPYFILE_DATA | COPYFILE_XATTR);
+  /* Convert a file to an AppleDouble file for serialization */
+  copyfile("/tmp/f2", "/tmp/tmpfile", NULL, COPYFILE_ALL | COPYFILE_PACK);
+  /* Release the state variable */
+  copyfile_state_free(s);
+  /* A more complex way to call copyfile() */
+  s = copyfile_state_alloc();
+  copyfile_state_set(s, COPYFILE_STATE_SRC_FILENAME, "/tmp/foo");
+  /* One of src or dst must be set... rest can come from the state */
+  copyfile(NULL, "/tmp/bar", s, COPYFILE_ALL);
+  /* Now copy the same source file to another destination file */
+  copyfile(NULL, "/tmp/car", s, COPYFILE_ALL);
+  copyfile_state_free(s);
+  /* Remove extended attributes from a file */
+  copyfile("/dev/null", "/tmp/bar", NULL, COPYFILE_XATTR);
+#endif
+  
+  return 0;
+}
+
+void install_library_cb(fltk3::Widget *, void *)
+{
+  char *source_path = 0L;
+  
+  printf("This is the platform installer for Xcode/OSX\n");
+  printf("The Fluid Source Code is here: <%s>\n", __FILE__);
+  char buf[2048], buf2[2048], buf3[2048];
+  strcpy(buf2, __FILE__);
+  
+  fltk3::filename_absolute(buf, buf2);
+  filename_minimize(buf);
+  
+  char *fe = strrchr(buf, '/');
+  if (fe) { *fe = 0; fe = strrchr(buf, '/'); }
+  if (!fe) {
+    printf("Unexpected path name\n");
+    return;
+  }
+  fe[1] = 0;
+  printf("FLTK base directory is <%s>\n", buf);
+  strcpy(buf3, buf);
+  strcat(buf3, "ide/Xcode4/FLTK.xcodeproj");
+  strcat(buf, 
"ide/Xcode4/FLTK.xcodeproj/project.xcworkspace/xcuserdata/%s.xcuserdatad/WorkspaceSettings.xcsettings");
+  sprintf(buf2, buf, getlogin());
+  printf("Workspace settings are in <%s>\n", buf2);
+  // 
./ide/Xcode4/FLTK.xcodeproj/project.xcworkspace/xcuserdata/matt.xcuserdatad/WorkspaceSettings.xcsettings
+  FILE *f = fopen(buf2, "rb");
+  if (f) {
+    printf("File exists. Check for entry (later)\n");
+    fclose(f);
+  }
+  // xcuserdata/.xcuserdatad
+  // This file is just a plist so easily readable. Our first step is to check 
the IDEWorkspaceUserSettings_DerivedDataLocationStyle value. If this is 1 we 
have a full path, if it is 2 we have a project relative path. Next we look at 
the IDEWorkspaceUserSettings_DerivedDataLocationStyle value to find the path. 
Simple enough.
+  
+  // Or: 
/Users/matt/Library/Developer/Xcode/DerivedData/FLTK-frqnkuxqefqgpnekypbtugmsyjpv/Build/Products/Debug/fltk.framework/
+  // Walk the directories and find info.plist, WorkspacePath should be the 
above path
+  sprintf(buf, "/Users/%s/Library/Developer/Xcode/DerivedData/", getlogin());
+  printf("Walk this directory: <%s>\n", buf);
+  
+  struct dirent **dir;
+  int i, nDir = fltk3::filename_list(buf, &dir);
+  
+  for (i=0; i<nDir; i++) {
+    printf("Dir %3d: %s\n", i, dir[i]->d_name);
+    if (strncmp(dir[i]->d_name, "FLTK-", 5)==0) { // FIXME: should that be 
"FLTK3-" ?
+      // verify that the path is correct in info.plist
+      sprintf(buf2, "%s%sinfo.plist", buf, dir[i]->d_name);
+      int sze = filesize(buf2);
+      if (sze>0) {
+        FILE *f = fopen(buf2, "rb");
+        if (f) {
+          printf("Checking info at %s\n", buf2);
+          char *blob = (char*)malloc(sze+1);
+          fread(blob, 1, sze, f);
+          blob[sze] = 0;
+          fclose(f);
+          const char *wsp = strstr(blob, "<key>WorkspacePath</key>");
+          // <key>WorkspacePath</key>
+          // 
<string>/Users/matt/dev/fltk-1.3.0/ide/Xcode4/FLTK.xcodeproj</string>
+          if (wsp) {
+            char *p1 = strstr(wsp, "<string>");
+            char *p2 = strstr(wsp, "</string>");
+            if (p1 && p2) {
+              p1 += 8;
+              *p2 = 0;
+              printf("Workspace is at <%s>\n", p1);
+              if (strcmp(p1, buf3)==0) {
+                printf("HOORRAY, found it\n");
+                source_path = strdup(buf2);
+              }
+            }
+          }
+          free(blob);
+        }
+      }
+    }
+    if (source_path) break;
+  }
+  
+  fltk3::filename_free_list(&dir, nDir);
+  
+  // Destination is:
+  // /Library/Frameworks/ or  ~/Library/Frameworks
+  
+  // Do we have a path? Check if there are any compiled libraries
+  strcpy(buf, source_path);
+  char *pp = (char*)fltk3::filename_name(buf);
+  strcpy(pp, "Build/Products/Debug/");
+  printf("Freshly built workspaces should be in <%s>\n", buf);
+  
+  // Great! No check if the workspaces are here and copy them over (Fluid as 
well? Where should it go?)
+  // OS X has a function copyfile() that recursively copies everything for us, 
including attribtes and resource fork. Thanks, Apple!
+  // on other platforms, copyfile() may or may not exists. Then again, we only 
need to copy files and not directory structures.
+  
+  // FIXME: check if the source is there and has a plausible date.
+  // FIXME: check for overwrite of old libraries
+  
+  sprintf(buf2, "/Users/%s/Library/Frameworks/", getlogin());
+  copyfiles(buf, "fltk3.workspace", buf2);
+  copyfiles(buf, "fltk3gl.workspace", buf2);
+  copyfiles(buf, "fltk3images.workspace", buf2);
+  copyfiles(buf, "fltk3png.workspace", buf2);
+  copyfiles(buf, "fltk3jpeg.workspace", buf2);
+  copyfiles(buf, "fltk3zlib.workspace", buf2);
+  copyfiles(buf, "fltk3connect.workspace", buf2);
+  
+  if (source_path) free(source_path);
+}
+
+#else
+
+void install_library_cb(fltk3::Widget *, void *)
+{
+}
+
+#endif
+
+
 //
 // End of "$Id: file_xcode.cxx 8870 2011-07-26 21:19:35Z matt $".
 //

Modified: branches/branch-3.0/fluid/fluid.cxx
===================================================================
--- branches/branch-3.0/fluid/fluid.cxx 2012-08-18 10:47:48 UTC (rev 9673)
+++ branches/branch-3.0/fluid/fluid.cxx 2012-08-18 10:52:24 UTC (rev 9674)
@@ -1178,6 +1178,7 @@
 void toggle_widgetbin_cb(fltk3::Widget *, void *);
 void toggle_sourceview_cb(fltk3::DoubleWindow *, void *);
 void write_makefiles_cb(fltk3::Widget *, void *);
+void install_library_cb(fltk3::Widget *, void *);
 
 fltk3::MenuItem Main_Menu[] = {
 {"&File",0,0,0,fltk3::SUBMENU},
@@ -1265,7 +1266,8 @@
   {"Execute &Command...",fltk3::ALT+'x',(fltk3::Callback *)show_shell_window},
   {"Execute &Again...",fltk3::ALT+'g',(fltk3::Callback 
*)do_shell_command,0,fltk3::MENU_DIVIDER},
   {"Build Application",fltk3::COMMAND+'b',(fltk3::Callback *)0L},
-  {"Run Application",fltk3::COMMAND+'r',(fltk3::Callback *)0L},
+  {"Run Application",fltk3::COMMAND+'r',(fltk3::Callback 
*)0L,0,fltk3::MENU_DIVIDER},
+  {"Install Library",0,(fltk3::Callback *)install_library_cb},
   //{"Convert", 0, 0, 0, fltk3::SUBMENU},
   //  {"FLTK 1 to 3", 0, convert_1_to_3_cb},
   //  {"FLTK 2 to 3", 0, convert_2_to_3_cb},

Modified: branches/branch-3.0/ide/VisualC2008/fltk3connect.vcproj
===================================================================
--- branches/branch-3.0/ide/VisualC2008/fltk3connect.vcproj     2012-08-18 
10:47:48 UTC (rev 9673)
+++ branches/branch-3.0/ide/VisualC2008/fltk3connect.vcproj     2012-08-18 
10:52:24 UTC (rev 9674)
@@ -184,7 +184,7 @@
                        </FileConfiguration>
                </File>
                <File
-                       
RelativePath="..\..\src\fltk3connect\SerialConnection.cxx"
+                       RelativePath="..\..\src\fltk3connect\SerialPort.cxx"
                        >
                        <FileConfiguration
                                Name="Debug|Win32"

Modified: branches/branch-3.0/ide/VisualC2010/fltk3connect.vcxproj
===================================================================
--- branches/branch-3.0/ide/VisualC2010/fltk3connect.vcxproj    2012-08-18 
10:47:48 UTC (rev 9673)
+++ branches/branch-3.0/ide/VisualC2010/fltk3connect.vcxproj    2012-08-18 
10:52:24 UTC (rev 9674)
@@ -100,7 +100,7 @@
       <AdditionalIncludeDirectories 
Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions 
Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
-    <ClCompile Include="..\..\src\fltk3connect\SerialConnection.cxx">
+    <ClCompile Include="..\..\src\fltk3connect\SerialPort.cxx">
       <Optimization 
Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
       <AdditionalIncludeDirectories 
Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions 
Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>

Modified: branches/branch-3.0/ide/VisualC6/fltk3connect.dsp
===================================================================
--- branches/branch-3.0/ide/VisualC6/fltk3connect.dsp   2012-08-18 10:47:48 UTC 
(rev 9673)
+++ branches/branch-3.0/ide/VisualC6/fltk3connect.dsp   2012-08-18 10:52:24 UTC 
(rev 9674)
@@ -87,7 +87,7 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\src\fltk3connect\SerialConnection.cxx
+SOURCE=..\..\src\fltk3connect\SerialPort.cxx
 # End Source File
 # Begin Source File
 

Modified: branches/branch-3.0/ide/VisualC6/fltk3connectdll.dsp
===================================================================
--- branches/branch-3.0/ide/VisualC6/fltk3connectdll.dsp        2012-08-18 
10:47:48 UTC (rev 9673)
+++ branches/branch-3.0/ide/VisualC6/fltk3connectdll.dsp        2012-08-18 
10:52:24 UTC (rev 9674)
@@ -95,7 +95,7 @@
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\src\fltk3connect\SerialConnection.cxx
+SOURCE=..\..\src\fltk3connect\SerialPort.cxx
 # End Source File
 # Begin Source File
 

Modified: branches/branch-3.0/ide/Xcode4/FLTK.xcodeproj/project.pbxproj
===================================================================
--- branches/branch-3.0/ide/Xcode4/FLTK.xcodeproj/project.pbxproj       
2012-08-18 10:47:48 UTC (rev 9673)
+++ branches/branch-3.0/ide/Xcode4/FLTK.xcodeproj/project.pbxproj       
2012-08-18 10:52:24 UTC (rev 9674)
@@ -479,7 +479,7 @@
                6E43C73F3494D4D92F5AE901 /* fltk3.framework in Frameworks */ = 
{isa = PBXBuildFile; fileRef = 86C380FE76A739F296A44961 /* fltk3.framework */; 
};
                2EC24DA9BFBB9AC18BF57B2B /* fltk3.framework in CopyFiles */ = 
{isa = PBXBuildFile; fileRef = 86C380FE76A739F296A44961 /* fltk3.framework */; 
};
                CB761F131FCAC105049627FC /* Socket.cxx in Sources */ = {isa = 
PBXBuildFile; fileRef = B6DC8E80A0BC8742EB50D6C9 /* Socket.cxx */; };
-               9944741CA0E834A94EFCAE9F /* SerialConnection.cxx in Sources */ 
= {isa = PBXBuildFile; fileRef = CE848D00D75058A9AF98D759 /* 
SerialConnection.cxx */; };
+               9944741CA0E834A94EFCAE9F /* SerialPort.cxx in Sources */ = {isa 
= PBXBuildFile; fileRef = CE848D00D75058A9AF98D759 /* SerialPort.cxx */; };
                2E2339CB19DB57CD41D12738 /* TCPSocket.cxx in Sources */ = {isa 
= PBXBuildFile; fileRef = E3300FB140BFB4B09CE11AEE /* TCPSocket.cxx */; };
                91D90EA7B228E6B6A3D51FC0 /* FTPClient.cxx in Sources */ = {isa 
= PBXBuildFile; fileRef = 6653881E54407BE8B3475553 /* FTPClient.cxx */; };
                BB62323B5751DEA0B2B54FD1 /* HTTPClient.cxx in Sources */ = {isa 
= PBXBuildFile; fileRef = ADEDA03B1A3DC4594498CFE4 /* HTTPClient.cxx */; };
@@ -487,7 +487,7 @@
                44F55CDB9FA65C71F10222AB /* all.h in Headers */ = {isa = 
PBXBuildFile; fileRef = D9E62B899DE54CC6C9DE8E49 /* all.h */; settings = 
{ATTRIBUTES = (Public, ); }; };
                1295F498263C3E4254217217 /* fltk3connect.h in Headers */ = {isa 
= PBXBuildFile; fileRef = 49D57DCA6AC907DBFB3EF012 /* fltk3connect.h */; 
settings = {ATTRIBUTES = (Public, ); }; };
                E2448FDB8226F5DCEB00893F /* Socket.h in Headers */ = {isa = 
PBXBuildFile; fileRef = BD6E3BFCED5FAF6386435304 /* Socket.h */; settings = 
{ATTRIBUTES = (Public, ); }; };
-               D7A1DAAC4FACA639AE414B00 /* SerialConnection.h in Headers */ = 
{isa = PBXBuildFile; fileRef = 0ED9DE6E5988668CF125B504 /* SerialConnection.h 
*/; settings = {ATTRIBUTES = (Public, ); }; };
+               D7A1DAAC4FACA639AE414B00 /* SerialPort.h in Headers */ = {isa = 
PBXBuildFile; fileRef = 0ED9DE6E5988668CF125B504 /* SerialPort.h */; settings = 
{ATTRIBUTES = (Public, ); }; };
                AFBB497E7C7A7AB9C1FB9F40 /* TCPSocket.h in Headers */ = {isa = 
PBXBuildFile; fileRef = 087FAF86423CD4458B04C53C /* TCPSocket.h */; settings = 
{ATTRIBUTES = (Public, ); }; };
                0B43B53BD6BAD148D4707528 /* FTPClient.h in Headers */ = {isa = 
PBXBuildFile; fileRef = B6C4777FCDD92C90D60875C4 /* FTPClient.h */; settings = 
{ATTRIBUTES = (Public, ); }; };
                0C4ECB313AD1610044814336 /* HTTPClient.h in Headers */ = {isa = 
PBXBuildFile; fileRef = E00EC8578C211F13A87F8F79 /* HTTPClient.h */; settings = 
{ATTRIBUTES = (Public, ); }; };
@@ -8992,13 +8992,13 @@
                D9E62B899DE54CC6C9DE8E49 /* all.h */ = {isa = PBXFileReference; 
fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = all.h; path = 
../../include/fltk3connect/all.h; sourceTree = SOURCE_ROOT; };
                49D57DCA6AC907DBFB3EF012 /* fltk3connect.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
fltk3connect.h; path = ../../include/fltk3connect/fltk3connect.h; sourceTree = 
SOURCE_ROOT; };
                BD6E3BFCED5FAF6386435304 /* Socket.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
Socket.h; path = ../../include/fltk3connect/Socket.h; sourceTree = SOURCE_ROOT; 
};
-               0ED9DE6E5988668CF125B504 /* SerialConnection.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
SerialConnection.h; path = ../../include/fltk3connect/SerialConnection.h; 
sourceTree = SOURCE_ROOT; };
+               0ED9DE6E5988668CF125B504 /* SerialPort.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
SerialPort.h; path = ../../include/fltk3connect/SerialPort.h; sourceTree = 
SOURCE_ROOT; };
                087FAF86423CD4458B04C53C /* TCPSocket.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
TCPSocket.h; path = ../../include/fltk3connect/TCPSocket.h; sourceTree = 
SOURCE_ROOT; };
                B6C4777FCDD92C90D60875C4 /* FTPClient.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
FTPClient.h; path = ../../include/fltk3connect/FTPClient.h; sourceTree = 
SOURCE_ROOT; };
                E00EC8578C211F13A87F8F79 /* HTTPClient.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
HTTPClient.h; path = ../../include/fltk3connect/HTTPClient.h; sourceTree = 
SOURCE_ROOT; };
                F6313A22BE464D0F077B0CD2 /* USBConnection.h */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = 
USBConnection.h; path = ../../include/fltk3connect/USBConnection.h; sourceTree 
= SOURCE_ROOT; };
                B6DC8E80A0BC8742EB50D6C9 /* Socket.cxx */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; 
name = Socket.cxx; path = ../../src/fltk3connect/Socket.cxx; sourceTree = 
SOURCE_ROOT; };
-               CE848D00D75058A9AF98D759 /* SerialConnection.cxx */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; 
name = SerialConnection.cxx; path = 
../../src/fltk3connect/SerialConnection.cxx; sourceTree = SOURCE_ROOT; };
+               CE848D00D75058A9AF98D759 /* SerialPort.cxx */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; 
name = SerialPort.cxx; path = ../../src/fltk3connect/SerialPort.cxx; sourceTree 
= SOURCE_ROOT; };
                E3300FB140BFB4B09CE11AEE /* TCPSocket.cxx */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; 
name = TCPSocket.cxx; path = ../../src/fltk3connect/TCPSocket.cxx; sourceTree = 
SOURCE_ROOT; };
                6653881E54407BE8B3475553 /* FTPClient.cxx */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; 
name = FTPClient.cxx; path = ../../src/fltk3connect/FTPClient.cxx; sourceTree = 
SOURCE_ROOT; };
                ADEDA03B1A3DC4594498CFE4 /* HTTPClient.cxx */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; 
name = HTTPClient.cxx; path = ../../src/fltk3connect/HTTPClient.cxx; sourceTree 
= SOURCE_ROOT; };
@@ -12401,7 +12401,7 @@
                                D9E62B899DE54CC6C9DE8E49 /* all.h */,
                                49D57DCA6AC907DBFB3EF012 /* fltk3connect.h */,
                                BD6E3BFCED5FAF6386435304 /* Socket.h */,
-                               0ED9DE6E5988668CF125B504 /* SerialConnection.h 
*/,
+                               0ED9DE6E5988668CF125B504 /* SerialPort.h */,
                                087FAF86423CD4458B04C53C /* TCPSocket.h */,
                                B6C4777FCDD92C90D60875C4 /* FTPClient.h */,
                                E00EC8578C211F13A87F8F79 /* HTTPClient.h */,
@@ -12414,7 +12414,7 @@
                        isa = PBXGroup;
                        children = (
                                B6DC8E80A0BC8742EB50D6C9 /* Socket.cxx */,
-                               CE848D00D75058A9AF98D759 /* 
SerialConnection.cxx */,
+                               CE848D00D75058A9AF98D759 /* SerialPort.cxx */,
                                E3300FB140BFB4B09CE11AEE /* TCPSocket.cxx */,
                                6653881E54407BE8B3475553 /* FTPClient.cxx */,
                                ADEDA03B1A3DC4594498CFE4 /* HTTPClient.cxx */,
@@ -14532,7 +14532,7 @@
                                44F55CDB9FA65C71F10222AB /* all.h in Headers */,
                                1295F498263C3E4254217217 /* fltk3connect.h in 
Headers */,
                                E2448FDB8226F5DCEB00893F /* Socket.h in Headers 
*/,
-                               D7A1DAAC4FACA639AE414B00 /* SerialConnection.h 
in Headers */,
+                               D7A1DAAC4FACA639AE414B00 /* SerialPort.h in 
Headers */,
                                AFBB497E7C7A7AB9C1FB9F40 /* TCPSocket.h in 
Headers */,
                                0B43B53BD6BAD148D4707528 /* FTPClient.h in 
Headers */,
                                0C4ECB313AD1610044814336 /* HTTPClient.h in 
Headers */,
@@ -20772,7 +20772,7 @@
                        buildActionMask = 2147483647;
                        files = (
                                CB761F131FCAC105049627FC /* Socket.cxx in 
Sources */,
-                               9944741CA0E834A94EFCAE9F /* 
SerialConnection.cxx in Sources */,
+                               9944741CA0E834A94EFCAE9F /* SerialPort.cxx in 
Sources */,
                                2E2339CB19DB57CD41D12738 /* TCPSocket.cxx in 
Sources */,
                                91D90EA7B228E6B6A3D51FC0 /* FTPClient.cxx in 
Sources */,
                                BB62323B5751DEA0B2B54FD1 /* HTTPClient.cxx in 
Sources */,

Deleted: branches/branch-3.0/include/fltk3connect/SerialConnection.h

Copied: branches/branch-3.0/include/fltk3connect/SerialPort.h (from rev 9645, 
branches/branch-3.0/include/fltk3connect/SerialConnection.h)
===================================================================
--- branches/branch-3.0/include/fltk3connect/SerialPort.h                       
        (rev 0)
+++ branches/branch-3.0/include/fltk3connect/SerialPort.h       2012-08-18 
10:52:24 UTC (rev 9674)
@@ -0,0 +1,192 @@
+//
+// "$Id$"
+//
+// FLTK3 connect library header file for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2002-2012 by Matthias Melcher and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems on the following page:
+//
+//     http://www.fltk.org/str.php
+//
+
+#ifndef FLTK3_SERIAL_PORT_H
+#define FLTK3_SERIAL_PORT_H
+
+#include <fltk3connect/Socket.h>
+
+/* \file
+ fltk3::SerialPort widget . */
+
+namespace fltk3 {
+
+/**
+ * A serial port communication widget for FLTK3.
+ *
+ * This widget manages communication over a serial port
+ * by providing a send and receive callback mechanism.
+ * It draws indicators of the connection state, but the
+ * Widget may as well stay hidden or not be part of a widget
+ * tree at all.
+ *
+ * Line indicators are two LED-style circles that are gray
+ * if the connection is closed, green if there is no data
+ * sent or received, and red if there is traffic.
+ *
+ * We are using a 2kByte ring buffer to implement buffering.
+ * If that seems to be too little, NRing in the constructor
+ * can be changed accordingly.
+ *
+ * \todo We have yet to stress test the threading mechanism for multiple 
open/close operations!
+ * \todo No buffer should be allocated until we actually open the line
+ * \todo We should implement some better error handling
+ * \todo We should provide an error message
+ * \todo We could provide a tooltip indicating the number of bytes transmitted
+ */
+class SerialPort : public Socket
+{
+public:
+  
+  /**
+   * Standard widget interface constructor.
+   */
+  SerialPort(int X, int Y, int W, int H, const char *L=0L);
+  
+  /**
+   * Constructor for superwidgets.
+   */
+  SerialPort(Socket *super);
+  
+  /**
+   * The destructor closes any open connections.
+   */
+  virtual ~SerialPort();
+  
+  /**
+   * Open a connection.
+   *
+   * All connections are opened with 8N1 for simplicity.
+   *
+   * \param[in] OS-specific port name, for example "\\.\COM1", or "/dev/ttyS0"
+   * \param[in] transfer rate in bits per second (38400bps)
+   * \return 0 for success, -1 if failed
+   */
+  virtual int open(const char *port, int bps);
+  
+  /**
+   * Write a block of binary data.
+   *
+   * This function returns immediatly.
+   *
+   * \param data[in] address of data block to send
+   * \param n[in] size of data block
+   * \return -1 if failed
+   */
+  int write(const unsigned char *data, int n);
+  
+  /**
+   * Return the number of bytes available.
+   *
+   * \return number of bytes available in the buffer
+   */
+  virtual int available() const;
+  
+  /**
+   * Read bytes from the buffer.
+   *
+   * This function reads at most n bytes from its internal
+   * buffer and makes room for new bytes to receive.
+   *
+   * \param dest[in] address of memory destination
+   * \param n[in] number of bytes to read at max
+   * \return number of bytes actually read
+   */
+  int read(unsigned char *dest, int n);
+  
+  /**
+   * Close the serial connection.
+   */
+  virtual void close();
+  
+  /**
+   * Check if the serial line is open.
+   *
+   * \return 0 if the connection is closed
+   */
+  int is_open();
+  
+  /**
+   * This will be called whenever data arrives.
+   *
+   * Alternative interface to callbacks. Available bytes
+   * are returned by available() and can then be read using
+   * read().
+   *
+   * \return return 1, if callback should not be called anymore
+   */
+  virtual int on_read();
+  
+  //virtual int on_error();
+  
+  virtual void draw();
+  void redraw();
+  
+protected:
+  
+  virtual int on_read_();
+  //virtual int on_error_();
+  
+private:
+  
+  static void on_read_cb(void *);
+  //static void on_error_cb(void *);
+  static void lights_cb(void *);
+  
+  unsigned char *ring_;
+  int NRing_;
+  int ringHead_;
+  int ringTail_;
+  char *portname_;
+  char rxActive_, pRxActive_;
+  char txActive_, pTxActive_;
+  
+  int available_to_end();
+  int free_to_end();
+  
+#ifdef WIN32
+  void reader_thread();
+  static void __cdecl reader_thread_(void*);
+  HANDLE port_;
+  HANDLE event_;
+  unsigned long thread_;
+  OVERLAPPED overlapped_;
+#else
+  int port_;
+  static void reader_cb(int, void*);
+  void reader();    
+#endif
+};
+
+}; // namespace
+
+#endif
+
+//
+// End of "$Id$".
+//
+

Modified: branches/branch-3.0/include/fltk3connect/all.h
===================================================================
--- branches/branch-3.0/include/fltk3connect/all.h      2012-08-18 10:47:48 UTC 
(rev 9673)
+++ branches/branch-3.0/include/fltk3connect/all.h      2012-08-18 10:52:24 UTC 
(rev 9674)
@@ -29,7 +29,7 @@
 #define FLTK3CONNECT_ALL_H
 
 #include "Socket.h"
-#include "SerialConnection.h"
+#include "SerialPort.h"
 #include "TCPSocket.h"
 #include "FTPClient.h"
 #include "HTTPClient.h"

Modified: branches/branch-3.0/src/Makefile
===================================================================
--- branches/branch-3.0/src/Makefile    2012-08-18 10:47:48 UTC (rev 9673)
+++ branches/branch-3.0/src/Makefile    2012-08-18 10:52:24 UTC (rev 9674)
@@ -203,7 +203,7 @@
 
 FLTK3CONNECT_CPPFILES = \
        fltk3connect/Socket.cxx \
-       fltk3connect/SerialConnection.cxx \
+       fltk3connect/SerialPort.cxx \
        fltk3connect/TCPSocket.cxx \
        fltk3connect/FTPClient.cxx \
        fltk3connect/HTTPClient.cxx \

Modified: branches/branch-3.0/src/fltk3/TextDisplay.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/TextDisplay.cxx       2012-08-18 10:47:48 UTC 
(rev 9673)
+++ branches/branch-3.0/src/fltk3/TextDisplay.cxx       2012-08-18 10:52:24 UTC 
(rev 9674)
@@ -2260,7 +2260,7 @@
  means translate the position to the nearest character cell.
  
  \param X, Y pixel coordinates
- \param[out] row, column neares row and column
+ \param[out] row, column nearest row and column
  \param posType CURSOR_POS or CHARACTER_POS
  */
 void fltk3::TextDisplay::xy_to_rowcol( int X, int Y, int *row,

Deleted: branches/branch-3.0/src/fltk3connect/SerialConnection.cxx

Copied: branches/branch-3.0/src/fltk3connect/SerialPort.cxx (from rev 9645, 
branches/branch-3.0/src/fltk3connect/SerialConnection.cxx)
===================================================================
--- branches/branch-3.0/src/fltk3connect/SerialPort.cxx                         
(rev 0)
+++ branches/branch-3.0/src/fltk3connect/SerialPort.cxx 2012-08-18 10:52:24 UTC 
(rev 9674)
@@ -0,0 +1,481 @@
+//
+// "$Id$"
+//
+// FLTK3 connect library source file for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 2002-2012 by Matthias Melcher and others.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU Library General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA.
+//
+// Please report all bugs and problems on the following page:
+//
+//     http://www.fltk.org/str.php
+//
+
+#include <fltk3connect/SerialPort.h>
+
+#ifdef _MSC_VER
+#pragma warning(disable : 4996)
+#endif
+
+//#define DEBUG_SEND
+//#define DEBUG_RECV
+
+#include "SerialPort.h"
+
+#include <fltk3/run.h>
+#include <fltk3/draw.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef WIN32
+# include <process.h>
+#else
+# include <sys/types.h>
+# include <sys/uio.h>
+# include <sys/ioctl.h>
+# include <unistd.h>
+# include <termios.h>
+# include <fcntl.h>
+# include <ctype.h>
+# include <errno.h>
+#endif
+
+using namespace fltk3;
+
+const int tDelay = 1000000/3480;
+//const int tDelay = 5000;
+
+
+fltk3::SerialPort::SerialPort(int X, int Y, int W, int H, const char *L)
+: fltk3::Socket(X, Y, W, H, L),
+ring_(0L),
+NRing_(0),
+ringHead_(0),
+ringTail_(0),
+portname_(0L),
+rxActive_(0),
+pRxActive_(0),
+txActive_(0),
+pTxActive_(0)
+#ifdef WIN32
+, port_(INVALID_HANDLE_VALUE),
+thread_(0)
+#else
+, port_(-1)
+#endif
+{
+  NRing_ = 2048;
+  ring_ = (unsigned char *)malloc(NRing_);
+}
+
+
+/*
+fltk3::SerialPort::SerialPort(fltk3::Socket *super)
+: fltk3::Socket(super),
+ring_(0L),
+NRing_(0),
+ringHead_(0),
+ringTail_(0),
+portname_(0L),
+rxActive_(0),
+pRxActive_(0),
+txActive_(0),
+pTxActive_(0),
+#ifdef WIN32
+port_(INVALID_HANDLE_VALUE),
+thread_(0)
+#else
+port_(-1)
+#endif
+{
+  NRing_ = 2048;
+  ring_ = (unsigned char *)malloc(NRing_);
+}
+ */
+
+
+fltk3::SerialPort::~SerialPort()
+{
+  close();
+  if (ring_)
+    ::free(ring_);
+  if (portname_)
+    ::free(portname_);
+}
+
+
+int fltk3::SerialPort::open(const char *portname, int bps)
+{
+  close();
+  if (portname_) {
+    free(portname_);
+    portname_ = 0L;
+  }
+  ringHead_ = ringTail_ = 0;
+  
+  if (!portname)
+    return -1;
+  
+  portname_ = strdup(portname);
+  
+#ifdef WIN32
+  port_ = CreateFile(portname, GENERIC_READ|GENERIC_WRITE,
+                     0, 0L, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0L );
+  if (port_ == INVALID_HANDLE_VALUE) {
+    return -1;
+  }
+  //SetupComm(port_, 2048, 2048);
+  
+  DCB arg; arg.DCBlength = sizeof(DCB);
+  GetCommState(port_, &arg);
+  int speed;
+  switch (bps) {
+    case 9600: speed = CBR_9600; break;
+    case 19200: speed = CBR_19200; break;
+    case 38400: speed = CBR_38400; break;
+    default: return -1;
+  }
+  arg.BaudRate = speed;
+  arg.fBinary = TRUE;
+  arg.fParity = FALSE;
+  arg.fOutxCtsFlow = FALSE;
+  arg.fOutxDsrFlow = TRUE;
+  arg.fDtrControl = DTR_CONTROL_HANDSHAKE;
+  arg.fDsrSensitivity = TRUE;
+  arg.fRtsControl = RTS_CONTROL_DISABLE;
+  arg.fAbortOnError = FALSE;
+  arg.ByteSize = 8;
+  arg.Parity = NOPARITY;
+  arg.StopBits = ONESTOPBIT;
+  SetCommState( port_, &arg );
+  
+  static COMMTIMEOUTS timeout = { MAXDWORD, 0, 0, 0, 0 };
+  SetCommTimeouts( port_, &timeout );
+  PurgeComm( port_, PURGE_TXCLEAR|PURGE_RXCLEAR );
+  ClearCommBreak(port_);
+  SetCommMask(port_, EV_RXCHAR);
+  
+  //EscapeCommFunction(port_, CLRRTS);
+  //EscapeCommFunction(port_, SETDTR);
+  
+  memset(&overlapped_, 0, sizeof(overlapped_));
+  event_ = CreateEvent(0, true, 0, 0);
+  overlapped_.hEvent = event_;
+  
+  if (!thread_)
+    _beginthread(reader_thread_, 0, this);
+#else
+  port_ = ::open(portname, O_RDWR|O_NOCTTY|O_NONBLOCK|O_NDELAY);
+  if (port_==-1)
+    return -1;
+  fcntl(port_, F_SETFL, FNDELAY);
+  struct termios tio = { 0 };
+  tcgetattr(port_, &tio);
+  // no modem support at all please
+  //cfmakeraw(&tio);
+  // now set the remaining flags to allow handshake via DTR/DSR
+  tio.c_iflag = (IGNPAR | IGNBRK); // don't do any of the modem stuff
+  tio.c_oflag = 0; // nothing to change here
+  tio.c_cflag = (CS8 | CREAD); // tfr is 8n1, not setting CLOCAL should enable 
DTR/DSR handshake
+  tio.c_lflag = 0; // and no terminal stuff either
+  cfmakeraw(&tio);
+  // FIXME: which flow control is actually used?
+  //tio.c_cflag = B38400 | CRTSCTS | CS8 | CLOCAL | CREAD;
+  //tio.c_cflag = B38400 | CS8 | CLOCAL | CREAD;
+  //tio.c_iflag = IGNPAR | IGNBRK;
+  //tio.c_oflag = 0;
+  //tio.c_lflag = 0;
+  cfsetspeed(&tio, bps);
+  tio.c_cc[VMIN] = 1;
+  tio.c_cc[VTIME] = 0;
+  tcflush(port_, TCIFLUSH);
+  int ret = tcsetattr(port_, TCSANOW, &tio);
+  if (ret==-1)
+    return -1;
+  fltk3::add_fd(port_, fltk3::READ, reader_cb, this);
+#endif
+  
+  rxActive_ = txActive_ = 0;
+  pRxActive_ = pTxActive_ = 0;
+  redraw();
+  fltk3::add_timeout(0.2, lights_cb, this);
+  
+#if (defined DEBUG_SEND) || (defined DEBUG_RCV)
+  printf("DEBUG: serial port \"%s\" at %dbps openend\n", portname, bps);
+#endif
+  
+  return 0;
+}
+
+
+/**
+ * Manage blinking status lights.
+ *
+ * This function works by checking the state of the line very 1/10th
+ * of a second. If data was sent or received, the corresponding
+ * LED will be set to red for the next 1/10th of a second. If nothing
+ * was sent, it will be set to green.
+ *
+ * If the state has not changed, nothing is drawn!
+ */
+void fltk3::SerialPort::lights_cb(void *u)
+{
+  fltk3::SerialPort *This = (fltk3::SerialPort*)u;
+  if ((This->rxActive_!=This->pRxActive_) || 
(This->txActive_!=This->pTxActive_)) {
+    This->pTxActive_ = This->txActive_;
+    This->pRxActive_ = This->rxActive_;
+    This->redraw();
+  }
+  This->txActive_ = This->rxActive_ = 0;
+  fltk3::repeat_timeout(0.1, lights_cb, This);
+}
+
+
+int fltk3::SerialPort::write(const unsigned char *data, int n)
+{
+#ifdef DEBUG_SEND
+  printf("DEBUG: ---> writing %d bytes to serial port\n", n);
+  DebugDumpBuffer((uint8_t*)data, n);
+#endif
+  
+  txActive_ = 1;
+#ifdef WIN32
+  DWORD result;
+  BOOL ret = WriteFile( port_, data, n, &result, &overlapped_ );
+  if (ret) {
+    return result;
+  } else {
+    return -1;
+  }
+#else
+  usleep(n*tDelay); // FIXME: artificial delay for Einstein pipe test
+  int ret = ::write(port_, data, n);
+  return ret;
+#endif
+}
+
+
+int fltk3::SerialPort::available() const
+{
+  int n = ringHead_ - ringTail_;
+  if (n<0)
+    n += NRing_;
+  return n;
+}
+
+
+int fltk3::SerialPort::read(unsigned char *dest, int n)
+{
+  int nMax = available();
+  if (nMax==0)
+    return 0;
+  if (n>nMax)
+    n = nMax;
+  int n1 = available_to_end();
+  if (n1>=n) {
+    memcpy(dest, ring_+ringTail_, n);
+    ringTail_ += n;
+  } else {
+    memcpy(dest, ring_+ringTail_, n1);
+    memcpy(dest+n1, ring_, n-n1);
+    ringTail_ = n-n1;
+  }
+#ifdef DEBUG_RECV
+  printf("DEBUG: <<-- read %d bytes from serial port buffer\n", n);
+  DebugDumpBuffer(dest, n);
+#endif
+  return n;
+}
+
+
+int fltk3::SerialPort::available_to_end()
+{
+  if (ringHead_>=ringTail_) {
+    return ringHead_ - ringTail_;
+  } else {
+    return NRing_ - ringTail_;
+  }
+}
+
+
+void fltk3::SerialPort::close()
+{
+  fltk3::remove_timeout(lights_cb, this);
+#ifdef WIN32
+  if (port_ != INVALID_HANDLE_VALUE) {
+    CloseHandle(port_);
+    port_ = INVALID_HANDLE_VALUE;
+  }
+#else
+  if (port_ != -1) {
+    fltk3::remove_fd(port_, fltk3::READ);
+    fltk3::remove_fd(port_);
+    ::close(port_);
+    port_ = -1;
+  }
+#endif
+  redraw();
+}
+
+
+int fltk3::SerialPort::free_to_end()
+{
+  if (ringHead_>=ringTail_) {
+    return NRing_ - ringHead_;
+  } else {
+    return ringTail_ - ringHead_ - 1;
+  }
+}
+
+#ifdef WIN32
+
+void fltk3::SerialPort::reader_thread()
+{
+  for(;;) {
+    DWORD nw;
+    DWORD mask;
+    WaitCommEvent(port_, &mask, &overlapped_);
+    WaitForSingleObject(event_, INFINITE);
+    // FIXME: what happens when we close the COM port?
+    // Will we ever leave the thread?
+    DWORD nc = 0, na;
+    for (;;) {
+      int n = free_to_end();
+      ReadFile(port_, ring_+ringHead_, n, &na, &overlapped_);
+      if (na==0)
+        break;
+      ringHead_ += na;
+      if (ringHead_ == NRing_)
+        ringHead_ = 0;
+      nc += na;
+    }
+    ResetEvent(event_);
+    if (nc) {
+      rxActive_ = 1;
+      Fl::awake(on_read_cb, this);
+    }
+  }
+}
+
+
+void fltk3::SerialPort::reader_thread_(void *u)
+{
+  fltk3::SerialPort *This = (fltk3::SerialPort*)u;
+  This->reader_thread();
+}
+
+#else
+
+void fltk3::SerialPort::reader_cb(int, void *u)
+{
+  fltk3::SerialPort *This = (fltk3::SerialPort*)u;
+  This->reader();
+}
+
+void fltk3::SerialPort::reader()
+{
+  int nc = 0;
+  for (;;) {
+    int n = free_to_end();
+    int na = ::read(port_, ring_+ringHead_, n);
+    if (na<=0)
+      break;
+    //#ifdef DEBUG_RECV
+    else {
+      printf("DEBUG: <--- received %d bytes from serial port\n", na);
+      //DebugDumpBuffer(ring_+ringHead_, na);
+    }
+    //#endif
+    ringHead_ += na;
+    if (ringHead_ == NRing_)
+      ringHead_ = 0;
+    nc += na;
+  }
+  usleep(nc*tDelay); // FIXME: artificial delay for Einstein pipe test
+  if (nc) {
+    rxActive_ = 1;
+    on_read_cb(this);
+  }
+}
+
+#endif
+
+void fltk3::SerialPort::draw()
+{
+  draw_box();
+  int r = (h()+2)/4, cx = x()+w()/2, cy = y()+h()/2;
+  fltk3::Color rxd, txd;
+  if (is_open()) {
+    if (pRxActive_) rxd = fltk3::RED; else rxd = fltk3::GREEN;
+    if (pTxActive_) txd = fltk3::RED; else txd = fltk3::GREEN;
+  } else {
+    rxd = txd = color();
+  }
+  fltk3::draw_symbol("@circle", cx-2*r-2, cy-r, 2*r+1, 2*r+1, rxd);
+  fltk3::draw_symbol("@circle", cx+0*r+2, cy-r, 2*r+1, 2*r+1, txd);
+}
+
+
+int fltk3::SerialPort::on_read() {
+  /*
+  if (super_)
+    return super_->on_read();
+  else
+   */
+    return 0;
+}
+
+
+int fltk3::SerialPort::on_read_() {
+  return on_read();
+}
+
+
+void fltk3::SerialPort::on_read_cb(void *u) {
+  fltk3::SerialPort *This = (fltk3::SerialPort*)u;
+  if (!This->on_read_() && This->callback()) {
+    This->do_callback();
+  }
+}
+
+
+int fltk3::SerialPort::is_open()
+{
+#ifdef WIN32
+  return (port_!=INVALID_HANDLE_VALUE);
+#else
+  return (port_!=-1);
+#endif
+}
+
+
+void fltk3::SerialPort::redraw()
+{
+  /*
+  if (super_)
+    super_->redraw();
+  else
+   */
+    fltk3::Socket::redraw();
+}
+
+
+//
+// End of "$Id$".
+//

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

Reply via email to