Applies To:
  • CitectSCADA 1.00, 1.01, 1.10, 1.11, 1.20, 2.00, 2.01

Summary:
Question: How does ComRead wait for characters from the COM ports. Does it wait until the number of characters asked for are read, or the timeout period? 

Solution:
ComRead does not wait until the specified number of characters have arrived before returning. When designing ComRead, we assumed that it is better to return half the characters now, rather than wait for the rest and return all of them in the future (a bird in the hand is worth two in the bush). This makes the response from ComRead faster, however you will most likely have to concatenate each read into the entire message. You would have to do this anyway, as ComRead could always have returned only part of the message.

ComRead will return as soon as it finds any characters. How many characters it returns will depend on the type of communication port. If you are using a Digiboard, ComRead will most likely return the entire protocol message. Citect's Digiboard drivers are designed to return data when they see a delay in the received characters. This delay normally occurs after the end of a message, (ie while the sender is waiting for your response). If however, the transmission from the sender is continuous, the Digiboard will only send the characters back when its buffers are 1/2 full - approximately 800 bytes of its 1600 byte buffer. Characters from the local COM port are unbuffered by an interrupt routine running off the Timer that runs every 55ms. Therefore, if you are using the local COM port, ComRead will return 55ms worth of data. At 9600 baud you should get around 52 characters.

The best way to use ComRead is as follows:

iLen = 127;
ComRead(hCom, sBuf, iLen, 2);

With this call ComRead, will return immediately with any characters waiting in Citect's buffers. If there are no characters, ComRead will block - waiting for characters. When the ComRead receives the next bunch of characters (Digiboard on receive delay or COM port on timer tick), it will return with those characters. If no characters are found within the 2 second timeout, ComRead will return with a timeout error (0x07).

The length specified in ComRead is really a maximum length of the buffer. (ComRead won't ever read more that this many characters into the buffer.) Note that characters are not lost as Citect has its own 1600 byte buffers. Only when these buffers fill up will you start to loose data from your COM ports. 


Keywords:
 

Attachments