daikeechi

hello guys ..

i need to communicate two PCs using serial communication ( connect via serial null modem cable ).. i managed to write and sent data to serial port but how to write loops to read data from serial port i'm using visual c++ 2005 express editon and my OS is windows XP.. below is my code .. can anyone help me


#pragma endregion

public: System::Void button1_Click(System:Surprisebject^ sender, System::EventArgs^ e) {

String^ msg;
msg = textBox2->Text;
textBox1->Text = textBox1->Text + "PC 1 : " + msg + Char(13) + Char(10);

serialport1->Write( msg + Char(13) + Char(10));
textBox2->Text = "";
}

private: System::Void Form1_Load(System:Surprisebject^ sender, System::EventArgs^ e) {
serialport1->Open();
}

private: System::Void Form1_FormClosed(System:Surprisebject^ sender, System::Windows::Forms::FormClosedEventArgs^ e) {
serialport1->Close();
}

private: System::Void serialport1_DataReceived(System:Surprisebject^ sender, System::IO:Stick out tongueorts:Tongue TiederialDataReceivedEventArgs^ e) {


int reg1;
String^ reg2;


do {
reg1 = serialport1->ReadChar();
reg2 = reg2 + Char(reg1);
} while (reg1 != 13);

textBox1->Text = textBox1->Text + "PC 2 : " + reg2 + Char(13) + Char(10);

}



Re: Visual C++ Express Edition Read data from serial port .. ?

Resander

You can use the Windows API.


static HANDLE hsio ;
static OVERLAPPED oswr ;
static OVERLAPPED osrd ;

static bool cancelling ;
static TCHAR * comportlkup [ MAXNUMPORTS ]
=
{
TEXT("COM1") , TEXT("COM2") , TEXT("COM3") , TEXT("COM4")
} ;


init with this:

void initsio ( int portix )
{
cancelling = false ;
readsioinprogress = false ;
writesioinprogress = false ;
curlbportix = portix ;
hsio = openport ( curlbportix ) ;

oswr.Offset = 0 ;
oswr.OffsetHigh = 0 ;
oswr.hEvent = NULL ;

osrd.Offset = 0 ;
osrd.OffsetHigh = 0 ;
osrd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
}

Open with this:

static HANDLE openport ( int portix )
{
HANDLE hsio = CreateFile ( comportlkup [ portix ] ,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_OVERLAPPED ,
0 ) ;
etc etc error handling
return hsio ;
}

write with this:

bool writesio ( int nbytes , unsigned char buf [ ] , int * errcoderet ,
int * lasterrorret )
{
bool ok = false ;
*errcoderet = NO_ERR ;
*lasterrorret = 0 ;
unsigned long nwritten ;
if ( !WriteFile ( hsio , buf , nbytes , &nwritten , &oswr ) )
{
int dw = GetLastError() ;
if ( dw == ERROR_IO_PENDING )
{
// write is delayed
writesioinprogress = true ;
}
else
{
// writefile failed, but it isn't delayed
*errcoderet = WRITE_ERR ;
*lasterrorret = dw ;
writesioinprogress = false ;
}
}
else // writefile returned immediately
{
if ( nwritten == (unsigned int)nbytes )
{
ok = true ;
}
else
{
*errcoderet = NWRITTENBAD_ERR ;
} ;
writesioinprogress = false ;
} ;
return ok ;
}

and read with this:

