timeout occur when use ReadUntil


khuenguyen

Recommended Posts

Tx (12:09:06.314): AI2M113

Rx (12:09:06.330): AI2M1V0.00410

above is data display on monitor windows that I sent/received on COM port. When I sent, I use command

Device.COM1.Write("AI2M1" + Chr(13)), my circuit return one string with content: AI2M1V0.004. How I can receive it without error. I try use Device.COM1.ReadUntil(Chr(10)) but timeout occur.

Thanks.

Link to comment
Share on other sites

this is my code. Timeout occur at line " strDataIn = Device.COM1.ReadUntil(Chr(10))"

code:

While (1)

if (!Device.COM1.LockPort())

throw ("Port in use!")

endif

Device.COM1.Write("AI2M0" + Chr(13))

strDataIn = Device.COM1.ReadUntil(Chr(10)) // no timeout

delay(1)

variable1 = Mid(strDataIn,6,5)

MIO_VOLT.AddValue(variable1 * 65)

Device.COM1.Write("DI1M1" + Chr(13))

strDataIn = Device.COM1.ReadUntil(Chr(10)) //timeout occur

delay(2)

strDataPro = Mid(strDataIn,3,2)

if (!Compare(strDataPro,"S1"))

status1 = 1

Fire_Alarm.AddValue(status1)

else

status1 = 0

Fire_Alarm.AddValue(status1)

endif

if (status1)

Device.COM1.Write("DO1S1M1" + Chr(13))

else

Device.COM1.Write("DO1S0M1" + Chr(13))

endif

Device.COM1.UnlockPort()

delay(1)

endwhile

my circuit return data with end of line character is ascii 10.

Link to comment
Share on other sites

I'm not saying there is anything wrong with the hardware, I just can't tell you what is happening. You need to look at the comm monitor to determine why DAQFactory thinks there is no response. If you want, post a screen shot of the comm monitor. Make sure the Display Time of Tx/Rx is checked.

Link to comment
Share on other sites

this is time send/receive in monitor windows:

Tx: (08:55:26.321): AI2M013

Rx: (08:55:26.341): AI2M0V3.26710

Tx: (08:55:30.368): AI2M013

Rx: (08:55:30.388): AI2M0V3.26910

Tx: (08:55:34.415): AI2M013

Rx: (08:55:34.435): AI2M0V3.30010

Tx: (08:55:38.462): AI2M013

Rx: (08:55:38.482): AI2M0V3.30110

please check it for me.

Thanks.

Link to comment
Share on other sites

this is output of Monitor window:

Tx (14:11:54.218): AI2M013

Rx (14:11:54.238): AI2M0V3.27610

Tx (14:11:56.264): DI1M113

Tx (14:11:57.264): DO1S0M113

Tx (14:11:59.265): AI2M013

Rx (14:11:59.285): AI2M0V3.28610

Tx (14:12:01.311): DI1M113

Tx (14:12:02.311): DO1S0M113

Tx (14:12:04.312): AI2M013

Rx (14:12:04.332): AI2M0V3.26110

Tx (14:12:06.358): DI1M113

and this is my code, with COM1 is COM port with parameters: Baudrate: 9600, byte size: 8bits, stopbits: 1, parity: none

//ignore("all")
Private string strDataIn
Private string strDataIn1
Private string strDataPro1
Private string strDataPro2
global status1
global var0 = 1
global var1 = 0
global gStatus
global variable1

While (1)

   if (var0 == 1 & var1 == 0)
	  Device.COM1.Write("DI1M1" + Chr(13))
	  try
		 strDataIn = Device.COM1.ReadUntil(10)
		 strDataIn = ReadUntil(10)
	  catch()
		 break
	  endcatch
	  strDataPro1 = Mid(strDataIn,3,2)
	  if (!Compare(strDataPro1,"S1"))
		 status1 = 1
		 Fire_Alarm.AddValue(status1)
	  else
		 status1 = 0
		 Fire_Alarm.AddValue(status1)
	  endif

	  if (status1)
		 Device.COM1.Write("DO1S1M1" + Chr(13))
	  else
		 Device.COM1.Write("DO1S0M1" + Chr(13))
	  endif

	  var0 = 0
	  var1 = 0
	  delay(2)
   endif

   if (var0 == 0 & var1 == 1)
	  Device.COM1.Write("AI2M0" + Chr(13))
	  try
		 strDataIn1 = Device.COM1.ReadUntil(10)
	  catch()
		 break
	  endcatch
	  variable1 = Mid(strDataIn1,6,5)
	  MIO_VOLT.AddValue(variable1 * 65)

	  var0 = 1
	  var1 = 1
	  delay(2)
   endif

   if (var0 == 0 & var1 == 0)
	  var1 = 1
   endif

   if (var0 == 1 & var1 == 1)
	  var1 = 0
   endif

endwhile

Link to comment
Share on other sites

Your problem is with the device, not the code. Just look at the monitor. There is no response from the DI command and thus the reason you get a timeout waiting for one. Maybe your device requires a line feed (chr(10)) instead of carriage return at the end? Or perhaps both? I can't say since its a custom piece of hardware. Hyperterminal I believe will send both a carriage return and linefeed when you hit "Enter", so if it works there, you probably need both.

Link to comment
Share on other sites

I'm sorry, but I get this all the time. People think DAQFactory is not working right and it turns out that it was a hardware problem. We even had someone saying DAQFactory Modbus wasn't working with a new Unitronics device. Turns out that the Unitronics device had a bug in its Modbus implementation, which they promptly fixed. DAQFactory is very well tested, especially in the serial and Ethernet comms and especially on stuff so basic. Serial / Ethernet is used by probably 80% of the thousands of DAQFactory users with no issues. I'm telling you, from looking at the monitor, DAQFactory is sending that command but it is not getting a response, and thus you are getting a timeout. I don't know why it works manually, but there is obviously something different in the way your device responds which is a bug in your hardware implementation. My guesses would be one of the following:

1) The script is running too fast and your device can't handle it. This would be surprising since you have delay(1) in there.

2) your device doesn't like having the DI1M1 command right after the AI2M0 command.

3) you have some really basic error, a typo that isn't getting carried over into the forum, a comm setting or something

Try simplifying your sequence to just poll DI1M1.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.