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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling Hex Numbers through MSComm

Status
Not open for further replies.

aclayborne

Programmer
May 3, 2000
49
US
I know this is a pretty basic question for most of you all but the whole concept escapes me.
I have an application that needs to send and receive information through MSComm the setting will be (9600,8,N,1)
I will recieve a 5 byte packet ex:
Offset1 = 0x7E
Offset2 = 0x01
Offset3 = 0x02
Offset4 = Unused
Offset5 = Checksum(Modulo-256 sum of 1 thru 3)

1) What will I actually see in comEvReceive in the MSComm1.CommEvent.
2) What's the best way to handle it? Can I use the Split()Do I declare the variable that will handle the data as string, or an array of bytes ex: Dim B(4) As Byte.
3) How do I calculate my checksum.


 
you will send with something like

mscommX.output=chr(offset1)

you should recieve the integer value in the commevent (in this case 126) then if you want it back in hex just use the hex function and finally store it as you want it (hex function returns a string)!!

as for the checksum, if i pretended to know exactly what i was doing(which i dont) it goes something like this.

to calculate:-
yourchecksum=sumofallhex % 256

to resolve:-
if (sumofallhex % 256)= yourchecksum then
msgbox "checksum is good"
else
msgbox "checksum is bad"
end if

hope this puts you in the right direction!!

good luck

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
oops... vb doesnt use "%" it uses Mod...

good luck

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top