请教一个串口通讯的问题!(200分)

  • 主题发起人 主题发起人 jafy
  • 开始时间 开始时间
TO :lgxyy
请教,该如何写才能得到正确的返回值?[:)]
 
TO:PIHOME
发送
MSCOMM1.OUTPUT:='S';
SLEEP(5);
MSCOMM1.OUTPUT:=#255;
返回s
MSCOMM1.OUTPUT:=#83;
返回SS
MSCOMM1.OUTPUT:=#172;
返回S
 
试试这个,mscomm1.output := 'S'#255
 
还是不行![:(]
 
多试几种组合。
另外,你不能找一下硬件设计者吗?
祝你好运![:)]
 
1。你有没有把MSComm的inputMode设成0,即是comInputModeText。
2。看看checksum()的返回值是什么类型。

 
各位:现在还是不行呀,因为客户手上只有这些资料,设备是一个外国公司的,另外还有一个VB写的控制程序,我试图把这个程序(vb3写的)反编译可是编译到一半就出错,继续不下去,请各位再伸伸手,帮帮我,感激不尽!
 
这么说Checksum()是做什么用的你是不知道了,这样会话就只有靠你慢慢琢磨了!
想省钱就得花功夫啊!呵呵
 
如果你有能控制且可以运行的程序,你可以试试PortMon,看看能控制的程序究竟发送了些什么数据
 
to:pihome
请问哪里有比较好用的PORTMON下载?
 
你在这里找一下 http://www.sysinternals.com
 
用串口监控程序,将VB程序的串口的通讯信息截出来。
或将VB程序的串口接到另外一台机上或自己的串2上,看它发出来的是什么?
 
用串口调试工具,同意楼上的
 