bool readsio ( int nbytes , unsigned char buf [ ] , int * errcoderet ,
int * lasterrorret , int tmovalms )
{
if ( readsioinprogress )
{
readsioinprogress = false ;
//CancelIo ( hsio ) ;
} ;
bool ok = false ;
*errcoderet = NO_ERR ;
*lasterrorret = 0 ;
cancelling = false ;
unsigned long n ;
unsigned long nread ;
if ( !ReadFile ( hsio , buf, nbytes , &nread , &osrd ) )
{
int dw = GetLastError() ;
if ( dw == ERROR_IO_PENDING) // read delayed
{
readsioinprogress = true ;
dw = WaitForSingleObject ( osrd.hEvent , tmovalms ) ;
if ( dw == WAIT_OBJECT_0 )
{
if ( !cancelling )
{
GetOverlappedResult ( hsio , &osrd , &n , FALSE ) ;
if ( n == (unsigned int)nbytes )
{
ok = true ;
}
else
{
*errcoderet = NREADBAD_ERR ;
} ;
}
else
{
//CancelIo ( hsio ) ;
*errcoderet = NREADCANCEL_ERR ;
} ;
}
else if ( dw == WAIT_TIMEOUT )
{
*errcoderet = READTMO_ERR ;
} ;
readsioinprogress = false ;
}
else
{
*errcoderet = READ_ERR ;
*lasterrorret = dw ;
}
}
else // read completed immediately
{
// ok
if ( nread == (unsigned int)nbytes )
{
ok = true ;
}
else
{
*errcoderet = NREADBAD_ERR ;
} ;
}
return ok ;
}

Ken





Re: Visual C++ Express Edition Read data from serial port .. ?

daikeechi

hello there..

i don't know how to reconsruct with your given code.. just copy paste and rebuild the solution.. got too many errors.. i don't know how to get the data from serial port and display in my textBox1 windows..

with my previous code what i did was when the software is load the program automatically open the serial port ( which i used the Form1_Load function ) and when the software is close the program automatically close the serial port ( which i used the Form1_FormClosed )..

so what left is just to perform write and read function .. i try to perform write function after the send button is press.. the msg type in the textBox2 then will be display in textBox1 after the send button is press .. i make my serial port loopback by connect the transmit and receive pin to test my code.. then after write function i perform read function to read from serial port.. with loopback connector the program is ok and run successful but when i try to connect two pcs.. there is a little bit problem with the read function.. both computers can transmit the data but only can read data from serial port if both computers press the send button together .. i don't know how to perform read function run in the background so the data available will automatically display in textBox1 .. your recommendation and advise is highly appreciated ..

#pragma once


