2014-05-08 15:34:28 +02:00
|
|
|
/*@!Encoding:1252*/
|
|
|
|
|
|
|
|
includes
|
|
|
|
{
|
2014-05-09 15:39:16 +02:00
|
|
|
#include "ModbusTcpClientCommon.cin"
|
2014-05-08 15:34:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
variables
|
|
|
|
{
|
|
|
|
msTimer muster;
|
|
|
|
byte gX[2] = {1, 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get information of local network interface such like ip address
|
|
|
|
|
|
|
|
on preStart
|
|
|
|
{
|
|
|
|
writeClear(0);
|
|
|
|
setStartdelay(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
on start
|
|
|
|
{
|
|
|
|
long fehler;
|
|
|
|
|
|
|
|
ModbusInit("192.168.1.3", 502);
|
|
|
|
}
|
|
|
|
|
2014-05-12 10:46:53 +02:00
|
|
|
|
|
|
|
// Modbus events ----------------------------------------------------------------------
|
|
|
|
void OnModbusReadBitsFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusReadRegistersFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusWriteBitFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusWriteRegisterFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusWriteBitsFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusWriteRegistersFailed(enum ModbusRequestError error, enum ModbusException ex, struct ModbusApHeader mbap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnModbusReadBitsSuccess(byte result[])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusReadRegistersSuccess(byte result[])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusWriteBitSuccess(byte result[])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusWriteRegisterSuccess(byte result[])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusWriteBitsSuccess(byte result[])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void OnModbusWriteRegistersSuccess(byte result[])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Key events -------------------------------------------------------------------------
|
2014-05-08 16:07:38 +02:00
|
|
|
on key 'r'
|
|
|
|
{
|
|
|
|
ModbusReadBits(0, 512);
|
|
|
|
}
|
|
|
|
|
2014-05-08 15:34:28 +02:00
|
|
|
on key 'a'
|
|
|
|
{
|
|
|
|
byte x[16] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
|
|
|
|
ModbusWriteBitsB(0, 16, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
on key 's'
|
|
|
|
{
|
|
|
|
byte x[16] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
|
|
|
|
ModbusWriteBitsB(0, 16, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
on key 'Y'
|
|
|
|
{
|
|
|
|
ModbusWriteBit(0, 0);
|
|
|
|
}
|
|
|
|
on key 'y'
|
|
|
|
{
|
|
|
|
ModbusWriteBit(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
on key 'X'
|
|
|
|
{
|
|
|
|
ModbusWriteBit(1, 0);
|
|
|
|
}
|
|
|
|
on key 'x'
|
|
|
|
{
|
|
|
|
ModbusWriteBit(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
on key 'C'
|
|
|
|
{
|
|
|
|
ModbusWriteBit(2, 0);
|
|
|
|
}
|
|
|
|
on key 'c'
|
|
|
|
{
|
|
|
|
ModbusWriteBit(2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
on key 'V'
|
|
|
|
{
|
|
|
|
ModbusWriteBit(3, 0);
|
|
|
|
}
|
|
|
|
on key 'v'
|
|
|
|
{
|
|
|
|
ModbusWriteBit(3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
on key '+'
|
|
|
|
{
|
|
|
|
byte x[2] = {0xFF, 0xFF};
|
|
|
|
ModbusWriteBits(0, 16, x);
|
|
|
|
}
|
|
|
|
on key '-'
|
|
|
|
{
|
|
|
|
byte x[2] = {0x00, 0x00};
|
|
|
|
ModbusWriteBits(0, 16, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
on key 't'
|
|
|
|
{
|
2014-05-08 17:22:21 +02:00
|
|
|
setTimerCyclic(muster, 100);
|
2014-05-08 15:34:28 +02:00
|
|
|
}
|
|
|
|
on key 'T'
|
|
|
|
{
|
|
|
|
cancelTimer(muster);
|
|
|
|
}
|
|
|
|
|
|
|
|
on timer muster
|
|
|
|
{
|
2014-05-09 15:39:16 +02:00
|
|
|
if (gX[0] != 0)
|
2014-05-08 15:34:28 +02:00
|
|
|
{
|
|
|
|
if (gX[0] == 0x80)
|
|
|
|
{
|
|
|
|
gX[0] = 0x00;
|
|
|
|
gX[1] = 0x01;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gX[0] <<= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gX[1] == 0x80)
|
|
|
|
{
|
|
|
|
gX[0] = 0x01;
|
|
|
|
gX[1] = 0x00;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gX[1] <<= 1;
|
|
|
|
}
|
2014-05-09 15:39:16 +02:00
|
|
|
ModbusWriteBits(0, 16, gX);
|
|
|
|
//ModbusReadBits(0, 512);
|
2014-05-08 15:34:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|