各位:由于我以前是做MIS系统的,没有做过控制,所以很多东西不是很清楚,十分的感谢大家的帮助。现在我是用了PORTMON进行跟踪,可得到的数据我不大懂,哪位能帮我解释一下?
0 0.00000400 TRWIN VCOMM_EscapeCommFunction 0x0 0x70042B Unknown Func: 38
1 0.00458480 TRWIN VCOMM_OpenComm COM2 SUCCESS
2 0.00000400 TRWIN VCOMM_SetupComm COM2 SUCCESS RxSize: 2048 TxSize: 512
3 0.21873520 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 9600 Bits: 7 Stop: 1 Parity: Even
4 0.00000400 TRWIN VCOMM_SetCommEventMask COM2 SUCCESS
5 0.00000480 TRWIN VCOMM_EscapeCommFunction COM2 SUCCESS GETCOMBASEIRQ
6 0.20983680 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 19200 Bits: 8 Stop: 1 Parity: None
7 0.00000400 TRWIN VCOMM_SetCommEventMask COM2 SUCCESS
8 0.19944560 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 1200 Bits: 8 Stop: 1 Parity: None
9 0.00000400 TRWIN VCOMM_SetCommEventMask COM2 SUCCESS
10 0.00001440 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 1200 Bits: 8 Stop: 1 Parity: None
11 0.00000560 TRWIN VCOMM_PurgeComm COM2 SUCCESS Transmit Queue
12 0.00000480 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
13 0.00000880 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 2: ..
14 0.00000640 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: .
15 0.00000960 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: .
16 0.00000400 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
230 0.00000400 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
231 0.00000960 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 7: at&fv1.
232 0.00000880 TRWIN VCOMM_PurgeComm COM2 SUCCESS Transmit Queue
233 0.00000720 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
234 0.00000960 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 7: at&fv1.
235 0.00000320 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
285 0.00000560 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
286 0.00000560 TRWIN VCOMM_ReadComm COM2 SUCCESS Length: 7: at&fv1.
287 0.00000720 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
288 0.00000400 TRWIN VCOMM_GetCommEventMask COM2 SUCCESS NONE
289 0.00000400 TRWIN VCOMM_SetCommEventMask COM2 SUCCESS
290 0.00002080 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 1200 Bits: 8 Stop: 1 Parity: None
291 0.00000720 TRWIN VCOMM_PurgeComm COM2 SUCCESS Transmit Queue
292 0.00000960 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: G
293 0.00001280 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: .
294 0.00000640 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
723 0.00000320 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
724 0.00000560 TRWIN VCOMM_ReadComm COM2 SUCCESS Length: 189: .S.-...%%.......8.......................[...TEMP ....1
725 0.00000320 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
868 0.00000320 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
869 0.00000560 TRWIN VCOMM_ReadComm COM2 SUCCESS Length: 89: .Q.............3. . ......Y
870 0.00000240 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
924 0.00000320 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
925 0.00000480 TRWIN VCOMM_ReadComm COM2 SUCCESS Length: 21: .R..P...............O
926 0.00000320 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
1103 0.00000400 TRWIN VCOMM_GetCommEventMask COM2 SUCCESS NONE
1104 0.00000400 TRWIN VCOMM_SetCommEventMask COM2 SUCCESS
1105 0.19815360 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 19200 Bits: 8 Stop: 1 Parity: None
1106 0.00000800 TRWIN VCOMM_EscapeCommFunction COM2 SUCCESS CLRRTS
1107 0.00000400 TRWIN VCOMM_PurgeComm COM2 SUCCESS Receive Queue
1108 0.00000320 TRWIN VCOMM_PurgeComm COM2 SUCCESS Transmit Queue
1109 0.00000480 TRWIN VCOMM_EscapeCommFunction COM2 SUCCESS CLRDTR
1110 0.00000320 TRWIN VCOMM_EscapeCommFunction 0x0 0x70042B Unknown Func: 39
1111 0.00469200 TRWIN VCOMM_CloseComm COM2 SUCCESS
 
你自己写一个接收程序将VB程序发送的内容收下来(用我前面的第二种方法),分析一下就行了!
 
楼上的不愧为一个好办法!我赞同!
 
楼上两位所说的有局限性啊,如果我不知道通信参数呢,那么得到的数据可能就是错误的了!既然有了PortMon,再用这种方法就是多些一举了!

to jafy:
对于你上面取出来的数据,你最好是在PortMon中作如下设置:Options->Show Hex选中,这样就会以16进制显示数据。
3 0.21873520 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 9600 Bits: 7 Stop: 1 Parity: Even
//设置波特率9600,数据位7位,1停止位,偶校验,后面类似的也一样,不过下面几次改变通信参数而没有发送或接收数据,不知道是作什么用的?你可以测试一下是否是必须的
13 0.00000880 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 2: ..
//发送两字节数据,最后的两点是不可见字符,应该以16进制方法显示才能看到其实际内容
724 0.00000560 TRWIN VCOMM_ReadComm COM2 SUCCESS Length: 189: .S.-...%%.......8.......................[...TEMP ....1
//接收到189字节数据,同样的,以16进制方式显示才能看到实际内容

分析一下其发送,接收步骤,以及通信参数设置等,那么你再用Delphi重新实现一下不会是什么难题了吧
 
多谢PIHOME的指点,的确,这样要能看清楚多了,可我的delphi还不太熟悉,不知这样用DELPHI的代码该如何实现?请各位再指导一下,就快胜利了!
49 20:47:24 TRWIN VCOMM_SetCommEventMask COM2 SUCCESS
50 20:47:24 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 1200 Bits: 8 Stop: 1 Parity: None
51 20:47:26 TRWIN VCOMM_PurgeComm COM2 SUCCESS Transmit Queue
52 20:47:26 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
53 20:47:26 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 2: 00 00
54 20:47:26 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: 11
55 20:47:26 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: EE
56 20:47:26 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
270 20:47:32 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
271 20:47:32 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 7: 61 74 26 66 76 31 0D
272 20:47:32 TRWIN VCOMM_PurgeComm COM2 SUCCESS Transmit Queue
273 20:47:32 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
274 20:47:32 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 7: 61 74 26 66 76 31 0D
275 20:47:32 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
325 20:47:34 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
326 20:47:34 TRWIN VCOMM_ReadComm COM2 SUCCESS Length: 7: 61 74 26 66 76 31 0D
327 20:47:34 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
328 20:47:34 TRWIN VCOMM_GetCommEventMask COM2 SUCCESS NONE
329 20:47:34 TRWIN VCOMM_SetCommEventMask COM2 SUCCESS
330 20:47:34 TRWIN VCOMM_SetCommState COM2 SUCCESS Mask: ffffffff Baud: 1200 Bits: 8 Stop: 1 Parity: None
331 20:47:34 TRWIN VCOMM_PurgeComm COM2 SUCCESS Transmit Queue
332 20:47:34 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: 47
333 20:47:34 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: B8
334 20:47:34 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
759 20:47:52 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
760 20:47:52 TRWIN VCOMM_ReadComm COM2 SUCCESS Length: 189: F0 53 AC 2D 00 00 00 25 00 00 00 80 00 00 00 38 00 00 00 80 00
761 20:47:52 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
762 20:47:52 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
763 20:47:52 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
764 20:47:52 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 3: F0 51 AE
765 20:47:52 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
897 20:47:52 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
898 20:47:52 TRWIN VCOMM_ReadComm COM2 SUCCESS Length: 89: F0 51 AE 10 00 00 01 00 07 00 07 00 01 00 07 33 0D 20 20 20 20
899 20:47:52 TRWIN VCOMM_ClearCommError COM2 SUCCESS NOERROR
 
人才不少哦
 
只要是VCOMM_write后面的东西你可以用MSCOMM.OUTPUT := 'XXXX'来实现。例如
20:47:26 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 2: 00 00
MSCOMM.OUTPUT := #0#0
333 20:47:34 TRWIN VCOMM_WriteComm COM2 SUCCESS Length: 1: B8
mscomm.output := #$B8
 
后退
顶部