Hi all!i need help...i have a write function and read function to write and read through RS-232 to another pc.This source code i put it inside a class.I have a main and want to call this function out.How am i going to call this function.Thanks!
/*-- Function Read --*/
/*-- For receiving of data from other parties --*/
public byte[] Read(int NumBytes)
{
byte[] BufBytes; //------Declaring of dynamic Array
byte[] OutBytes; //------Declaring of dynamic Array
BufBytes =
new byte[NumBytes]; //------Setting the Array Size to NumBytes( From parameter )
/*-- Check Port is Open --*/
if( hComm != INVALID_HANDLE_VALUE )
{
OVERLAPPED ovlCommPort =
new OVERLAPPED(); //------Declaring of ovlCommport
int BytesRead = 0; //------Declaring of BytesRead and set to 0
ReadFile(hComm,BufBytes,NumBytes,
ref BytesRead,ref ovlCommPort); //------Get data from RS232
OutBytes =
new byte[BytesRead]; //------Setting the size of Array to BytesRead
Array.Copy(BufBytes,OutBytes,BytesRead);
//------Copy previous array data to new array data for preventing data loss
return OutBytes; //------Return the GET data
}
/*-- End of Check Port is Open --*/
return null; //------Return null( nothing )
}
/*-- End of Function Read --*/
/*-- Function Write --*/
/*-- For transfering of data from other parties --*/
public void Write(byte[] WriteBytes)
{
/*-- Check Port is Open --*/
if( hComm != INVALID_HANDLE_VALUE )
{
OVERLAPPED ovlCommPort =
new OVERLAPPED(); //------Declaring of ovlCommport
int BytesWritten = 0; //------Declaring of BytesWritten and set to 0
WriteFile(hComm,WriteBytes,WriteBytes.Length,
ref BytesWritten,ref ovlCommPort); //------Transfer data to RS232
}/*-- End of Check Port is Open --*/
}
/*-- End of Function Write --*/