作者death811125 (安安王子見)
看板C_and_CPP
標題[問題] RS232資料接收及傳送問題
時間Wed Sep 5 19:29:09 2018
開發平台(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的能指導我,十分謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.194.237
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1536146954.A.5B7.html
→ Raymond0710: 先找個其他Tool測看看 通訊能不能work09/06 01:27
推 chuegou: 他有回應該是有通 我猜是protocol有問題09/06 12:14
→ feeya: 字串 /r 結尾有傳嗎09/06 14:36
抱歉/r結尾是什麼意思呢
※ 編輯: death811125 (27.247.32.20), 09/06/2018 17:43:46
→ uranusjr: 我猜 write 了沒有 flush 所以根本沒送出去09/06 17:52
推 chuegou: 抱歉原來設備沒反應 你先把自己的tx rx對接 自發自送09/06 19:10
→ chuegou: 看看到底有沒有送出09/06 19:10
推 dces4212: \r 是換行字元 有些接收端會用此字元當作command termin09/07 13:32
→ dces4212: ator 也就是你送給他的command的結尾 然後有些是要收\r\09/07 13:32
→ dces4212: n 看他的spec09/07 13:32
謝各位回覆 我在試試看
※ 編輯: death811125 (39.10.37.31), 09/07/2018 23:52:30