Hallo, please, I have RX and TX pins at serial cable at my computer connect. In hyper terminal I try, that is all OK, I send and recive data.

In visual basic I send BYTES with code which I send down OK, but when I use
dat = READBYTE
Text2.Text = Str$(dat)

I not view data which I send...I cant read bytes value...please, help me, I have visual basic 5


Private Sub Command1_Click()
'MSComm1.Output = "12345"
'MSComm1.Output = "Test rs232"
'MSComm1.Output = Chr(32 + 3) + Chr(32 + (1532 \ 224)) + Chr((32 + 1532 Mod 224)) & vbCr
MSComm1.Output = (xconvert(3, 1532))
End Sub

Private Sub Form_Load()
Form1.Caption = "App1"
With MSComm1
.Handshaking = 2 - comRTS
.RThreshold = 1
.RTSEnable = True
.Settings = "2400,n,8,1"
.SThreshold = 1
.PortOpen = True
End With
Command1.Caption = "&Print rs232"


End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub

Private Function xconvert(ByVal register As Integer, ByVal xval As Integer) As String
register = 3
xval = 1532

xconvert = Chr(32 + register) + Chr(32 + (xval \ 224)) + Chr((32 + xval Mod 224)) & vbCr

End Function

Private Sub MSComm1_OnComm()

Dim sData As String
If MSComm1.CommEvent = comEvReceive Then
' sdata = MSComm1.Input ' Get data (2 bytes)
' lHighByte = Asc(Mid$(sData, 1, 1)) ' get 1st byte
' lLowByte = Asc(Mid$(sData, 2, 1)) ' Get 2nd byte

' Combine bytes into a word
'lWord = (lHighByte * &H100) Or lLowByte

' Convert value to a string and display
' Label1.Caption = CStr(sData)
' Label1.Caption = CStr(sdata)
End If
'sData = MSComm1.Input
'Label1.Caption = CStr(sData)
'Label1.Caption.Byte = Chr(sData)
'If MSComm1.CommEvent > -1 Then Text1.Text = CStr(sData)

dat = READBYTE

Text1.Text = Text1.Text + dat + " "
Text2.Text = Str$(dat)

End Sub

I become after sending data this:
#&Ü
and I must become number in this format for example:
13 245 32 56

please HELP ME

hi
u can send like this
dim b() as byte
b=convertstr("1234567",vbfromunicode)
mscomm1.output =b

and recive

dim b() as byte
b=msscomm1.input
s=convertstr(s,vbunicode)

Omoridi, thank you for your anwer, thank you for your time.

I try your tip, but he is functioned only for sending in format as you write:

Dim b() As Byte
b = StrConv("34567", vbFromUnicode)
MSComm1.Output = b

And for recive:
s = MSComm1.Input
sData = StrConv(s, vbUnicode) & s

I become only number "3" but not "34567"


BUT


I need recive data in this sending format which is good:
a = (xconvert(3, 1532))

Private Function xconvert(ByVal register As Integer, ByVal xval As Integer) As String
register = 3
xval = 1532
xconvert = Chr(32 + register) + Chr(32 + (xval \ 224)) + Chr((32 + xval Mod 224)) & vbCr
End Function


It is functioned, but recive is BAD:


sData = MSComm1.Input
Text1.Text = sData

I become only: #&Ü

And I must become a numbers.....when I use other program with READBYTE, it is functioned OK...but in this program I cant use READBYTE and :

sData = MSComm1.Input
Text1.Text = sData

NOT WORK as good as SENTBYTE....please what I must do for
sData = MSComm1.Input
Text1.Text = sData
for same function as SENBYTE?

Private Sub mscLocal_OnComm()
Dim s As String
Select Case mscLocal.CommEvent
Case comEvCTS
Case comEvReceive
s = mscLocal.Input
End Select
End Sub

To Send Use
mscLocal.Output = S

and set properties
mscLocal.InputLen=1
mscLocal.InputMode=0
mscLocal.RThreshold=1
mscLocal.Sthreshold=1


Omoridi, thank you for your anwer, thank you for your time.

I try your tip, but he is functioned only for sending in format as you write:

Dim b() As Byte
b = StrConv("34567", vbFromUnicode)
MSComm1.Output = b

And for recive:
s = MSComm1.Input
sData = StrConv(s, vbUnicode) & s

I become only number "3" but not "34567"


BUT


I need recive data in this sending format which is good:
a = (xconvert(3, 1532))

Private Function xconvert(ByVal register As Integer, ByVal xval As Integer) As String
register = 3
xval = 1532
xconvert = Chr(32 + register) + Chr(32 + (xval \ 224)) + Chr((32 + xval Mod 224)) & vbCr
End Function


It is functioned, but recive is BAD:


sData = MSComm1.Input
Text1.Text = sData

I become only: #&Ü

And I must become a numbers.....when I use other program with READBYTE, it is functioned OK...but in this program I cant use READBYTE and :

sData = MSComm1.Input
Text1.Text = sData

NOT WORK as good as SENTBYTE....please what I must do for
sData = MSComm1.Input
Text1.Text = sData
for same function as SENBYTE?

Set this Properties
InputLen=1
InputMode=0
RThershold=1
SThershold=1

Private Sub mscLocal_OnComm()
Dim S as string
Select Case mscLocal.CommEvent
Case comEvCTS
Case comEvReceive
S=mscLocal.Input
End Select
END sub

To Send Data
S="12345"
mscLocal.Output = S

Omoridi, thank you for your anwer, thank you for your time.

I try your tip, but he is functioned only for sending in format as you write:

Dim b() As Byte
b = StrConv("34567", vbFromUnicode)
MSComm1.Output = b

And for recive:
s = MSComm1.Input
sData = StrConv(s, vbUnicode) & s

I become only number "3" but not "34567"


BUT


I need recive data in this sending format which is good:
a = (xconvert(3, 1532))

Private Function xconvert(ByVal register As Integer, ByVal xval As Integer) As String
register = 3
xval = 1532
xconvert = Chr(32 + register) + Chr(32 + (xval \ 224)) + Chr((32 + xval Mod 224)) & vbCr
End Function


It is functioned, but recive is BAD:


sData = MSComm1.Input
Text1.Text = sData

I become only: #&Ü

And I must become a numbers.....when I use other program with READBYTE, it is functioned OK...but in this program I cant use READBYTE and :

sData = MSComm1.Input
Text1.Text = sData

NOT WORK as good as SENTBYTE....please what I must do for
sData = MSComm1.Input
Text1.Text = sData
for same function as SENBYTE?

Set this Properties
InputLen=1
InputMode=0
RThershold=1
SThershold=1

Private Sub mscLocal_OnComm()
Dim S as string
Select Case mscLocal.CommEvent
Case comEvCTS
Case comEvReceive
S=mscLocal.Input
End Select
END sub

To Send Data
S="12345"
mscLocal.Output = S

OMORIDI, thank you very much, I must try IT because two day I solve this trouble and I cant solve it. Thanky you for your time and I wish you nice day. I go try IT.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.