Tips on how to convert a device driver from desktop Seislog to SeislogCE
#########################################################################

In drivername.cpp  e.g SeisAD18.cpp
"""""""""""""""""""""""""""""""""""
Add
#include "stdafx.h"
#include "<aygshell.h>

remove define STRICT
add #define WINCE
 after #include lines

Search and replace
 CHAR -> TCHAR
 strcpy -> wcscpy
 strcmp -> wcscmp
 strcat -> wcscat
 itoa -> _itow
 sprintf -> swprintf
 sscanf -> swscanf
 strncpy -> wcsncpy
 atoi -> _wtoi


This is the biggest job:
all text i "", use the TEXT makro
 "text here" -> TEXT("text here")
Use search/replace.  


In ConfigDlgProc<drivername> method
Add the following so window pop up ok after pressing Configure button (after device is chosen):
define variable: SHINITDLGINFO shidi; // New in PocketPC version
...
after: case WM_INITDIALOG
        // Create a Done button and size it. New in PocketPC version.
 	  shidi.dwMask = SHIDIM_FLAGS;
	  shidi.dwFlags = SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
	  shidi.hDlg = hWndDlg;
	  SHInitDialog(&shidi);

At the end of WM_INITDIALOG change to:
ifdef WINCE
 SetForegroundWindow(hWndDlg);
#else
 BringWindowToTop(hWndDlg)
#endif


Just before CreateFile( ..)
#ifdef WINCE
  // All ports in Windows CE must end with ':'
  TCHAR CEPortName[7];
  wcscpy(CEPortName, DeviceConf.PortName);
  wcscat(CEPortName, TEXT(":"));
  hComm=CreateFile(CEPortName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
#else 
   wcscpy(SerPort, TEXT("\\\\.\\")); wcscat(SerPort, DeviceConf.PortName);
   hComm=CreateFile(SerPort, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
#endif
 
Fix 
ReaderThread<drivername>
RS-232 settings. Can not use BuildCommDCB(..). Define one and one setting, e.g.
#ifdef WINCE
  dcb.BaudRate  = _wtoi(SI->CommSpeed);
  dcb.Parity    = NOPARITY;
  dcb.StopBits  = ONESTOPBIT;
  dcb.ByteSize  = 8;
#else
  wcscpy(DevCntrlStr, TEXT("baud="));
  wcscat(DevCntrlStr, DeviceConf.CommSpeed);
  wcscat(DevCntrlStr, TEXT(" parity=N data=8 stop=1"));
  BuildCommDCB(DevCntrlStr, &dcb);
#endif         


In Devices.h
"""""""""""""
add 
DWORD WINAPI <name_of_driver>MngrThrd(PVOID);

In Devices.cpp
add name and driver-id in 3 methods; StartDevice, StartDeviceManager and AddDeviceDlgProc


Graphics (defined in Seislog.rc)
""""""""
Use dialog editor, visual tool. Copy element names (IDC_COMBO1 ..) from Seislog for Windows.
Except IDC_EDIT1 can not be used, use name IDC_TIME_CORR instead.
In combobox disable sort, define length of rolled down combobox by pressing key down arrow and drag the box downwards.

Search/replace in the drivername.cpp fil for the IDC_names that is changed (IDC_EDIT1 -> IDC_TIME_CORR).


Other
""""""""
In SeisAD18.cpp there was a problem with TM_STOP not sent when stop system chosen in menu, only TM_EXIT message sent.

This is new practice from programmer of Seislog for Windows. TM_EXIT method must then stop serialport Reader thread, 
after: case TM_DEPTHREADS_STOPPED: insert

         // First stop the device-reader thread.
         if (hReaderThread) {
            SerialRead=FALSE;                                            // Signal the reader thread.
            status=WaitForSingleObject(hReaderThread, 2000);             // Wait for the thread to stop.
            if (status==WAIT_TIMEOUT) TerminateThread(hReaderThread, 0); // If thread wont stop, kill it.
            hReaderThread=NULL;
         }

Sometimes PCHAR -> PTCHAR

DrawStatusBarText() takes only 2 parameter in CE (not 4 as in desktop Windows), two last are discarded.



