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

How to send serial data (non printable char) with MSComm

Status
Not open for further replies.

pancy

Technical User
Jan 23, 2004
17
0
0
HK
I've been sticking to it for a long time already...I tried to send something using MSComm1.Output but when I send an integer valued larger than 127, my microprocessor (which is the receiving side) gets a zero. Here's my code:
...
MSComm1.Output = chr(0) & stringA & chr(integerA) & "."

my data format is like this:
a null (=chr(0)), then a string of two characters, then an integer of 1 byte (0 to 255), then a dot to denote the end of transmission

it works when integerA is 0-127 but fails when I send a value larger than 127

Could anypone please help? Does it relate to the inputmode Setting of the Com Port? I used
default Inputmode

any help would be great! Thanks alot.
Pancy
 
It sounds very much like your microprocessor does not like characters over 127.
Try connecting to a comm port on a pc and see if it comes through correctly.
 
neilharris
I tried downloading some dll for the VB which allows me to send serial data, and it worked. So I think my microprocessor should have no prob.
However, I cant use that dll coz it only support sending but not receiving.
Any suggestion? Thank you very much!
Pancy
 
Oops. For output of data..
"The Output property can transmit text data or binary data. To send text data using the Output property, you must specify a Variant that contains a string. To send binary data, you must pass a Variant which contains a byte array to the Output property."



Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
I suppose you've checked that your protocol is 8,n,1 not 7,n,1

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Dear all,
In fact, I want to send a command to a robot. The command is typed in text1.text
part of my code is like this:

------------------------------------------------------
Private Sub Text1_KeyPress(keyascii As Integer)
Dim clcom As String, clname As String, clint As Byte, clcode As Integer

If keyascii = vbKeyReturn And Text1.Text <> "" Then
clcom = Text1.Text
clname = UCase(Left(clcom, 2))
clint = Mid(clcom, 3, 3)
Text2.Text = Text2.Text + clname & clint & vbCrLf
MSComm1.Output = Chr$(0) & clname & Chr$(clint) & "."
End If
End Sub
----------------------------------------------------------
so, when I type "FD100" the program will send out
0 "FD" 64 "." (64 is the hex of 100) through the com port

Settings of the MSComm are :
---------------------------------------------------------
MSComm1.RThreshold = 1
MSComm1.InputLen = 0
MSComm1.Settings = "9600,N,8,1"
MSComm1.commPort = 1
MSComm1.PortOpen = True
MSComm1.SThreshold = 0
---------------------------------------------------------
The problem is when I type "FD200", (in fact it's any number 129~254), I got zero at the other end.
I tried using some downloaded dll and it worked. but I couldnt use this dll in my project.
I tried the variable type of clint as byte, string, integer, variant...all dont work!

I really have no idea...
Please kindly give me some idea you can think of. Thanks alot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top