Solved

How to send binary data using Mscomm

Posted on 1998-08-08
5
307 Views
Last Modified: 2011-09-20
i need to send 16 bits binary data using rs232 (mscomm.output) .but i don't know how . please help !!!
i have search for the solution for days but seems that nobody know how
to do it except the same thing in vb help that is using a byte array ??
but what do that means ???
0
Comment
Question by:khchan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
ID: 1468364
khchan,
As you know, 8 bits is a byte.  Each piece of your 16 bits data need to bytes to hold it.  Assume you need to send 5 piece of data, that means you need 10 bytes. So you would have an array with data type of byte (instead of integer, string) and size of 10. so you need to do
Dim myBinData (1 to 10) as Byte
Now fill the array with your data and you should be able do it.
Let me know if you have more questions.
Regards
Dalin
0
 

Author Comment

by:khchan
ID: 1468365
Thanks Dalin .I know what you say and  i have try with the method that you mention above but it just don't work . let me explain in more detail about what i want.

The data that i need to send is actually an integer from -2047 to +2047 . this need 12 bit for each data but since that we can just send binary by byte then i need 16 bit (2 bytes).i have sucessfully separate my data to highbyte and lowbyte .
below is a portion of my code


dim value(i) as integer 'so that i can key in the data
dim lowbyte,highbyte as byte


For i = 1 To 9
value(i)= 200  ' example of the value that i send

If Value(i) > 256 Then
    lowbyte = Value(i) Mod 256
    highbyte = Int(Value(i) / 256)
Else
    lowbyte = Value(i)
    highbyte = 0
End If
MSComm1.PortOpen = True

MSComm1.Output = highbyte
MSComm1.Output = lowbyte
MSComm1.PortOpen = False
next i

the error that came out is
invalid property value.

i have even try this
dim portionbyte(1 to 2) as byte

For i = 1 To 9
If Value(i) > 256 Then
    portionbyte(1) = Value(i) Mod 256
    portionbyte(2) = Int(Value(i) / 256)
Else
    portionbyte(1) = Value(i)
    portionbyte(2) = 0
End If

MSComm1.PortOpen = True

MSComm1.Output = portionbyte(1)
MSComm1.Output = portionbyte(2)
MSComm1.PortOpen = False

Next i

just for the sake of the byte array that mscomm needed to send binary data.but the error still there .

please help!!!

Thanks again
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1468366
khchan,

dim portionbyte(1 to 2)
For i = 1 To 9
       If Value(i) > 256 Then
           portionbyte(1) = Value(i) Mod 256
           portionbyte(2) = Int(Value(i) / 256)
       Else
           portionbyte(1) = Value(i)
           portionbyte(2) = 0
       End If

     MSComm1.Output = portionbyte
Next i
0
 

Author Comment

by:khchan
ID: 1468367
THANKS FOR YOUR HELP .
BUT I STILL CAN'T GET IT RIGHT.
AND I HAVE FOUND OUT A METHOD . THAT IS USING

CHR$(PORTIONBYTE(1)) TO CONVERT TO ASCII AND SEND IT THROUGH COM PORT.

0
 
LVL 9

Expert Comment

by:Dalin
ID: 1468368
Well, If it did not work, you should not accept the answer.
I am sorry. but it works for me.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question