Applies To: |
|
Summary: |
Question: I have written a cicode function which sends strings out via the serial ports. I am using the ComWrite() function to transmit the strings. I find that the cicode function works fine with the local COM port on the computer, however it sometimes fails when using a Digiboard. What are the differences between the local serial ports and using a Digiboard? |
Solution: |
The Digiboard and COM ports have slightly
differently timing which can effect the way the functions ComRead()
and ComWrite() operate. The effect on the timing of the ComRead()
is discussed in article Q1126.
It has also been found that there is a side effect when using the ComWrite() function with a Digiboard. CIT has confirmed this to be a problem in Citect for Windows versions 1.00 to 3.10. This problem has been fixed in version 3.20. This problem is detailed below: ComWrite has the following arguments defined: ComWrite(hPort, sBuffer, iLength, iTimeOut) Where iLength is the number of characters to be transmitted. What the help does not explain is that ComWrite will modify the value of the iLength variable to contain the actual number of charters transmitted. So if all characters are transmitted iLength will be unchanged and if the transmit fails iLength will be set to 0. Due to the timing differences on transmit between the COM port and the Digiboard, this effect may only occur on a Digiboard. This will cause problems if you code looks like this: iLength = 1; As when any call to ComWrite() fails then the iLength will be set to 0. Then the next time you call ComWrite() the iLength will be set to 0 and you will transmit nothing. This will cause ComWrite() to return 'out of range error' (error code 257). As the above code does not check the return value, it will see as the ComWrite() will no longer transmit anything. You may work around this problem by always setting iLength to the correct length just before calling ComWrite(). For example: FOR i = 0 TO 100 DO As we feel that it is unlikely you want to know the number of characters which were transmitted by ComWrite(), in version 3.2 and later ComWrite() will not modify the iLength parameter. If you have written code in previous versions of Citect to rely on modifications of iLength, you will have to modify you code to check for the return error code as an indication of failure. |
Keywords: |
Related Links
Attachments