作者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://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1536146954.A.5B7.html
1F:→ Raymond0710: 先找个其他Tool测看看 通讯能不能work09/06 01:27
2F:推 chuegou: 他有回应该是有通 我猜是protocol有问题09/06 12:14
3F:→ feeya: 字串 /r 结尾有传吗09/06 14:36
抱歉/r结尾是什麽意思呢
※ 编辑: death811125 (27.247.32.20), 09/06/2018 17:43:46
4F:→ uranusjr: 我猜 write 了没有 flush 所以根本没送出去09/06 17:52
5F:推 chuegou: 抱歉原来设备没反应 你先把自己的tx rx对接 自发自送09/06 19:10
6F:→ chuegou: 看看到底有没有送出09/06 19:10
7F:推 dces4212: \r 是换行字元 有些接收端会用此字元当作command termin09/07 13:32
8F:→ dces4212: ator 也就是你送给他的command的结尾 然後有些是要收\r\09/07 13:32
9F:→ dces4212: n 看他的spec09/07 13:32
谢各位回覆 我在试试看
※ 编辑: death811125 (39.10.37.31), 09/07/2018 23:52:30