Solved

Sending Text to device in .NET

Posted on 2016-10-19
9
45 Views
Last Modified: 2016-10-20
I am trying to send the attached string (or ascii equivalent) to a device, via a serial com port. However I dont know how to reproduce this string in vb

Any help would be appreciated

THanks
0
Comment
Question by:cmdolcet
  • 5
  • 3
9 Comments
 
LVL 33

Expert Comment

by:it_saige
ID: 41850618
No attachment.

-saige-
0
 

Author Comment

by:cmdolcet
ID: 41850624
Sorry
String.PNG
0
 

Author Comment

by:cmdolcet
ID: 41850707
I think there needs to be some conversion, however I am not too sure as to what that conversion is or how to take place.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:cmdolcet
ID: 41850719
I thought I could write it like this....

SerialPort1.Write("SOH" & "V" & "STX" & "01" & "Hello" & "ETX" & vbCr)
0
 
LVL 9

Expert Comment

by:Karen
ID: 41851307
well, you are trying to send non-ascii characters, so you need to change the serial port encoding, i.e.
SerialPort1.Encoding = UTF8Encoding
0
 

Author Comment

by:cmdolcet
ID: 41851358
Could I write the following to the serial port?

 Dim msg As Byte() = New Byte(11) {}
                msg(0) = &H1  ' start (SOH) bit
                msg(1) = &H55  ' start (V) bit
                msg(2) = &H2  ' start (STX) bit
                msg(3) = &H30  ' for "0"
                msg(4) = &H31   ' for "1"         
                msg(5) = &H47   ' for "H"
                msg(6) = &H65   ' for "e"
                msg(7) = &H6c   ' for "l"
                msg(8) = &H6c   ' for "l"
                msg(9) = &H6f   ' for "o"
                msg(10) = &H3  ' stop (ETX) bit
                TelesisSerialPort1.Write(msg, 0, 11)

Open in new window

0
 
LVL 9

Accepted Solution

by:
Karen earned 500 total points
ID: 41851380
Yes I think so, or you could do something like

    Dim utf8 As New UTF8Encoding
    Dim s As String = ChrW(&h1) & ChrW(&h55) & ChrW(&h2) & "01Hello" & ChrW(&h3) 
    Dim encodedBytes As Byte() = utf8.GetBytes(s)
    TelesisSerialPort1.Write(encodedBytes, 0, encodedBytes.Length)

Open in new window

0
 

Author Comment

by:cmdolcet
ID: 41852064
Karen,

the "01" is after the V and before the STX so how would I write that as 01?
0
 
LVL 9

Expert Comment

by:Karen
ID: 41853092
it should be fine to do
ChrW(&h1) & ChrW(&h55) & "01" & ChrW(&h2) & "Hello" & ChrW(&h3)
it should even be fine to do
ChrW(&h1) & "V01" & ChrW(&h2) & "Hello" & ChrW(&h3)
it is just the unprintable characters that you have to do one byte at a time
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
write xml in vb.net 2 32
Write to a printer using vb.net 9 39
Get number of Files in Directory and Sub Directories 2 48
RLDC Reporting in Visual studio 11 30
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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