Moxa DA-683-DPP-T-W7E [31/35] Sin _gettchar n _tstoi sin do switch n if char 1 display the di do status case 1 open device hdiodev mxdgio_open for inti 0 i di_port_number i get digital input port_no i ndata mxdgio_get_input_signal hdiodev port_no _tprintf _t di d d r n port_no ndata

Moxa DA-683-DPP-T-W7E [31/35] Sin _gettchar n _tstoi sin do switch n if char 1 display the di do status case 1 open device hdiodev mxdgio_open for inti 0 i di_port_number i get digital input port_no i ndata mxdgio_get_input_signal hdiodev port_no _tprintf _t di d d r n port_no ndata
Sample Code for Digital I/O Control
Below we reproduce the LED control code. This is a simple function that
u
u
s
s
e
e
r
r
s
s
m
m
a
a
y
y
f
f
r
r
e
e
e
e
l
l
y
y
m
m
o
o
d
d
i
i
f
f
y
y
t
t
o
o
s
s
u
u
i
i
t
t
t
t
h
h
e
e
i
i
r
r
n
n
e
e
e
e
d
d
s
s
.
.
/* Copyright (C) MOXA Inc. All rights reserved.
This software is distributed under the terms of the
MOXA License. See the file COPYING-MOXA for details.
*/
#include "stdafx.h"
#include <windows.h>
#include "..\\Include\\mxdev.h"
#define DI_PORT_NUMBER 4
#define DO_PORT_NUMBER 4
int _tmain(intargc, _TCHAR* argv[])
{
HANDLE hDioDev;
intport_no;
int data;
intnData = 0;
intnRet = 0;
int port = 0;
int mode = 0;
int n = 0;
TCHAR sin;
TCHAR smode;
_tprintf(_T("DIO Test Program\r\n"));
_tprintf(_T("\t (0) Exit Program\r\n"));
_tprintf(_T("\t (1) Display DO & DI\r\n"));
_tprintf(_T("\t (2) Set DO value\r\n"));
sin = _gettchar();
n = _tstoi(&sin);
do
{
switch (n)
{
// if char == '1', display the DI/DO status
case 1:
// Open device
hDioDev = mxdgio_open();
for (inti = 0; i< DI_PORT_NUMBER; i++)
{
// Get digital input
port_no = i;
nData = mxdgio_get_input_signal( hDioDev, port_no);
_tprintf(_T("DI[%d] = %d\r\n"), port_no, nData);
}

Содержание

Похожие устройства

Скачать