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

RS232不能設定stop 位元為1.5 byte

尚未結案
plihui
初階會員


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

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-09-19 10:25:39 IP:218.168.xxx.xxx 未訂閱
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//選擇使用的port: com1 或 com2
 char *Com_port;
 DCB dcb;
 String Com_name="COM" IntToStr(CommSelect->ItemIndex 1);
 Com_port=Com_name.c_str();
 hComm=CreateFile(Com_port, GENERIC_READ | GENERIC_WRITE,
                  0, NULL, OPEN_EXISTING, 0 ,0);
 if ( hComm == INVALID_HANDLE_VALUE)
  {
  MessageBox(0, "開啟錯誤的通訊阜!!!","錯誤的通訊阜", MB_OK);
  return;
  }
 // 將dcb位置傳入,已設定通訊參數
 GetCommState(hComm,&dcb);
 dcb.BaudRate = CBR_9600;
 dcb.ByteSize = 8;
 dcb.Parity=NOPARITY;
 dcb.StopBits=ONE5STOPBITS;
              ^^^^^^^^^^^^^^^^^     if( !SetCommState( hComm, &dcb) )
  {
   MessageBox(0, "通訊參數設定失敗", "Setting Error", MB_OK);
   CloseHandle(hComm);
   return;
  }
}
結果出現"通訊參數設定失敗"的訊息??? 是程式哪裡出問題?還是RS232不能設定stop 位元為1.5 byte? ps: 我的作業系統為window XP

版主


發表:261
回覆:2302
積分:1667
註冊:2005-01-04

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-09-20 14:22:16 IP:211.22.xxx.xxx 未訂閱
去查一下它的通訊協定吧. 232 的停止位元 應該只有1 or 2 bit , 沒有所謂1.5 byte 只有start bit 有1 or 1.5 bit, 但也沒有byte...
------
-------------------------------------------------------------------------
走是為了到另一境界,停是為了欣賞人生;未走過千山萬水,怎知生命的虛實與輕重!?
plihui
初階會員


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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-09-21 16:40:44 IP:218.168.xxx.xxx 未訂閱
引言: 去查一下它的通訊協定吧. 232 的停止位元 應該只有1 or 2 bit , 沒有所謂1.5 byte 只有start bit 有1 or 1.5 bit, 但也沒有byte...
也對 筆誤.....不過 dcb.StopBits=ONE5STOPBITS; 結果出現"通訊參數設定失敗"的訊息??? 是程式哪裡出問題?還是RS232不能設定stop 位元為1.5 bit ps: 我的作業系統為window XP
暗黑破壞神
版主


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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-09-21 16:59:37 IP:59.104.xxx.xxx 未訂閱
引言: 去查一下它的通訊協定吧. 232 的停止位元 應該只有1 or 2 bit , 沒有所謂1.5 byte 只有start bit 有1 or 1.5 bit, 但也沒有byte... 是程式哪裡出問題?還是RS232不能設定stop 位元為1.5 bit
你還真的是搞不清勒。。。。。。。。
plihui
初階會員


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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-09-21 17:13:28 IP:218.168.xxx.xxx 未訂閱
引言:
引言: 去查一下它的通訊協定吧. 232 的停止位元 應該只有1 or 2 bit , 沒有所謂1.5 byte 只有start bit 有1 or 1.5 bit, 但也沒有byte... 是程式哪裡出問題?還是RS232不能設定stop 位元為1.5 bit
你還真的是搞不清勒。。。。。。。。
呵呵....不曉得可否提供RS232相關格式和資料 給小弟參考??尤其是start bit 和stop bit的設定 ^^^^^^^^^ ^^^^^^^ 感激不禁
暗黑破壞神
版主


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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-09-21 21:20:55 IP:59.104.xxx.xxx 未訂閱
去 google 找找吧。 資料一堆。就怕你不去找。
plihui
初階會員


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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-09-23 20:48:04 IP:61.216.xxx.xxx 未訂閱
http://www.lammertbies.nl/comm/info/RS-232_specs.html 找到了....    [原文] Stop bits Suppose that the receiver has missed the start bit because of noise on the transmission line. It started on the first following data bit with a space value. This causes garbled date to reach the receiver. A mechanism must be present to resynchronize the communication. To do this, framing is introduced. Framing means, that all the data bits and parity bit are contained in a frame of start and stop bits. The period of time lying between the start and stop bits is a constant defined by the baud rate and number of data and parity bits. The start bit has always space value, the stop bit always marking value. If the receiver detects a value other than marking when the stop bit should be present on the line, it knows that there is a synchronization failure. This causes a framing error condition in the receiving UART. The device then tries to resynchronize on new incomming bits.     For resynchronizing, the receiver scans the incomming data for valid start and stop bit pairs. This works, as long as there is enough variation in the bit patterns of the data words. If data value zero is sent repeatedly, resynchronization is not possible for example.     The stop bit identifying the end of a data frame can have different lengths. Actually, it is not a real bit but a minimum period of time the line must be idle (marking state) at the end of each word. On PC's this period can have three lengths: the time equal to 1, 1.5 or 2 bits. 1.5 bits is only used with data words of 5 bits length and 2 only for longer words. A stop bit length of 1 bit is possible for all data word sizes.     
系統時間:2024-04-26 14:38:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!