User`s manual
ThinkCore DA-660 WinCE User’s Manual Programming Examples
5-6
y In the Solution Explorer View, add mxdevice.dll to the reference section.
y Click OK
Example #1—MOXA UART Supports RS-232/422/485
The following C# code shows a sample application on operating a serial port. It provides methods
to switch the operation mode of the port among RS-232, RS-422 and RS-485 modes. In addition, it
uses an event based method to handle data reception.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
using System.IO.Ports;
namespace MxSerialPort
{
class MxComPortConfig
{
[DllImport("coredll.dll", EntryPoint = "CreateFileW", SetLastError = true)]
private static extern IntPtr CECreateFileW(string lpFileName, UInt32
dwDesiredAccess, UInt32 dwShareMode, IntPtr lpSecurityAttributes, UInt32
dwCreationDisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("coredll.dll", EntryPoint = "CloseHandle", SetLastError = true)]
private static extern Int32 CECloseHandle(IntPtr hObject);
[DllImport("coredll.dll", EntryPoint = "Sleep", SetLastError = true)]
private static extern void CESleep(UInt32 dwMilliseconds);
[DllImport("coredll.dll", EntryPoint = "DeviceIoControl", SetLastError = true)]
public static extern bool DeviceIoControl(
IntPtr hDevice,
uint dwIoControlCode,