用VB如何实现下面的功能和串口通讯,求解
例2、功能参数设定
要设定18#机台的“P0105 加速时间”的值为990.0秒。参数标号0105D=0069H
方法如下:990.0去掉小数点为9900D=26ACH
A=18=12H (变频器地址为“12H”)
K=06H (功能参数设定为“06H”)
P1P0=0069H (参数标号数字序号为“0069H”)
D3=00H (数据高字节为 “00H”)
D2=00H (数据次高字节为 “00H”)
D1=26H (数据次低字节为 “26H”)
D0=ACH (数据低字节为 “ACH”)
S=53H (和校验字节为“53H”)
(S=12H+06H+00H+69H+00H+00H+26H+ACH=1 53H)
电脑先后依次发送字节如下的数据包:3ah,31h,32h,30h,36h,30h,30h,36h,39H, 30h,30h,30h,30h,32h,36H,41h,43h,35h,33h,0dh,0ah
若变频器正确接收到以上数据包,变频器将回复这个数据包的拷贝.
例3、功能参数查询
11#变频器在运行状态下查询它的“输出频率”。
方法如下:
A=11=0BH (变频器地址为“0BH”)
K=07H (功能参数查询为“07H”)
P1P0=0001H (输出频率功能号为“0001H”)
D3=00H (数据高字节为“00H”)
D2=00H (数据次高字节为“00H”)
D1=00H (数据次低字节为“00H”)
D0=00H (数据低字节为“00H”)
S=13H (和校验字节为“12H”)
(S=0BH+07H+00H+01H+00H+00H+00H+00H =13H)
主机(电脑)先后依次发送字节如下的数据包ASCII:3ah,30h,42h,30h,37h,30h,30h,30h,31h,30h,30h,30h,30h,30h,30h,30h,30h,
31h,33h,0dh,0ah
若11#变频器“输出频率”为35.00Hz。
35.00去掉小数为3500D=0DACH
D3=00H (数据高字节为“00H”)
D2=00H (数据次高字节为“00H”)
D1=0DH (数据次低字节为“0DH”)
D0=ACH (数据低字节为“ACH”)
S=CCH (和校验字节为“12H”)
(S=0BH+07H+00H+01H+00H+00H+0DH+ACH =CCH)
若变频器正确接收到主机数据包,变频器将回复如下数据包:
3ah,30h,42h,30h,37h,30h,30h,30h,31h,30h,30h,30h,30h,30h,44h,41h,43h,
43h,43h,0dh,0ah
[解决办法]
建议楼主认真看通信协议
[解决办法]
把你构建好的通信命令,放到Byte类型的数组中,在发送出去,感觉楼主的变频器好像是台安的?
[解决办法]
能详细说一下吗?谢谢了
[解决办法]
已经解决,下面是我写的测试代码,现在分享给大家
MSComm1.InBufferCount = 0 '清除接收缓冲区
MSComm1.OutBufferCount = 0 '清除发送缓冲区
MSComm1.SThreshold = 2 '设置Output 一次从发送缓冲读取字节数为1
MSComm1.RThreshold = 0 '设置接收一个字节产生OnComm事件
z1 = "&h" + DEC_to_HEX(Text1.Text)
z2 = &H7
z3 = &H0
z4 = &H1
z6 = &H0
z7 = &H0
z8 = &H0
z9 = &H0
OutStr(0) = &H3A
OutStr(1) = &H30 '设置机器号
OutStr(2) = Asc(DEC_to_HEX(Text1.Text)) '设置机器号
OutStr(3) = &H30
OutStr(4) = &H37
OutStr(5) = &H30
OutStr(6) = &H30
OutStr(7) = &H30
OutStr(8) = &H31
OutStr(9) = &H30
OutStr(10) = &H30
OutStr(11) = &H30
OutStr(12) = &H30
OutStr(13) = &H30
OutStr(14) = &H30
OutStr(15) = &H30
OutStr(16) = &H30
OutStr(17) = Asc(Left(Right(Hex(z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9), 2), 1)) '校验位
OutStr(18) = Asc(Right(Right(Hex(z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8 + z9), 2), 1)) '校验位
OutStr(19) = &HD
OutStr(20) = &HA
MSComm1.Output = OutStr