• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • Last Modified:

how to send characters to com port..

is very simple in another language..

of course, in VB, too.

But in vb, i don't know how to send

above 128.(0xfe, 0xff, 0x80..etc)

thank you..



0
can9999
Asked:
can9999
  • 2
1 Solution
 
TimCotteeCommented:
These characters can be represented by chr$(128) etc so a string to the comm port can be

MSComm1.Output "This is a message string including" & chr$(128) & " and other odd things such as " & chr$(241)

0
 
can9999Author Commented:
Please, try this..

MsgBox "{" & chr$(128) & "}"

you can see 128th character between "{ " and "}"

ok ,, next ..

MsgBox "{" & chr$(129) & "}"

you can't see any characters besides "{".

What do you think about this problem ?

.....

thank you !
0
 
TimCotteeCommented:
This is true, it does not necessarily mean that the characters have not been sent to the serial port though. An alternative method is to use a byte array to send binary data.

An example of this is shown below, add an mscomm control and a command button to a new form. Run it and click the command button. The values in the msgbox display will be garbage but the correct characters will in fact be output to the serial port.

You could extend this to send both character data and byte data to the port either by parsing your character strings into a byte array or by using a sequence of output commands.

Dim aryOutput() As Byte

Private Sub Command1_Click()
    ReDim Preserve aryOutput(10)
    For intCount = 0 To 9
        aryOutput(intCount) = (128 + intCount)
    Next
    MsgBox (aryOutput)
    MSComm1.PortOpen = True
    MSComm1.Output = aryOutput
    MSComm1.PortOpen = False
End Sub
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now