namespace pc2pc {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:Big Smileata;
using namespace System:Big Smilerawing;


/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();

static HANDLE hsio ;
static OVERLAPPED oswr ;
static OVERLAPPED osrd ;

static bool cancelling ;
static TCHAR * comportlkup [ MAXNUMPORTS ] =
{
TEXT("COM1") , TEXT("COM2") , TEXT("COM3") , TEXT("COM4")
} ;


void initsio ( int portix )
{
cancelling = false ;
readsioinprogress = false ;
writesioinprogress = false ;
curlbportix = portix ;
hsio = openport ( curlbportix ) ;

oswr.Offset = 0 ;
oswr.OffsetHigh = 0 ;
oswr.hEvent = NULL ;

osrd.Offset = 0 ;
osrd.OffsetHigh = 0 ;
osrd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
}


//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TabControl^ tabControl1;
protected:

private: System::Windows::Forms::TabPage^ tabPage2;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::IO:Stick out tongueorts:Tongue TiederialPort^ serialport1;

public:

private:


private: System::ComponentModel::IContainer^ components;

private:
/// <summary>
/// Required designer variable.
/// </summary>


#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->serialport1 = (gcnew System::IO:Stick out tongueorts:Tongue TiederialPort(this->components));
this->tabControl1->SuspendLayout();
this->tabPage2->SuspendLayout();
this->SuspendLayout();
//
// tabControl1
//
this->tabControl1->Controls->Add(this->tabPage2);
this->tabControl1->Location = System:Big Smilerawing:Stick out tongueoint(56, 33);
this->tabControl1->Name = L"tabControl1";
this->tabControl1->SelectedIndex = 0;
this->tabControl1->Size = System:Big Smilerawing:Tongue Tiedize(681, 340);
this->tabControl1->TabIndex = 0;
//
// tabPage2
//
this->tabPage2->Controls->Add(this->button1);
this->tabPage2->Controls->Add(this->textBox2);
this->tabPage2->Controls->Add(this->textBox1);
this->tabPage2->Location = System:Big Smilerawing:Stick out tongueoint(4, 22);
this->tabPage2->Name = L"tabPage2";
this->tabPage2->Padding = System::Windows::Forms:Stick out tongueadding(3);
this->tabPage2->Size = System:Big Smilerawing:Tongue Tiedize(673, 314);
this->tabPage2->TabIndex = 1;
this->tabPage2->Text = L"Chat";
this->tabPage2->UseVisualStyleBackColor = true;
//
// button1
//
this->button1->Location = System:Big Smilerawing:Stick out tongueoint(467, 169);
this->button1->Name = L"button1";
this->button1->Size = System:Big Smilerawing:Tongue Tiedize(75, 23);
this->button1->TabIndex = 2;
this->button1->Text = L"Send";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// textBox2
//
this->textBox2->Location = System:Big Smilerawing:Stick out tongueoint(125, 169);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System:Big Smilerawing:Tongue Tiedize(316, 20);
this->textBox2->TabIndex = 1;
//
// textBox1
//
this->textBox1->Location = System:Big Smilerawing:Stick out tongueoint(125, 34);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->ScrollBars = System::Windows::Forms:Tongue TiedcrollBars::Vertical;
this->textBox1->Size = System:Big Smilerawing:Tongue Tiedize(403, 109);
this->textBox1->TabIndex = 0;
//
// serialport1
//
this->serialport1->DtrEnable = true;
this->serialport1->PortName = L"COM1";
this->serialport1->RtsEnable = true;
this->serialport1->DataReceived += gcnew System::IO:Stick out tongueorts:Tongue TiederialDataReceivedEventHandler(this, &Form1:Tongue Tiederialport1_DataReceived);
//
// Form1
//
this->AutoScaleDimensions = System:Big Smilerawing:Tongue TiedizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System:Big Smilerawing:Tongue Tiedize(764, 385);
this->Controls->Add(this->tabControl1);
this->Name = L"Form1";
this->Text = L"Form1";
this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &Form1::Form1_FormClosed);
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->tabControl1->ResumeLayout(false);
this->tabPage2->ResumeLayout(false);
this->tabPage2->PerformLayout();
this->ResumeLayout(false);

}
#pragma endregion
public: System::Void button1_Click(System:Surprisebject^ sender, System::EventArgs^ e) {
String^ msg;
msg = textBox2->Text;
textBox1->Text = textBox1->Text + "PC 1 : " + msg + Char(13) + Char(10);

bool writesio ( int nbytes , unsigned char buf [ ] , int * errcoderet ,
int * lasterrorret )
{
bool ok = false ;
*errcoderet = NO_ERR ;
*lasterrorret = 0 ;
unsigned long nwritten ;
if ( !WriteFile ( hsio , buf , nbytes , &nwritten , &oswr ) )
{
int dw = GetLastError() ;
if ( dw == ERROR_IO_PENDING )
{
// write is delayed
writesioinprogress = true ;
}
else
{
// writefile failed, but it isn't delayed
*errcoderet = WRITE_ERR ;
*lasterrorret = dw ;
writesioinprogress = false ;
}
}
else // writefile returned immediately
{
if ( nwritten == (unsigned int)nbytes )
{
ok = true ;
}
else
{
*errcoderet = NWRITTENBAD_ERR ;
} ;
writesioinprogress = false ;
} ;
return ok ;
}
serialport1->Write( msg + Char(13) + Char(10));
textBox2->Text = "";

}
private: System::Void Form1_Load(System:Surprisebject^ sender, System::EventArgs^ e) {



static HANDLE openport ( int portix )
{
HANDLE hsio = CreateFile ( comportlkup [ portix ] ,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_OVERLAPPED ,
0 ) ;
etc etc error handling
return hsio ;
}

}

private: System::Void Form1_FormClosed(System:Surprisebject^ sender, System::Windows::Forms::FormClosedEventArgs^ e) {
serialport1->Close();


}

