I am trying to write a program which sends text from a forms Rich Edit Boxes via 2 serial ports( COM3 and COM 4 have 2 rich edit boxes each for incoming and outgoing text) using Borland C++ Builder 2006. This program uses some C++ serial port communication library code I downloaded. I have also created a buffer for each of them. The serial ports are opened successfully when I run this program. However, I can't get the rich edit boxes to display the texts their serial ports have received. The files containing the codes are as follows:
1. serialcomform.cpp

2. serialcomform.h

The library files are as follows:
1. rlserial.cpp
2. rlserial.h
3. rldefine.h
4. rlthread.h
5. rlwthread.h

The documentation of the library codes can be found at http://pvbrowser.de/pvbrowser/sf/manual/rllib/html/classrlSerial.html"> http://pvbrowser.de/pvbrowser/sf/manual/rllib/html/classrlSerial.html
Also find attached some of the project files in case you want to compile and run it.

1. serialkomm.cpp


Can comeone please help me with this problem?
Thanks!

NB: I'm sorry if I haven't followed all the forum's posting rules. It's my first time and I've done it to the best of my understanding.

Attachments
/***************************************************************************
                           rldefine.h  -  description
                              -------------------
     begin                : Wed Dec 04 2002
     copyright            : (C) 2001 by Rainer Lehrig
     email                : lehrig@t-online.de
  ***************************************************************************/
 
 /***************************************************************************
  *                                                                         *
  *   This library is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
  *   published by the Free Software Foundation                             *
  *                                                                         *
  ***************************************************************************/
 #ifndef _RL_DEFINE_H_
 #define _RL_DEFINE_H_
 
 // define unix if not already defined
 #ifdef __unix__
 #ifndef unix
 #define unix
 #endif
 #endif
 
 #define rl_PRINTF_LENGTH             4096
 #define rl_PRINTF_LENGTH_SPREADSHEET 4096
 
 #define BIT0  1
 #define BIT1  2
 #define BIT2  4
 #define BIT3  8
 #define BIT4  16
 #define BIT5  32
 #define BIT6  64
 #define BIT7  128
 #define BIT8  256*1
 #define BIT9  256*2
 #define BIT10 256*4
 #define BIT11 256*8
 #define BIT12 256*16
 #define BIT13 256*32
 #define BIT14 256*64
 #define BIT15 256*128
 #define BIT16 256*256*1
 #define BIT17 256*256*2
 #define BIT18 256*256*4
 #define BIT19 256*256*8
 #define BIT20 256*256*16
 #define BIT21 256*256*32
 #define BIT22 256*256*64
 #define BIT23 256*256*128
 #define BIT24 256*256*256*1
 #define BIT25 256*256*256*2
 #define BIT26 256*256*256*4
 #define BIT27 256*256*256*8
 #define BIT28 256*256*256*16
 #define BIT29 256*256*256*32
 #define BIT30 256*256*256*64
 #define BIT31 256*256*256*128
 
 #endif
