Solved

Sending Text to device in .NET

Posted on 2016-10-19
9
51 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 34

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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