Solved

Sending Text to device in .NET

Posted on 2016-10-19
9
43 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Receiving a string from a WebService Push 21 47
VB.NET - Error - Object not set in Module 4 33
VB: Convert 2 dates to specific format 24 48
ASP/VB email question 4 34
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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