Write Method

Writes specified number of bytes to serial port.

Syntax

Visual Basic .NET
Function Write(ByVal DataBuffer As System.IntPtr, ByVal BytesToWrite As UInt32) As UInt32 
Visual C#
UInt32 Write(IntPtr DataBuffer, UInt32 BytesToWrite);

Parameters

DataBuffer

[in] Buffer of characters to be written. Use type-casting to convert it from void* or char*.

BytesToWrite

[in] Number of bytes to write to serial port.

Return

Number of bytes written to serial port. It can write fewer bytes than requested; the return value must be noted, and the reminder of the operation should be retried when possible.

Errors

The method may throw exception. Refer to Handle errors sample for details.

Remarks

In Visual Basic use WriteArray.

Code Example

// using System.Runtime.InteropServices;

byte[] ReadBuffer = System.Text.Encoding.ASCII.GetBytes("Write Data");
IntPtr Ptr = Marshal.AllocHGlobal(ReadBuffer.GetLength(0));
Marshal.Copy(ReadBuffer, 0, Ptr, ReadBuffer.GetLength(0));

try
{
	ftspcControl1.Write(Ptr, (uint)ReadBuffer.GetLength(0));
}
catch (FTSPCException E)
{
	MessageBox.Show("Error " + E.ErrorCode.ToString() + "\r\n" + 
		E.ErrorSource, "Error", MessageBoxButtons.OK,
		MessageBoxIcon.Error);
}

See Also

WriteArray