cmdolcet
asked on
Sending Text to device in .NET
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
Any help would be appreciated
THanks
ASKER
Sorry
String.PNG
String.PNG
ASKER
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.
ASKER
I thought I could write it like this....
SerialPort1.Write("SOH" & "V" & "STX" & "01" & "Hello" & "ETX" & vbCr)
SerialPort1.Write("SOH" & "V" & "STX" & "01" & "Hello" & "ETX" & vbCr)
well, you are trying to send non-ascii characters, so you need to change the serial port encoding, i.e.
SerialPort1.Encoding = UTF8Encoding
SerialPort1.Encoding = UTF8Encoding
ASKER
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)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Karen,
the "01" is after the V and before the STX so how would I write that as 01?
the "01" is after the V and before the STX so how would I write that as 01?
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
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
-saige-