Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

MODBUS TCP/IP and WHILE function


fpborges Jan 28, 2014 01:26 PM

Hello,

I'm using a CR1000 as a slave device to transmit data via MODBUS TCP/IP through a NL240 Network Link, connected to the datalogger's CS I/O port in brigde mode.

We've been monitoring the IP signal from a DOS terminal using the "ping" command. I've noticed that when I use a While...Wend function on my CRBasic program to verify any bytes arriving on the SDM-SIO1 serial port, inside the main Scan...NextScan, we loose the IP connection.

When we comment this function inside the main Scan...NextScan, thus, allowing the SDM-SIO1 buffer to overflow, we don't loose the IP connection.

Is this a timeout issue or we can't use the While...Wend condition when the MODBUS TCP/IP protocol is on?

I've been doing this tests using the example from the ModbusSlave() function help window:

Public PTemp, batt_volt, Counter, I
Public horario(9)
Public Port(8) As Boolean
Public ModIn(10)
Public buffer As Long
Const serialport = 32
'Main Program
BeginProg
SerialOpen (Com3,9600,19,0,3000)
ModBusSlave (502,115200,1,ModIn(),Port(),0)
SerialOpen (serialport,9600,19,0,5000)
SerialFlush(serialport)
Scan (10,Min,0,0)
RealTime(horario())
PanelTemp (PTemp,250)
Battery (batt_volt)
Counter=Counter+1

'Coleta dos dados do AWAC
buffer = 0
buffer = SerialInChk (serialport)
While buffer = 0
buffer = SerialInChk (serialport)
Wend

ModIn(1) = horario(1) 'year
ModIn(2) = horario(2) 'month
ModIn(3) = horario(3) 'day
ModIn(4) = horario(4) 'hour
ModIn(5) = horario(5) 'minutes
ModIn(6) = horario(6) 'seconds
ModIn(7) = Counter
ModIn(8) = batt_volt
ModIn(9) = PTemp
' PortSet (1,Port(1))
' PortSet (2,Port(2))
' PortSet (3,Port(3))
' PortSet (4,Port(4))
serialflush(serialport)
NextScan
EndProg

* Last updated by: fpborges on 1/28/2014 @ 6:31 AM *


jtrauntvein Jan 29, 2014 07:48 PM

I believe that you may be misunderstanding how to read the serial port. According to the CRBasic help, SerialInChk() is used to return the number of bytes waiting to be read by SerialIn() or SerialInBlock(). Given that your program is not flushing the serial port within the scan and it is not actually reading any data from the serial port, I believe that it will get stuck in the scan as long as SerialInChk() returns a value greater than zero.

Log in or register to post/reply in the forum.