private: System::Void serialport1_DataReceived(System:Surprisebject^ sender, System::IO:Stick out tongueorts:Tongue TiederialDataReceivedEventArgs^ e) {


bool readsio ( int nbytes , unsigned char buf [ ] , int * errcoderet ,
int * lasterrorret , int tmovalms )
{
if ( readsioinprogress )
{
readsioinprogress = false ;
//CancelIo ( hsio ) ;
} ;
bool ok = false ;
*errcoderet = NO_ERR ;
*lasterrorret = 0 ;
cancelling = false ;
unsigned long n ;
unsigned long nread ;
if ( !ReadFile ( hsio , buf, nbytes , &nread , &osrd ) )
{
int dw = GetLastError() ;
if ( dw == ERROR_IO_PENDING) // read delayed
{
readsioinprogress = true ;
dw = WaitForSingleObject ( osrd.hEvent , tmovalms ) ;
if ( dw == WAIT_OBJECT_0 )
{
if ( !cancelling )
{
GetOverlappedResult ( hsio , &osrd , &n , FALSE ) ;
if ( n == (unsigned int)nbytes )
{
ok = true ;
}
else
{
*errcoderet = NREADBAD_ERR ;
} ;
}
else
{
//CancelIo ( hsio ) ;
*errcoderet = NREADCANCEL_ERR ;
} ;
}
else if ( dw == WAIT_TIMEOUT )
{
*errcoderet = READTMO_ERR ;
} ;
readsioinprogress = false ;
}
else
{
*errcoderet = READ_ERR ;
*lasterrorret = dw ;
}
}
else // read completed immediately
{
// ok
if ( nread == (unsigned int)nbytes )
{
ok = true ;
}
else
{
*errcoderet = NREADBAD_ERR ;
} ;
}
return ok ;
}
int reg1;
String^ reg2;


do {
reg1 = serialport1->ReadChar();
reg2 = reg2 + Char(reg1);
} while (reg1 != 13);

textBox1->Text = textBox1->Text + "PC 2 : " + reg2 + Char(13) + Char(10);

}
};
}



and the error i got ..

