好久没回来了,请大家帮忙看下这个发送语句怎么写? 散分50.

szywelcome 2008-10-22 10:28:36
ex) When reading the D-Register from PV(D0001) to SP(D0002)
- Transmission : [stx]01RSD,02,0001[cr][lf]
- Transmission (Include Check Sum) : [stx]01RSD,02,0001C5[cr][lf]
If received data are PV=50.0 and SP=30.0, the result is as under;
- Reception : [stx]01RSD,OK,01F4,012C[cr][lf]
- Reception (Include Check Sum) : [stx]01RSD,OK,01F4,012C19[cr][lf]
※The converting process for display received hexadecimal PV value.
①. Converting decimal : 01F4 (Hexadecimal) 500(Decimal)
②. Result × 0.1 : 500 * 0.1 50.0
[stx]=0x02
[cr]=0x0D
[lf]=0x0A

根据上面的值我写了一条发送数据Transmission : [stx]01RSD,02,0001[cr][lf]

0x0201RSD,02,00010x0D0x0A .这样把值直接写进去有错吗,还是要用逗号分开.
MSComm1.Output="0x0201RSD,02,00010x0D0x0A"
发送数据有反应,但没返回数据.
现在程序和接线都是正确的,就是命令发了过去没返回数据.
请问这条输出命令根据上面的提示该怎么写?


...全文
169 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingsang 2008-10-23
  • 打赏
  • 举报
回复
up
zdingyun 2008-10-23
  • 打赏
  • 举报
回复
以上代码依据:
NOVA Series
Communication Manual
Communication with sum check, the ASCII codes of the text between STX and before checksum are
converted into hexadecimal values and added on a byte basis.
Then the lowermost byte of the added results is turned into ASCII code, and its lower byte is used as the
checksum.(Lower 2 bytes)
zdingyun 2008-10-23
  • 打赏
  • 举报
回复
你的命令应按以下方式发送:

Private Sub CmdSend_Click()
Dim sj As String
Dim i As Integer
Dim sum As Integer
Dim sumStr As String
sj = "01RSD,02,0001"
Text1 = sj
For i = 1 To Len(sj)
sum = sum + Asc(Mid(sj, i, 1))
Next
sumStr = Hex(sum Mod 256)
MsComm1.Output = Chr(2) & sj & sumStr & Chr(&HD) & Chr(&HA) '这是有校验和的
End Sub

如果无校验和则:
Private Sub CmdSend_Click()
Dim sj As String
Dim i As Integer
Dim sum As Integer
Dim sumStr As String
sj = "01RSD,02,0001"
Text1 = sj
For i = 1 To Len(sj)
sum = sum + Asc(Mid(sj, i, 1))
Next
sumStr = Hex(sum Mod 256)
MsComm1.Output = Chr(2) & sj & Chr(&HD) & Chr(&HA)
End Sub

szywelcome 2008-10-22
  • 打赏
  • 举报
回复
Transmission : [stx]01RSD,02,0001[cr][lf]
发送上面的数据格式,是字符串形式还是数组形式.

864

社区成员

发帖
与我相关
我的任务
社区描述
VB COM/DCOM/COM+
c++ 技术论坛(原bbs)
社区管理员
  • COM/DCOM/COM+社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