/***************************************************************************
                           rlserial.cpp  -  description
                              -------------------
     begin                : Sat Dec 21 2002
     copyright            : (C) 2002 by Rainer Lehrig
     email                : lehrig@t-online.de
 
     RMOS implementation:
     Copyright            : (C) 2004 Zertrox GbR
     Written by           : Alexander Feller
     Email                : feller@zertrox.de
  ***************************************************************************/
 
 /***************************************************************************
  *                                                                         *
  *   This library is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
  *   published by the Free Software Foundation                             *
  *                                                                         *
  ***************************************************************************/
 #include "rlserial.h"
 
 #ifdef unix
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <termios.h>
 #include <unistd.h>
 #include <signal.h>
 #endif
 
 #ifdef __VMS
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <starlet.h>
 #include <descrip.h>
 #include <lib$routines.h>
 #include <ssdef.h>
 #include <iodef.h>
 typedef struct
 {
   short    iostat;
   unsigned short msg_len;
   int      reader_pid;
 }IOSB;
 #endif
 
 #ifdef _WIN32
 #include <windows.h>
 #include <stdio.h>
 #endif
 
 #ifdef RM3
 #include <stdio.h>
 #include <stdlib.h>
 #include <rmcomp.h>
 #include <rmapi.h>
 #include <rio.h>
 #include <drvspec.h>
 #include <rm3cav.h>
 //#include <clean.h>
 #include <rcinc.h>
 #define RTS_TIME_WAIT 0x008     /* Verzoerungszeit fuer RTS - Signal      */
 #endif
 
 #include "rlthread.h"
 
 /*
 static void sighandler(int sig)
 {
   if(sig == SIGINT)
   {
     closeDevice();
     closeDatabase();
   }
 }
 */
 
 rlSerial::rlSerial()
 {
   ttysavefd = -1;
   ttystate  = RESET;
   fd        = -1;
   trace     = 0;
 }
 
 rlSerial::~rlSerial()
 {
   closeDevice();
 }
 
 void rlSerial::setTrace(int on)
 {
   if(on == 1) trace = 1;
   else        trace = 0;
 }
 
 int rlSerial::openDevice(const char *devicename, int speed, int block, int rtscts, int bits, int stopbits, int parity)
 {
 #ifdef unix
   struct termios buf;
 
   if(fd != -1) return -1;
   fd = open(devicename, O_RDWR | O_NOCTTY | O_NDELAY);
   if(fd < 0) { return -1; }
 
   //signal(SIGINT, sighandler);
 
   if(tcgetattr(fd, &save_termios) < 0) { return -1; }
   buf = save_termios;
   buf.c_cflag = speed | CLOCAL | CREAD;
   if(rtscts   == 1)  buf.c_cflag |= CRTSCTS;
   if(bits     == 7)  buf.c_cflag |= CS7;
   else               buf.c_cflag |= CS8;
   if(stopbits == 2)  buf.c_cflag |= CSTOPB;
   if(parity == rlSerial::ODD)  buf.c_cflag |= (PARENB | PARODD);
   if(parity == rlSerial::EVEN) buf.c_cflag |= PARENB;
   buf.c_lflag = IEXTEN; //ICANON;
   buf.c_oflag     = OPOST;
   buf.c_cc[VMIN]  = 1;
   buf.c_cc[VTIME] = 0;
   buf.c_line      = 0;
   buf.c_iflag     = IGNBRK | IGNPAR | IXANY;
   if(tcsetattr(fd, TCSAFLUSH, &buf) < 0) { return -1; }
   //if(tcsetattr(fd, TCSANOW, &buf) < 0) { return -1; }
   ttystate = RAW;
   ttysavefd = fd;
   if(block == 1) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
   tcflush(fd,TCIOFLUSH);
 #endif
 
 #ifdef __VMS
   // Please set com parameters at DCL level
   struct dsc$descriptor_s dsc;
   int status;
 
   dsc.dsc$w_length  = strlen(devicename);
   dsc.dsc$a_pointer = (char *) devicename;
   dsc.dsc$b_class   = DSC$K_CLASS_S;
   dsc.dsc$b_dtype   = DSC$K_DTYPE_T;
   status = SYS$ASSIGN(&dsc,&vms_channel,0,0);
   if(status != SS$_NORMAL) return -1;
 #endif
 
 #ifdef _WIN32
   DWORD ccsize;
   COMMCONFIG cc;
   int baudrate,ret;
   char devname[100];
 
   if(strlen(devicename) > 80) return -1;
   sprintf(devname,"\\\\.\\%s",devicename);        // Aenderung: allow more than 4 COM ports
   hdl = CreateFile(
                    devname,                       // devicename, // pointer to name of the file
                    GENERIC_READ | GENERIC_WRITE,  // access (read-write) mode
                    0,                             // share mode
                    0,                             // pointer to security attributes
                    OPEN_EXISTING,                 // how to create
                    0,                             // not overlapped I/O
                    0                              // handle to file with attributes to copy
                   );
   if(hdl == INVALID_HANDLE_VALUE)
   {
     printf("CreateFile(%s) failed\n",devicename);
     return -1;
   }
 
   baudrate = CBR_9600;
   if(speed == B50     ) baudrate = 50;
   if(speed == B75     ) baudrate = 75;
   if(speed == B110    ) baudrate = CBR_110;
   if(speed == B134    ) baudrate = 134;
   if(speed == B150    ) baudrate = 150;
   if(speed == B200    ) baudrate = 200;
   if(speed == B300    ) baudrate = CBR_300;
   if(speed == B600    ) baudrate = CBR_600;
   if(speed == B1200   ) baudrate = CBR_1200;
   if(speed == B1800   ) baudrate = 1800;
   if(speed == B2400   ) baudrate = CBR_2400;
   if(speed == B4800   ) baudrate = CBR_4800;
   if(speed == B9600   ) baudrate = CBR_9600;
   if(speed == B19200  ) baudrate = CBR_19200;
   if(speed == B38400  ) baudrate = CBR_38400;
   if(speed == B57600  ) baudrate = CBR_57600;
   if(speed == B115200 ) baudrate = CBR_115200;
   if(speed == B230400 ) baudrate = 230400;
   if(speed == B460800 ) baudrate = 460800;
   if(speed == B500000 ) baudrate = 500000;
   if(speed == B576000 ) baudrate = 576000;
   if(speed == B921600 ) baudrate = 921600;
   if(speed == B1000000) baudrate = 1000000;
   if(speed == B1152000) baudrate = 1152000;
   if(speed == B1500000) baudrate = 1500000;
   if(speed == B2000000) baudrate = 2000000;
   if(speed == B2500000) baudrate = 2500000;
   if(speed == B3000000) baudrate = 3000000;
   if(speed == B3500000) baudrate = 3500000;
   if(speed == B4000000) baudrate = 4000000;
 
   GetCommConfig(hdl,&cc,&ccsize);
   //cc.dwSize            = sizeof(cc);  // size of structure
   //cc.wVersion          = 1;           // version of structure
   //cc.wReserved         = 0;           // reserved
   //  DCB   dcb;                      // device-control block
   cc.dcb.DCBlength     = sizeof(DCB); // sizeof(DCB)
   cc.dcb.BaudRate      = baudrate;    // current baud rate
   cc.dcb.fBinary       = 1;           // binary mode, no EOF check
   cc.dcb.fParity       = 1;           // enable parity checking
   cc.dcb.fOutxCtsFlow  = 0;           // CTS output flow control
   if(rtscts == 1) cc.dcb.fOutxCtsFlow = 1;
   cc.dcb.fOutxDsrFlow  = 0;           // DSR output flow control
   cc.dcb.fDtrControl   = DTR_CONTROL_DISABLE;  // DTR flow control type
   cc.dcb.fDsrSensitivity   = 0;       // DSR sensitivity
   cc.dcb.fTXContinueOnXoff = 1;       // XOFF continues Tx
   //cc.dcb.fOutX         = 0;           // XON/XOFF out flow control
   //cc.dcb.fInX          = 0;           // XON/XOFF in flow control
   //cc.dcb.fErrorChar    = 0;           // enable error replacement
   cc.dcb.fNull         = 0;           // enable null stripping
   cc.dcb.fRtsControl   = RTS_CONTROL_DISABLE;
   if(rtscts == 1)  cc.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;  // RTS flow control
   cc.dcb.fAbortOnError = 0;           // abort reads/writes on error
   //cc.dcb.fDummy2       = 0;           // reserved
   //cc.dcb.wReserved     = 0;           // not currently used
   //cc.dcb.XonLim        = 0;           // transmit XON threshold
   //cc.dcb.XoffLim       = 0;           // transmit XOFF threshold
   cc.dcb.ByteSize      = bits;        // number of bits/byte, 4-8
   cc.dcb.Parity        = 0;           // 0-4=no,odd,even,mark,space
   if(parity == rlSerial::ODD)    cc.dcb.Parity = 1;
   if(parity == rlSerial::EVEN)   cc.dcb.Parity = 2;
   cc.dcb.StopBits      = ONESTOPBIT;  // 0,1,2 = 1, 1.5, 2
   if(stopbits==2) cc.dcb.StopBits = TWOSTOPBITS;
   //cc.dcb.XonChar       = 0;           // Tx and Rx XON character
   //cc.dcb.XoffChar      = 0;           // Tx and Rx XOFF character
   //cc.dcb.ErrorChar     = 0;           // error replacement character
   //cc.dcb.EofChar       = 0;           // end of input character
   //cc.dcb.EvtChar       = 0;           // received event character
   //cc.dcb.wReserved1    = 0;           // reserved; do not use
   cc.dwProviderSubType = PST_RS232;   // type of provider-specific data
   //cc.dwProviderOffset  = 0;           // offset of provider-specific data
   //cc.dwProviderSize    = 0;           // size of provider-specific data
   //cc.wcProviderData[0] = 0;           // provider-specific data
 
   ret = SetCommConfig(hdl,&cc,sizeof(cc));
   if(ret == 0)
   {
     printf("SetCommConfig ret=%d devicename=%s LastError=%d\n",ret,devicename,GetLastError());
     return -1;
   }
 #endif
 
 #ifdef RM3
   RmEntryStruct    CatEntry;        /* Struktur der Deiviceinformationen              */
   int              iStatus;         /* Rckgabewert                                    */
   RmIOStatusStruct DrvSts;          /* Struktur der Rckgabewerte fr RmIO - Funktion   */
   RmBytParmStruct  PBlock;          /* Parameterstruktur fr RmIO - Funktion           */
   static UCD_BYT_PORT Ucd_byt_drv;  /* Struktur zum Setzen der UCD - Werte            */
   ushort           uTimeBd;         /* Timing - Wert der ertragungsgeschwindigkeit   */
   uint             uMode;           /* Portsteuerungsparameter                        */
   unsigned char    cByte;           /* Byte - Parameter                               */
                                     /* Timing = 748800 / Baudrate;                    */
                                     /*****************************************
/***************************************************************************
                           rlserial.cpp  -  description
                              -------------------
     begin                : Sat Dec 21 2002
     copyright            : (C) 2002 by Rainer Lehrig
     email                : lehrig@t-online.de
 
     RMOS implementation:
     Copyright            : (C) 2004 Zertrox GbR
     Written by           : Alexander Feller
     Email                : feller@zertrox.de
  ***************************************************************************/
 
 /***************************************************************************
  *                                                                         *
  *   This library is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
  *   published by the Free Software Foundation                             *
  *                                                                         *
  ***************************************************************************/
 #ifndef _RL_SERIAL_H_
 #define _RL_SERIAL_H_
 
 #include "rlthread.h"
 
 #ifdef unix
 #include <termios.h>
 #endif
 
 #ifndef B0
 // speed will be defined by termios.h, this is just for documentation
 #define  B0       0000000  /* hang up */
 #define  B50      0000001
 #define  B75      0000002
 #define  B110     0000003
 #define  B134     0000004
 #define  B150     0000005
 #define  B200     0000006
 #define  B300     0000007
 #define  B600     0000010
 #define  B1200    0000011
 #define  B1800    0000012
 #define  B2400    0000013
 #define  B4800    0000014
 #define  B9600    0000015
 #define  B19200   0000016
 #define  B38400   0000017
 #define  B57600   0010001
 #define  B115200  0010002
 #define  B230400  0010003
 #define  B460800  0010004
 #define  B500000  0010005
 #define  B576000  0010006
 #define  B921600  0010007
 #define  B1000000 0010010
 #define  B1152000 0010011
 #define  B1500000 0010012
 #define  B2000000 0010013
 #define  B2500000 0010014
 #define  B3000000 0010015
 #define  B3500000 0010016
 #define  B4000000 0010017
 #endif
 
 class rlSerial
 {
   public:
     enum Parity
     {
       NONE = 0,
       ODD ,
       EVEN
     };
 
     rlSerial();
     ~rlSerial();
     int openDevice(const char *devicename, int speed=B9600, int block=1, int rtscts=1, int bits=8, int stopbits=1, int parity=rlSerial::NONE);
     int select(int timeout=500);
     int readChar();
     int writeChar(unsigned char uchar);
     int readBlock(unsigned char *buf, int len);
     int writeBlock(const unsigned char *buf, int len);
     int readLine(unsigned char *buf, int maxlen, int timeout=1000);
     int closeDevice();
     void setTrace(int on);
   private:
 #ifdef unix
     struct termios save_termios;
 #endif
 #ifdef __VMS
     unsigned short int vms_channel;
 #endif
 #ifdef _WIN32
     HANDLE hdl;
 #endif
 #ifdef RM3
     int device, uint, com, baudrate;
 #endif
     enum { RESET, RAW, CBREAK } ttystate;
     int ttysavefd;
     int fd,trace;
 };
 
 #endif
/***************************************************************************
                           rlthread.h  -  description
                              -------------------
     begin                : Tue Jan 02 2001
     copyright            : (C) 2001 by Rainer Lehrig
     email                : lehrig@t-online.de
  ***************************************************************************/
 
 /***************************************************************************
  *                                                                         *
  *   This library is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
  *   published by the Free Software Foundation                             *
  *                                                                         *
  ***************************************************************************/
 #ifndef _RL_THREAD_H_
 #define _RL_THREAD_H_
 
 #include "rldefine.h"
 #include "rlwthread.h"
 
 class rlThread;
 
 typedef struct
 {
   rlThread *thread;
   void     *user;
   int      running;
 }
 THREAD_PARAM;
 
 class rlThread
 {
 public:
   rlThread(int max_semphore=1000);
   ~rlThread();
   int create(void *(*func)(void*), void *argument);
 
   int trylock();
 
   int lock();
 
   int unlock();
 
   int waitSemaphore();
 
   int incrementSemaphore();
 
   int join(void **status);
 
   int cancel();
 
   void threadExit(void *status);
 
   pthread_t       tid;
   pthread_attr_t  attr;
   pthread_mutex_t mutex;
   WSEMAPHORE      semaphore;
 private:
   THREAD_PARAM    arg;
 };
 
 class rlMutex
 {
 public:
   rlMutex(const pthread_mutexattr_t *attr = NULL);
   ~rlMutex();
 
   int trylock();
 
   int lock();
 
   int unlock();
 
   pthread_mutex_t mutex;
 };
 
 class rlSemaphore
 {
 public:
   rlSemaphore(int max_semaphore = 1000);
   ~rlSemaphore();
 
   int waitSemaphore();
 
   int incrementSemaphore();
 
   WSEMAPHORE      semaphore;
 };
 
 #endif
/***************************************************************************
                           wthread.h  -  description
                              -------------------
     begin                : Sun Jan 02 2000
     copyright            : (C) 2001 by Rainer Lehrig
     email                : lehrig@t-online.de
  ***************************************************************************/
 
 /***************************************************************************
  *                                                                         *
  *   This library is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
  *   published by the Free Software Foundation                             *
  *                                                                         *
  ***************************************************************************/
 /***********************************************************************************
 
 Wrapper for posix threads (UNIX,VMS,windows)
 
 (C) Rainer Lehrig 2001                                       lehrig@t-online.de
 
 ***********************************************************************************/
 
 #ifndef _RL_WTHREAD_H_
 #define _RL_WTHREAD_H_
 
 #include "rldefine.h"
 
 #ifdef _WIN32
 
 #include <windows.h>
 #include <winbase.h>
 #include <stddef.h>
 #include <string.h>
 
 #ifndef _WRAPTHREAD_
 #ifndef _WTHREAD_H_
 typedef unsigned long int pthread_t;
 
 /* Attributes for threads */
 struct __sched_param
 {
   int sched_priority;
 };
 
 typedef struct
 {
   int     __detachstate;
   int     __schedpolicy;
   struct  __sched_param __schedparam;
   int     __inheritsched;
   int     __scope;
   size_t  __guardsize;
   int     __stackaddr_set;
   void   *__stackaddr;
   size_t  __stacksize;
 }pthread_attr_t;
 
 typedef HANDLE pthread_mutex_t;
 //old typedef CRITICAL_SECTION pthread_mutex_t;
 typedef long             pthread_mutexattr_t;
 #endif
 #endif
 
 #else  /* VMS or UNIX */
 #include <pthread.h>
 #endif /* end of MSWINDOWS */
 
 #ifndef _WRAPTHREAD_
 #ifndef _WTHREAD_H_
 typedef struct
 {
 #ifdef _WIN32
   int    cmax;
   HANDLE hSemaphore;
 #else
   int              cmax;
   int              nready;
   pthread_mutex_t  mutex;
   pthread_cond_t   cond;
 #endif
 }WSEMAPHORE;
 #endif
 #endif
 
 /* function prototypes */
 //#ifdef __cplusplus
 //extern "C" {
 //#endif
 int  rlwthread_attr_init(pthread_attr_t *attr);
 int  rlwthread_create(pthread_t *tid, const pthread_attr_t *attr,
                       void *(*func)(void*), void *arg);
 void rlwthread_close_handle(pthread_t *tid);
 void rlwthread_exit(void *status);
 int  rlwthread_join(pthread_t tid, void **status);
 int  rlwthread_mutex_init(pthread_mutex_t *mptr, const pthread_mutexattr_t *attr);
 int  rlwthread_mutex_destroy(pthread_mutex_t *mptr);
 int  rlwthread_mutex_lock(pthread_mutex_t *mptr);
 int  rlwthread_mutex_trylock(pthread_mutex_t *mptr);
 int  rlwthread_mutex_unlock(pthread_mutex_t *mptr);
 int  rlwthread_cancel(pthread_t tid);
 int  rlwrapinit_semaphore(WSEMAPHORE *s, int cmax);
 int  rlwrapdestroy_semaphore(WSEMAPHORE *s);
 int  rlwrapincrement_semaphore(WSEMAPHORE *s);
 int  rlwrapwait_semaphore(WSEMAPHORE *s);
 int  rlwthread_sleep(long msec);
 void rlsleep(long msec);
 //#ifdef __cplusplus
 //};
 //#endif
 
 #endif
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "serialcomform.h"
#include "rlserial.h"
#include "rldefine.h"
#include "rlthread.h"
#include "rlwthread.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmSerialPort *frmSerialPort;
//---------------------------------------------------------------------------
__fastcall TfrmSerialPort::TfrmSerialPort(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TfrmSerialPort::FormDestroy(TObject *Sender)
{
	delete mySerial3, mySerial4;
}
//---------------------------------------------------------------------------

void __fastcall TfrmSerialPort::btnsend2COM4Click(TObject *Sender)
{
	// mySerial3->writeChar((char)edCOM4->Lines->Text.c_str());

	// Assign the pointers to their respective buffers.
	// ptr_buf_COM3_Out = buf_COM3_Out;
	// ptr_buf_COM4_In = buf_COM4_In;

	//*ptr_buf_COM3_Out = (char)edCOM3Out->Lines->Text.c_str();
	// ptr_buf_COM4_In  = ptr_buf_COM3_Out; //This code only simulates the ports channels in a situation where they were on different computers.


	// COM3 writes to COM4's ptr_buf_COM4_In.
	*ptr_buf_COM4_In  = (unsigned char)edCOM3Out->Lines->Text.c_str();

	int buf_COM4_In_byte_size = sizeof(*ptr_buf_COM4_In);

	//Write contents of COM4's buffer to edCOM4
	if (mySerial3->writeBlock((const unsigned char*)*ptr_buf_COM4_In, buf_COM4_In_byte_size) != 1)
	{
	  //Clear edCOM3Out of it's contents (text) after it has sent it's contents to COM4.
	  edCOM3Out->Lines->Text = ' ';
	}



}
//---------------------------------------------------------------------------

void __fastcall TfrmSerialPort::Timer1Timer(TObject *Sender)
{
	// Declaration of the TimeOut Duration (constants).
	const unsigned int COMTimeOut = 500;


  if (mySerial3->readLine(buf_COM3_In, MAXLENGTH, COMTimeOut) != -1)
  {
	edCOM3In->Lines->Text = (String) *ptr_buf_COM3_In;
	edCOM3In->Lines->Add("\n");
  }

  if (mySerial4->readLine(buf_COM4_In, MAXLENGTH, COMTimeOut) != -1)
  {
	edCOM4In->Lines->Add(*ptr_buf_COM4_In);
	edCOM4In->Lines->Add("\n");
  }
}
//---------------------------------------------------------------------------

void __fastcall TfrmSerialPort::FormCreate(TObject *Sender)
{
   int com3_status, com4_status;
   mySerial3 = new rlSerial();
   com3_status = mySerial3->openDevice("COM3", 9600, 1, 1, 8, 1, 0);
   if ( com3_status == 0)
   { this->lblCOM3_Status->Caption = "COM3: Opening operation successful.";}
   else
   { this->lblCOM3_Status->Caption = "COM3: Opening operation failed!";}

   mySerial4 = new rlSerial();
   com4_status = mySerial4->openDevice("COM4", 9600, 1, 1, 8, 1, 0);
   if ( com4_status == 0)
   { this->lblCOM4_Status->Caption = "COM4: Opening operation successful.";}
   else
   { this->lblCOM4_Status->Caption = "COM4: Opening operation failed!";}

   // Assign the pointers to their respective buffers.
   ptr_buf_COM4_In = buf_COM4_In;
   ptr_buf_COM3_In = buf_COM3_In;
}
//---------------------------------------------------------------------------






void __fastcall TfrmSerialPort::btnSend2COM3Click(TObject *Sender)
{
	// Assign the pointers to their respective buffers.
	//ptr_buf_COM4_Out = buf_COM4_Out;
	//ptr_buf_COM3_In = buf_COM3_In;

	//*ptr_buf_COM4_Out = (char)edCOM4Out->Lines->Text.c_str();
	//ptr_buf_COM3_In  = ptr_buf_COM4_Out; //This code only simulates the ports' channels exchange between two computers.

	// COM4 writes to COM3's ptr_buf_COM3_In.
	// int buf_COM3_In_byte_size = sizeof(*ptr_buf_COM3_In);
	// mySerial4->writeBlock(ptr_buf_COM3_In, buf_COM3_In_byte_size);

	*ptr_buf_COM3_In  = (unsigned char)edCOM4Out->Lines->Text.c_str();

	int buf_COM3_In_byte_size = sizeof(*ptr_buf_COM3_In);

	//Write contents of COM3's buffer to edCOM3In
	if (mySerial4->writeBlock((const unsigned char*)*ptr_buf_COM3_In, buf_COM3_In_byte_size) != 1)
	{
	  //Clear edCOM4Out of it's text after it has sent it's contents to COM3.
	  edCOM4Out->Lines->Text = ' ';
	}




}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

#ifndef serialcomformH
#define serialcomformH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include "rlserial.h"
#include "rldefine.h"
#include "rlthread.h"
#include "rlwthread.h"
#include <ExtCtrls.hpp>
#define MAXLENGTH 512
//---------------------------------------------------------------------------
class TfrmSerialPort : public TForm
{
__published:	// IDE-managed Components
	TButton *btnsend2COM4;
	TButton *btnSend2COM3;
	TTimer *Timer1;
	TLabel *lblCOM3;
	TLabel *lblCOM4;
	TRichEdit *edCOM3In;
	TRichEdit *edCOM3Out;
	TRichEdit *edCOM4In;
	TRichEdit *edCOM4Out;
	TLabel *lblCOM3In;
	TLabel *lblCOM3Out;
	TLabel *lblCOM4In;
	TLabel *lblCOM4Out;
	TLabel *lblCOM3_Status;
	TLabel *lblCOM4_Status;
	void __fastcall FormDestroy(TObject *Sender);
	void __fastcall btnsend2COM4Click(TObject *Sender);
	void __fastcall Timer1Timer(TObject *Sender);
	void __fastcall FormCreate(TObject *Sender);
	void __fastcall btnSend2COM3Click(TObject *Sender);
private:	// User declarations

	// Instances of Serial Ports (COM3 & COM4)
	rlSerial  *mySerial3, *mySerial4;

	// Arrays are used as original In & Out Buffers for COM3 & COM4
	// so that enough memory can be allocated to the buffers.
	unsigned char buf_COM3_In[MAXLENGTH], buf_COM4_In[MAXLENGTH];
	//unsigned char buf_COM3_Out[MAXLENGTH], buf_COM4_Out[MAXLENGTH];

	// Pointers for the buffers - Character arrays cannot be assigned to at run-time
	// except for the use of the strcpy function.
	//unsigned char  *ptr_buf_COM3_Out, *ptr_buf_COM4_Out;
	unsigned char *ptr_buf_COM3_In, *ptr_buf_COM4_In;
	
public:		// User declarations
	__fastcall TfrmSerialPort(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfrmSerialPort *frmSerialPort;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("serialcomform.cpp", frmSerialPort);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	try
	{
		Application->Initialize();
		Application->CreateForm(__classid(TfrmSerialPort), &frmSerialPort);
		Application->Run();
	}
	catch (Exception &exception)
	{
		Application->ShowException(&exception);
	}
	catch (...)
	{
		try
		{
			throw Exception("");
		}
		catch (Exception &exception)
		{
			Application->ShowException(&exception);
		}
	}
	return 0;
}
//---------------------------------------------------------------------------

>>NB: I'm sorry if I haven't followed all the forum's posting rules. It's my first time and I've done it to the best of my understanding

You did ok -- at least you tried which is more than many do. :)

I'm not able to help you out because I don't have that compiler.

This article has been dead for over six months. Start a new discussion instead.