Using the TCP Master code on a Fieldbus Accelerator with a Koyo Click, the following code throws a parsing error when processing the second request.
#require "ModbusRTU.class.nut:1.0.0"
#require "ModbusMaster.class.nut:1.0.0"
#require "ModbusTCPMaster.class.nut:1.0.0"
#require "W5500.device.nut:1.0.0"
FieldbusGateway_005 <- {
"LED_RED" : hardware.pinP,
"LED_GREEN" : hardware.pinT,
"LED_YELLOW" : hardware.pinQ,
"MIKROBUS_AN" : hardware.pinM,
"MIKROBUS_RESET" : hardware.pinH,
"MIKROBUS_SPI" : hardware.spiBCAD,
"MIKROBUS_PWM" : hardware.pinU,
"MIKROBUS_INT" : hardware.pinXD,
"MIKROBUS_UART" : hardware.uart1,
"MIKROBUS_I2C" : hardware.i2cJK,
"XBEE_RESET" : hardware.pinH,
"XBEE_AND_RS232_UART": hardware.uart0,
"XBEE_DTR_SLEEP" : hardware.pinXD,
"RS485_UART" : hardware.uart2,
"RS485_nRE" : hardware.pinL,
"WIZNET_SPI" : hardware.spi0,
"WIZNET_RESET" : hardware.pinXA,
"WIZNET_INT" : hardware.pinXC,
"USB_EN" : hardware.pinR,
"USB_LOAD_FLAG" : hardware.pinW
}
function writeCB(err, res) {
if (err) {
server.error(err);
} else {
if (typeof res == "array") {
foreach(item in res) {
server.log(item)
}
} else {
server.log(res);
}
}
}
local CONNECTION_SETTINGS_DEST_IP = "192.168.0.10";
local CONNECTION_SETTINGS_DEST_PORT = 502;
local NETWORK_SETTINGS_SOURCE_IP = "192.168.0.2";
local NETWORK_SETTINGS_SUBNET_MASK = "255.255.255.0";
local NETWORK_SETTINGS_GATEWAY_IP = "192.168.0.1";
FieldbusGateway_005.WIZNET_SPI.configure(CLOCK_IDLE_LOW | MSB_FIRST | USE_CS_L, 500);
local wiz = W5500(FieldbusGateway_005.WIZNET_INT, FieldbusGateway_005.WIZNET_SPI, null, FieldbusGateway_005.WIZNET_RESET);
wiz.configureNetworkSettings(NETWORK_SETTINGS_SOURCE_IP, NETWORK_SETTINGS_SUBNET_MASK, NETWORK_SETTINGS_GATEWAY_IP);
// Initialize Modbus
local modbus = ModbusTCPMaster(wiz);
// Open Connection
local connectionSettings = {"destIP" : CONNECTION_SETTINGS_DEST_IP, "destPort" : CONNECTION_SETTINGS_DEST_PORT};
modbus.connect(connectionSettings, function(err, conn) {
if (err) {
server.error (err);
} else {
modbus.write(MODBUSRTU_TARGET_TYPE.COIL, 8192, 1, true, writeCB);
modbus.write(MODBUSRTU_TARGET_TYPE.COIL, 8194, 1, true, writeCB);
}
})
2017-05-08 14:59:26 -07:00 [Status] Downloading new code; 27.01% program storage used
2017-05-08 14:59:33 -07:00 [Device] true
2017-05-08 14:59:33 -07:00 [Device] ERROR: Error parsing the response, transactionID 1 does not exist
2017-05-08 15:00:33 -07:00 [Device] true
2017-05-08 15:00:33 -07:00 [Device] ERROR: Error parsing the response, transactionID 3 does not exist
Using the TCP Master code on a Fieldbus Accelerator with a Koyo Click, the following code throws a parsing error when processing the second request.
logs:
2017-05-08 14:59:26 -07:00 [Status] Downloading new code; 27.01% program storage used
2017-05-08 14:59:33 -07:00 [Device] true
2017-05-08 14:59:33 -07:00 [Device] ERROR: Error parsing the response, transactionID 1 does not exist
2017-05-08 15:00:33 -07:00 [Device] true
2017-05-08 15:00:33 -07:00 [Device] ERROR: Error parsing the response, transactionID 3 does not exist