------ Build started: Project: pc2pc, Configuration: Debug Win32 ------
Compiling...
pc2pc.cpp
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(30) : error C2146: syntax error : missing ';' before identifier 'hsio'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(30) : error C2065: 'hsio' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(31) : error C2146: syntax error : missing ';' before identifier 'oswr'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(31) : error C2065: 'oswr' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(32) : error C2146: syntax error : missing ';' before identifier 'osrd'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(32) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(32) : error C2086: 'int OVERLAPPED' : redefinition
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(31) : see declaration of 'OVERLAPPED'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(32) : error C2065: 'osrd' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(35) : error C2143: syntax error : missing ';' before '*'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(35) : error C2065: 'comportlkup' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(35) : error C2065: 'MAXNUMPORTS' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(36) : error C2059: syntax error : '{'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(36) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(38) : error C2143: syntax error : missing ';' before '}'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(37) : error C3861: 'TEXT': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(37) : error C3861: 'TEXT': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(37) : error C3861: 'TEXT': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(37) : error C3861: 'TEXT': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(42) : error C2601: 'initsio' : local function definitions are illegal
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(194) : error C2601: 'writesio' : local function definitions are illegal
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(237) : error C2146: syntax error : missing ';' before identifier 'openport'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(237) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(237) : error C2144: syntax error : 'int' should be preceded by ')'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(237) : error C2059: syntax error : ')'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(238) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(239) : error C2146: syntax error : missing ';' before identifier 'hsio'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(237) : error C3861: 'openport': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(239) : error C2065: 'portix' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(240) : error C2065: 'GENERIC_READ' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(240) : error C2065: 'GENERIC_WRITE' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(243) : error C2065: 'OPEN_EXISTING' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(244) : error C2065: 'FILE_ATTRIBUTE_NORMAL' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(245) : error C2065: 'FILE_FLAG_OVERLAPPED' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(239) : error C3861: 'CreateFile': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(247) : error C2065: 'etc' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(247) : error C2146: syntax error : missing ';' before identifier 'etc'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(247) : error C2146: syntax error : missing ';' before identifier 'error'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(248) : error C2065: 'error' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(248) : error C2146: syntax error : missing ';' before identifier 'handling'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(248) : error C2065: 'handling' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(248) : error C2143: syntax error : missing ';' before 'return'
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(264) : error C2601: 'readsio' : local function definitions are illegal
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(43) : error C2065: 'cancelling' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(44) : error C2065: 'readsioinprogress' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(45) : error C2065: 'writesioinprogress' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(46) : error C2065: 'curlbportix' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(47) : error C3861: 'openport': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(49) : error C2228: left of '.Offset' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(50) : error C2228: left of '.OffsetHigh' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(51) : error C2228: left of '.hEvent' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(51) : error C2065: 'NULL' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(53) : error C2228: left of '.Offset' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(54) : error C2228: left of '.OffsetHigh' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(55) : error C2228: left of '.hEvent' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(55) : error C2065: 'TRUE' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(55) : error C2065: 'FALSE' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(55) : error C3861: 'CreateEvent': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(196) : error C2065: 'NO_ERR' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(199) : error C3861: 'WriteFile': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(201) : error C3861: 'GetLastError': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(202) : error C2065: 'ERROR_IO_PENDING' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(210) : error C2065: 'WRITE_ERR' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(223) : error C2065: 'NWRITTENBAD_ERR' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(276) : error C3861: 'ReadFile': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(278) : error C3861: 'GetLastError': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(282) : error C2228: left of '.hEvent' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(282) : error C3861: 'WaitForSingleObject': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(283) : error C2065: 'WAIT_OBJECT_0' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(287) : error C3861: 'GetOverlappedResult': identifier not found
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(294) : error C2065: 'NREADBAD_ERR' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(300) : error C2065: 'NREADCANCEL_ERR' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(303) : error C2065: 'WAIT_TIMEOUT' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(305) : error C2065: 'READTMO_ERR' : undeclared identifier
c:\documents and settings\apiz torres\my documents\visual studio 2005\projects\pc2pc\pc2pc\Form1.h(311) : error C2065: 'READ_ERR' : undeclared identifier
Build log was saved at "file://c:\Documents and Settings\Apiz Torres\My Documents\Visual Studio 2005\Projects\pc2pc\pc2pc\Debug\BuildLog.htm"
pc2pc - 77 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========





Re: Visual C++ Express Edition Read data from serial port .. ?

Resander

In order to use the Windows API you first need to download and install the Windows Platform SDK and then adjust compiler settings as described in Getting Started. You would get the first error message if the compiler does not recognize HANDLE, which is a Windows API datatype.


Once the Windows API is in place, I would first get the serial IO working and then and only then add the GUI.

For the IO test I would make two Console applications, one that writes and another that reads.

Writer:

void main ( )
{
initsio ( 0 ) ;
unsigned char * data = "abcd\r\n" ;
int nbytes = strlen ( data ) ;
int errcode ;
int lasterror ;
writesio ( nbytes , data , &errcode , &lasterror ) ;
// error checking is omitted
}


reader: (without error checking)

void main ( )
{
initsio ( 0 ) ;
int ndatabytes = 0 ;
char data [ 100 ] ;
int errcode ;
int lasterror ;
int timeout = 100000 ; // 100 seconds
while ( ndatabytes < 100 )
{
readsio ( 1 , data+ndatabytes , &errcode , &lasterror , timeout ) ;
if ( data [ ndatabytes ] == '\n' )
{
break ;
}
ndatabytes++ ;
}
}

First start the PC with the reader, then the PC with the writer.

When the serial IO is working you will need to define the data transmissions protocol. This may be very simple or quite hard depending on, for example, if the computers are equals and both need to be able to send or receive, or if one computer is Master and the other is a Slave, whether data is binary or text, whether data volumes are small or huge, whether the two computers need to send and receive at the same time etc.

You may also want to decouple the GUI from the data comms on each computer by making the GUI and data comms run as separate processes.This is easy to do with the Windows API, but I would not know if it is as easy with managed solutions in VC++ 2005.

Ken