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.

What is the best way to write CRBasic for receiving a data from sensor via TCP connection that comes randomly.


Kong Jan 10, 2020 10:05 AM

HI there,

We have a case where our sensor (RS232 connected to a MOXA serial server on port, says 1000) will be sending data randomly or could says every 20 minutes or so.

The data will be sending from the sensor as ASCII, it looks similar to those GPS NMEA sentences but will be a series of 30 sentences of individual parameters, in total of around 3000-4000 bytes.

What should be the best way to write a CRBasic code to standby for the incoming data?  Should we constantly open the TCP connection and monitor for the SerialInChk <>0 ? I was not sure if the Scan loop might miss the data.

Appreciated all ideas and suggestions.


JDavis Jan 13, 2020 11:48 PM

Use TCPOpen() with the buffer set greater than 4000, and it can catch data between scans. Use instructions such as SerialInRecord() to read the data from the buffer.


Kong Jan 14, 2020 04:22 AM

man thanks for your kind reply.

at what scan interval should we set for the slowsequence? just cusious how we do a loop for getting responses without effect the other loop.

Currently we are using

IPSocket = TCPOpen("192.168.0.100",10002,4096,1500)
If IPSocket <> 0 Then
   SerialInBlock(IPSocket,IncomingTCPString,4096)
   a = InStr(1,IncomingTCPString,CHR(02),2)
   b = InStr(a,IncomingTCPString,CHR(03),2)
   MidWSStr = Mid(IncomingTCPString,a+1,b-2)
   Call SaveToTable
End If

But it didn't seem to pick up the data successfully and we got zero reading.

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