Hello
I’m trying to have my BL4S200 read a digital input, and have a Master device read the status of that input.
I’m using some of the code from the example" DIGIN.C" to printf the status of an input, so i know the board’s I/O is intialized and reading, but i can’t seem to read the status from the MODBUS device.
My code is as follows:
// The following three definitions are required for proper operation
// of the TCP/IP keepalive function. If they are not defined here
// default values will be used.
#define INACTIVE_PERIOD 5 // period of inactivity, in seconds, before sending a
// keepalive, or 0 to turn off keepalives.
#define KEEPALIVE_WAITTIME 3 // number of seconds to wait between keepalives,
// after the 1st keepalive was sent
#define KEEPALIVE_NUMRETRYS 3 // number of retrys
#define TCPCONFIG 0
#define USE_ETHERNET 1
// set up my IP addresses
#define IFCONFIG_ETH0 \
IFS_IPADDR,aton("192.168.0.253"), \
IFS_ROUTER_SET, aton("192.168.0.1"), \
IFS_NETMASK,aton("255.255.255.0"), \
IFS_UP
#use dcrtcp.lib
#define MY_MODBUS_ADDRESS 1
#use BLxS2xx.lib
#use Modbus_Slave_TCP.Lib
#use Modbus_Slave.Lib
#use Modbus_Slave_BL4S200.Lib
#class auto
// set the STDIO cursor location and display a string
void DispStr(int x, int y, char *s)
{
x += 0x20;
y += 0x20;
printf ("\x1B=%c%c%s", x, y, s);
}
// update digital inputs for the given channel range
void update_input(int start_channel, int end_channel, int col, int row)
{
char *ptr;
char display[80];
int reading;
int channel;
// display the input status for the given channel range
ptr = display; //initialize the string pointer
for (channel = start_channel; channel <= end_channel; ++channel)
{
reading = digIn(channel); //read channel
ptr += sprintf(ptr, "%d ", reading); //format reading in memory
}
DispStr(col, row, display); //update input status
}
///////////////////////////////////////////////////////////////////
void main ()
{
int channel;
// Initialize the Controller
brdInit();
// Set configurable I/O 0-15 to be general digital inputs
for(channel = 0; channel < 16; ++channel)
{
setDigIn(channel);
}
sock_init();
while (ifpending(IF_DEFAULT) == IF_COMING_UP) {
tcp_tick(NULL);
}
MODBUS_TCP_Init (1,502);
// Tick forever and respond to inputs.
//Display user instructions and channel headings
DispStr(8, 1, " <<< Configurable I/O set as inputs 00 - 15 >>>");
DispStr(8, 3, "DIN00 DIN01 DIN02 DIN03 DIN04 DIN05 DIN06 DIN07");
DispStr(8, 4, "----- ----- ----- ----- ----- ----- ----- -----");
for (;;)
{
MODBUS_TCP_tick();
// update input channels 0 - 7, located at col = 8 row = 5.
update_input(0, 7, 8, 5);
}
}
I have my MODBUS master set to read the Digital Coils ( 0 ) and Digital inputs ( 1 ), just to make sure i wasnt missing anything, but it seems like the data isnt being transmitted and i don’t know where to start debugging.
Also, where do i find out / set the baud rate?