开发者

VB6 RS232 commands not working

I have the following code:

MSCommProj.CommPort = 6
MSCommProj.RThreshold = 1
MSCommProj.Settings = "19200,N,8,1"
MSCommProj.InputLen = 0
MSCommProj.PortOpen = True

And it opens just fine and connects but when i try sending the command:

MSCommProj.Output = "21 8901 5057 31 0A" & Chr$(13)

and

MSCommProj.Output = "21 89 01 50 57 31 0A" & Chr$(13)

and

MSCommProj.Output = "3F 89 01 50 57 0A" & Chr$(13)

as instructed by the user manual, it does not come on开发者_如何学运维.

Here is the pages in the manual that shows this. Maybe i am just doing it wrong?:

VB6 RS232 commands not working

VB6 RS232 commands not working

VB6 RS232 commands not working

VB6 RS232 commands not working


Are you sure that you're meant to be sending character data to the RS232 interface for that? Those look like binary sequences to me.

Rather than:

MSCommProj.Output = "3F 89 01 50 57 0A" & Chr$(13)

I'd be looking at transmitting the binary data thus:

MSCommProj.Output = chr$(63) & chr$(137) & chr$(1) & chr$(80) & chr$(87) & chr(10)

You'll note that there's no chr$(13) at the end, the spec doesn't call for that.


If you want to know what the conversions are for those hex values, start up the Windows calculator, change the view to scientific, switch to hex mode, enter the value, the switch to decimal mode.

Or you can download an ASCII table for this purpose. Or view one of my voluminous essays on the subject here.


You are required to send bytes given.
You instead send string representation of those.

Send actual bytes.
chr$(&h21) & chr$(&h89) & chr$(&h01) & chr$(&h50) etc.


It was because i did not use a cross-over cable... All the rs232 codes were correct. Blah.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