• 08-12

    2013

    【通訊程式】如何自動偵測設備的鮑速率(baud rate)

    最近在寫通訊程式,常常遇到不知道目標設備的鮑速率設定為多少 下面提供了一個有趣的偵測方法: 對於我們的設備寄一個我們已知的字串像00ABCD,然後看是否能收到這個字串 如果沒有收到正確的字串的話,就再換一個鮑速率再測一次 不過可以的話,還是建議詢問或查詢該設備正確的鮑速率 Q: How do I automatically detect the baud rate of a device?  The PC doesn’t have built-in automatic baud detection, but there is an easy trick to implement basic baud detection for many devices.  If there is a known call & response to the device you can set the baud rate of the port to one setting, open the port, send the call, see if you get the expected response, and if not close the port, set a different baud rate, and repeat.  For my own devices I’ve had some of them send a known character string (could be anything, like 000ABCD) after they receive a high on the DTR line.  This way my serial code can set DTR high, see if it gets the ABCD at one baud rate and if not, close the port, set another baud rate, open the port, turn DTR high, and try again.  If the baud rates match the characters will be read correctly, if not then the characters will be jumbled.  This can be done with many other devices as well if there's a known call and response, like sending a modem an AT command with an expected response code.  參考資料: http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx   台北網頁設計,新竹網頁設計
  • 08-10

    2013

    【通訊程式】監控 com port ( RS232) 裡面的資料流

    現在電腦雖然都很少RS232 但是仍然有很多硬體設備仍要靠這個通訊來溝通 所以下面介紹一個免費的監控 com port ( RS232)  它就叫 Free Serial Port Monitor Free Serial Port Monitor allows you to intercept, display and analyze all data exchanged between the Windows application and the serial device. It can be successfully used in application development, device driver or serial hardware development and offers the powerful platform for effective coding, testing and optimization. Free Serial Port Monitor可以讓你截取,顯示並且分析程式和設備之類的資料 他還可以把資料轉存一個log文件,不過這個就是免費功能了 但是一般免費版就有大部份功能,讓分析資料的工作做的好了 直接下載 官方網址 : http://www.serial-port-monitor.com/ 台北網頁設計,新竹網頁設計
      台北網頁設計,新竹網頁設計