Solved

Sending Text to device in .NET

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

Expert Comment

by:it_saige
Comment Utility
No attachment.

-saige-
0
 

Author Comment

by:cmdolcet
Comment Utility
Sorry
String.PNG
0
 

Author Comment

by:cmdolcet
Comment Utility
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
Comment Utility
I thought I could write it like this....

SerialPort1.Write("SOH" & "V" & "STX" & "01" & "Hello" & "ETX" & vbCr)
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Expert Comment

by:Karen
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

12 Experts available now in Live!

Get 1:1 Help Now