Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ENQ/Hex 05

Status
Not open for further replies.

charliea123

Technical User
Nov 4, 2008
3
I am trying to pass a Hex 05 to a set of scales but I am having issues. Can someone please help with the correct code to use to send a Hex 05 using FoxPro 5.0?
 
bborissov,

Thanks for your reply. I have a form setup do you can select the comm port, braud rate, etc.. I had a text box that you could type in the string and replaced that and hardcoded the string in the code. I have tried chr(5) and it failed. I have also tried 0x05 and the return string was 0x05. I have used Hypertermail to test and by sending a ctrl-e which should be the same as HEX 05 i get the response back from the scale. Below is the code for the "Test Scale" button on my form. Please take a look and see what I maybe doing wrong.

if empty(thisform.commport)
=messagebox('Missing communication.','Invalid port...')
return
endif

if empty(thisform.setting)
=messagebox('Missing setting.','Invalid setting...')
return
endif

**thisform.output = chr(5)
**thisform.output = thisform.dtext1.value

**if empty(thisform.output)
** =messagebox('Missing output string.','Invalid string...')
** return
**endif

if llportopen = .f.
wait 'Setup comm port 1 parameters' window timeout 3
thisform.cm.commport = thisform.commport
thisform.cm.settings = thisform.setting
thisform.cm.handshaking = thisform.handshake
thisform.cm.rthreshold = thisform.treshold
endif

if llportopen = .f.
wait 'Open port 1' window timeout 3
llportopen = .t.
thisform.cm.portopen = .t.
endif

thisform.output = chr(5)
**thisform.cm.output = "0x05"

thisform.timer1.enabled = .t.

wait window 'Waiting for scale to stabilize...' timeout 3

if thisform.cm.commevent <> 2
thisform.dtext2.value = 'Scale Test failed: ' + str(thisform.cm.commevent)
thisform.returnstr = 'Scale Test failed: ' + str(thisform.cm.commevent)
else
thisform.returnstr = thisform.cm.input
thisform.dtext2.value = thisform.returnstr
endif

wait 'Close port 1/2/3' window timeout 3

thisform.cm.portopen = .f.

thisform.timer1.enabled = .f.

thisform.refresh()
 
I can't tell you what you do wrong because I don't know the scale interface. What I know is that you SHOULD first flush the COM (or read everything that in its buffer), then Send what you want (and believe me that IS CHR(5)) and then in ONCOMM event of the MSCOMM control read what you receive from it.
I don't like MSCOMM control much just because first time I used it it was buggy, I don't know how it is now.
Also VFP5 was one of the buggiest versions of VFP ever (maybe VFP3 was buggier but I don't know I never used it).
Try to search and install "Microsoft Communication Control 6"
But as I said I never deal with it and not sure if this helps.

Check this:
If you know C++ you could write your own FLL that could deal with COM ports.


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
The scale readout is connected via serial port from PC to readout. If you pass a HEX 05 to the readout it is suppose to return the readout info. So if nothing is on the scale it should return something like this 0.0lb G CZ, which is zero gross pounds..
 
I'm guessing that since you're using thisform.cm.commport in your code, 'cm' is the comm control. If that's the case, you need to be using
thisform.cm.output = chr(5) instead of thisform.output = chr(5) to actually send the data.



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Also, you almost had it with thisform.cm.output = "0x05".

You should have used thisform.cm.output = chr(0x05) (which actually would have been the same as thisform.cm.output = chr(5) )

You don't want to use "0x05" because it would have output the entire string of 0, 0, x, 5 rather than just the desired chr(5).



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top