線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2952
推到 Plurk!
推到 Facebook!

如何中斷RS232傳輸...然後在續傳 ?!

尚未結案
plihui
初階會員


發表:88
回覆:96
積分:41
註冊:2003-07-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-09-21 16:36:09 IP:218.168.xxx.xxx 未訂閱
如題: 我已經參考過 C builder 與Rs 232 串列通訊控制這本書了 但是翻遍內容都沒有中斷RS232傳輸然後在續傳的相關範例 或者有先輩可以提供一些API或是意見 感激不禁
暗黑破壞神
版主


發表:9
回覆:2301
積分:1627
註冊:2004-10-04

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-09-21 16:57:02 IP:59.104.xxx.xxx 未訂閱
引言: 我已經參考過 C builder 與Rs 232 串列通訊控制這本書了 但是翻遍內容都沒有中斷RS232傳輸然後在續傳的相關範例
嗯。不錯有看過書 那就是說書上沒寫的囉? 所以。我們要用通訊協定來解決它。 怎麼說勒。 比方說 PC -> device hello 我來了。你要什麼檔案? device -> PC 喔。我想要 ABC.TXT PC -> device 喔。這個檔案共 3M 你要由那邊開始傳? device -> PC 我這邊已經有 30 bytes 了。你由第31 byte 開始丟給我吧。 PC -> device 資料如下。。。。。。。開始丟剩下的東東。 當然 device 也可以跟 PC 說。你由 0 byte 開始丟給我。 寫程式吧。^_^
DavidLo
高階會員


發表:17
回覆:225
積分:168
註冊:2004-07-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-09-21 23:25:56 IP:218.169.xxx.xxx 未訂閱
於大量傳輸資料情況下,就要使用[暫緩續傳]功能. 當PC的接收緩衝區長度使用超過80%,PC送出XOFF字元,告知外部設備停止送出資料.當PC的接收緩衝區長度使用低於20%,PC送出XON字元,告知外部設備繼續送出未完成資料. 轉載國外參考資料: RS232 flow control and handshaking Software flow control Both software and hardware flow control need software to perform the handshaking task. This makes the term software flow control somewhat misleading. What is ment is that with hardware flow control, additional lines are present in the communication cable which signal handshaking conditions. With software flow control, which is also known under the name XON-XOFF flow control, bytes are sent to the sender using the standard communication lines. Using hardware flow control implies, that more lines must be present between the sender and the receiver, leading to a thicker and more expensive cable. Therefore, software flow control is a good alternative if it is not needed to gain maximum performance in communications. Software flow control makes use of the datachannel between the two devices which reduces the bandwidth. The reduce of bandwidth is in most cases however not so astonishing that it is a reason to not use it. Two bytes have been predefined in the ASCII character set to be used with software flow control. These bytes are named XOFF and XON, because they can stop and restart transmitting. The bytevalue of XOFF is 19, it can be simulated by pressing Ctrl-S on the keyboard. XON has the value 17 assigned which is equivalent to Ctrl-Q. Using software flow control is easy. If sending of characters must be postponed, the character XOFF is sent on the line, to restart the communication again XON is used. Sending the XOFF character only stops the communication in the direction of the device which issued the XOFF. This method has a few disadvantages. One is already discussed: using bytes on the communication channel takes up some bandwidth. One other reason is more severe. Handshaking is mostly used to prevent an overrun of the receiver buffer, the buffer in memory used to store the recently received bytes. If an overrun occurs, this affects the way newcoming characters on the communication channel are handled. In the worst case where software has been designed badly, these characters are thrown away without checking them. If such a character is XOFF or XON, the flow of communication can be severely damaged. The sender will continuously supply new information if the XOFF is lost, or never send new information if no XON was received. This also holds for communication lines where signal quality is bad. What happens if the XOFF or XON message is not received clearly because of noise on the line? Special precaution is also necessary that the information sent does not contain the XON or XOFF characters as information bytes. Therefore, serial communication using software flow control is only acceptable when communication speeds are not to high, and the probability that buffer overruns or data damage occur are minimal. Hardware flow control Hardware flow control is superior compared to software flow control using the XON and XOFF characters. The main problem is, that an extra investment is needed. Extra lines are necessary in the communication cable to carry the handshaking information. Hardware flow control is sometimes referred to as RTS / CTS flow control. This term mentions the extra input and outputs used on the serial device to perform this type of handshaking. RTS / CTS in its original outlook is used for handshaking between a computer and a device connected to it such as a modem. First, the computer sets its RTS line to signal the device that some information is present. The device checks if there is room to receive the information and if so, it sets the CTS line to start the transfer. When using a null modem connection, this is somewhat different. There are two ways to handle this type of handshaking in that sitiuation. One is, where the RTS of each side is connected with the CTS side of the other. In that way, the communication protocol differs somewhat from the original one. The RTS output of computer A signals computer B that A is capable of receiving information, rather than a request for sending information as in the original configuration. This type of communication can be performed with a null modem cable for full handshaking. Although using this cable is not completely compatible with the original way hardware flow control was designed, if software is properly designed for it it can achieve the highest possible speed because no overhead is present for requesting on the RTS line and answering on the CTS line. In the second situation of null modem communication with hardware flow control, the software side looks quite similar to the original use of the handshaking lines. The CTS and RTS lines of one device are connected directly to each other. This means, that the request to send query answers itself. As soon as the RTS output is set, the CTS input will detect a high logical value indicating that sending of information is allowed. This implies, that information will always be sent as soon as sending is requested by a device if no further checking is present. To prevent this from happening, two other pins on the connector are used, the data set ready DSR and the data terminal ready DTR. These two lines indicate if the device attached is working properly and willing to accept data. When these lines are cross-connected (as in most null modem cables) flow control can be performed using these lines. A DTR output is set, if that computer accepts incomming characters.
系統時間:2024-04-20 21:08:28
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!