User`s manual

ThinkCore DA-660 WinCE User’s Manual Programming Examples
5-5
Depending on the serial port to which a device connects, the target computer supports serial
communication in four operation modes: RS-232, RS-422, 2-wire RS-485, and 4-wire RS-485;
RS-232 is the default. To change the operation mode, your program should include the following
macro definitions; also insert the following DeviceIoControl function on the open handle before
the program performs read/write operations.
/* --------- extracted from <moxa/devices> -------------------
#define MOXA_SET_OP_MODE (0x400 + 66)
#define MOXA_GET_OP_MODE (0x400+ 67)
#define RS232_MODE 0
#define RS485_2WIRE_MODE 1
#define RS422_MODE 2
#define RS485_4WIRE_MODE 3
*/
/* for example, set the mode to 4-wire RS485 */
BYTE mode = RS485_4WIRE_MODE;
DeviceIoControl(hCom,MOXA_SET_OP_MODE, &mode, sizeof(mode), NULL,0,NULL,NULL);
/* for example, get the current mode */
BYTE mode, size;
DeviceIoControl(hCom,MOXA_GET_OP_MODE, NULL, 0, (LPVOID)&mode,
sizeof(mode),&size,NULL);
Example #2—Buzzer
The target computer supports buzzer hardware for your applications to generate alarms on critical
errors. You can set the frequency and the duration of the buzzer at the application level by using
the APIs as follows. For example, the code shown below triggers the buzzer for 2000 milliseconds
at frequency 500Hzs.
/* execute a beeper at a specified frequency for lasting a duration in miniseconds */
int mxbeep(unsigned int nHz, unsigned int nMiniSec);
#include <moxa/devices.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
mxbeep(500,2000);
return 0;
}
Visual Studio 2005 C# Examples
To simplify application development with the Visual Studio 2005 tool, we provide you with a
device .Net Compact Framework 2.0 class library (mxdevice.dll). To link the library with your
project environment, perform the following steps from your Visual Studio 2005 environment:
y Copy the mxdevice.dll from the CD to your local disk. (CD path:\utility\NetCF20Lib\)
y Open the visual studio 2005 IDE tool, and then add a new C# Smart device console
application.
y Input the project name and location path.