Solved

Sending Text to device in .NET

Posted on 2016-10-19
9
38 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
 

Author Comment

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

SerialPort1.Write("SOH" & "V" & "STX" & "01" & "Hello" & "ETX" & vbCr)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now