[問題] RS232資料接收及傳送問題

作者: death811125 (安安王子見)   2018-09-05 19:29:09
開發平台(Platform): (Ex: Win10, Linux, ...)
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
開發平台(Platform): (Ex: Win10, Linux, ...)
Win7
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
VC 2013
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
參考 https://www.teuniz.net/RS-232/
RS232.c, RS232.h
問題(Question):
我要使用RS232連接我的裝置
裝置是一台Sony的攝像機(Visca協定),可以控制他的底座轉向。
目前只能確認有開始使用COM1。
不知道問題是在
1.給指令的方法有問題
2.根本沒連接到攝像機
預期的正確結果(Expected Output):
我傳送一段指令 例如:81010601010103FF
他會回傳我:9041FF9051FF
錯誤結果(Wrong Output):
輸入指令,設備確沒有反應。
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
#include <stdlib.h>
#include <stdio.h>
#include <Windows.h>
#include "rs232.h"
int main()
{
int i, n,
cport_nr=0, /* COM1 = 0 */
bdrate=9600; /* baud */
unsigned char buf[4096];
char mode[]={'8','N','1',0};
if(RS232_OpenComport(cport_nr, bdrate, mode))
{
printf("Can not open comport\n");
return(0);
}
char s[100];
scanf("%s", s);
if( s != NULL )
{
RS232_cputs(cport_nr, s);
}
n = RS232_PollComport(cport_nr, buf, 4095);
if(n > 0)
{
buf[n] = 0; /* always put a "null" at the end of a string! *
/
printf("%s", (char *)buf);
}
RS232_CloseComport(cport_nr);
return(0);
}
希望有使用過這library的能指導我,十分謝謝。
作者: Raymond0710 (雷門)   2018-09-06 01:27:00
先找個其他Tool測看看 通訊能不能work
作者: chuegou (chuegou)   2018-09-06 12:14:00
他有回應該是有通 我猜是protocol有問題
作者: feeya (24 August 升格為鄉民)   2018-09-06 14:36:00
字串 /r 結尾有傳嗎
作者: uranusjr (←這人是超級笨蛋)   2018-09-06 17:52:00
我猜 write 了沒有 flush 所以根本沒送出去
作者: chuegou (chuegou)   2018-09-06 19:10:00
抱歉原來設備沒反應 你先把自己的tx rx對接 自發自送看看到底有沒有送出
作者: dces4212 (flawless)   2018-09-07 13:32:00
\r 是換行字元 有些接收端會用此字元當作command terminator 也就是你送給他的command的結尾 然後有些是要收\r\n 看他的spec

Links booklink

Contact Us: admin [ a t ] ucptt.com