473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

RS232 Dilema

Hello,

The church I go to has a data projector (Toshiba TDP-S20) that can be controlled via a serial connection. When it was installed, we connected the projector to the nearest PC (runnings Windows XP) and I found a RS232 software program online that allowed me to control it successfully. To power up the projector, I found I could send the following string of characters:

BlackSmileyFace + PON + BlackHeartSuit (without the plus signs and spaces)

I was able to put the symbols into the transmit textbox by right-clicking within the transmit textbox and choose the symbols from a pop-up ASCII table. I'd click on the Send button and everything was fine.

A few days ago I decided to build a windows app in VB.NET that would allow us to control the projector using various buttons, each button controlling one of the functions like POWER ON, SHUTDOWN, INPUT1, INPUT2, etc, etc. In each case the string of characters needed started with the Black Smiley Face and ended with the Black Heart Suit symbol.

BlackSmileyFace + PON + BlackHeartSuit
BlackSmileyFace + IN2 + BlackHeartSuit

I'm developing the program from my Home Office computer using Visual Studio 2008. The PC used to control the projector and the projector are at a different location.

Simply put, I thought I had it all figured out when I could click on my Power On button and the correct string of characters would appear in my "Code Sent" textbox. I would see the BlackSmileyFace, the string of three function characters (PON, for example) and the BlackHeartSuit symbol. I used the following VB.Net code to get the correct characters to display in my CodeSent textbox on my development PC.

Expand|Select|Wrap|Line Numbers
  1. Dim BlackSmileyFace As Char
  2. Dim BlackHeart As Char
  3. BlackSmileyFace = ChrW("9787")
  4. BlackHeart = ChrW("9829")
  5. CodeSent.Text = BlackSmileyFace + "PON" + BlackHeart
I thought all I had to do was grab what was in the CodeSent textbox and write it to the serial port, something like the following:

Expand|Select|Wrap|Line Numbers
  1. If moRS232.IsOpen Then
  2.      Dim outgoing as string      
  3.      outgoing = CodeSent.Text
  4.      moRS232.WriteLine(outgoing)
  5. End If
This did not work. I tried to send the Turn On command (PON) and the projector did not turn on.

Next, I decided to open the RS232 terminal program I had successfully used to control the projector, enter the Power On command in that program's transmit textbox (using the ASCII table to enter the BlackSmileyFace and BlackHeartSuit symbols in the proper place) and copy that string of characters to my clipboard. I did so.

I pasted that string of characters from my clipboard into my program's CodeSent textbox, clicked on my SEND button and the projector turned on.

I pasted what was in my clipboard into NOTEPAD, copied that, pasted that into my programs CodeSent textbox, clicked on my SEND button and the projector turned on. I then changed the three function command characters (between the two symbols) in my open notepad file to IN1 - to change the projectors input to Input #1 - copied the revised notepad code, pasted it into my CodeSent textbox, clicked on the SEND button and the projector responded appropriately.

So, for some reason, when I try to send the start and stop part of my command code to the projector using ChrW() and sending the command as a string, it doesn't work.

SUMMARY:

This does not work, even though it appears to be display correctly on my development PC:

Expand|Select|Wrap|Line Numbers
  1. BlackSmileyFace + PON + BlackHeartSuit
I generated the BlackSmileyFace using ChrW("9787") and the BlackHeartSuite using ChrW("9829").

I can grab what appears to be exactly the same command string from the working RS232 terminal program and it does work.

I can grab what was copied into or edited within NOTEPAD (the symbols do not appears as the Black Smiley Face and the Black Heart Suit) and that will work in my program.

I wish I could see the code behind what was displaying in NOTEPAD and the working, third-party, RS232 terminal program.

I know that the serial port is opening and closing correctly within my program. I am using the SerialPort class.

Given the above, what VB.NET code would you suggest I use to write the correct command to the projector?

Thanks for your help.
Jan 27 '10 #1
4 5098
tlhintoq
3,525 Expert 2GB
Any time you try sending text and characters you are open to having the operating system 'interpret' them for you. Unicode for example is a text encoding that uses 2 bytes for every character.

Serial on the other hand is all about the bytes. There should be a set of commands that came with the project that tell you what bytes are expected as the commands.
Bytes 96, 17, 155 is the command to power down for conversation sake.
So you want to send bytes, not characters.

When you convert the byte 96 to character 96, then stick it in a text box, then take it back out of a text box, it may no longer be a single byte of 96 - because Windows was 'helpful' to you and turned it into a 2-byte unicode character.
Jan 27 '10 #2
alexis4
113 100+
If I understood correctly then I'd suggest this:

First of all be 100% sure that you have the proper configuration (baudrate, stopbits etc).
Then try to send your frame not from your custom application, but from an existing one (not from windows hyper terminal, try silverlight). If you send the "proper" string and everything is OK, then you don't send what you thing you send from your application and your code needs to be corrected. If the problem remains, then this is not the proper string, or it's the proper string but you need a start and stop byte that you don't know. Either way silverlight will show what is going wrong, because you can then set it up to receive from the projector software so you will see the incoming frame.
Jan 27 '10 #3
OK, I want to send bytes, not characters, to my serial device.

The projector's users manual states:

Communication method - RS-232C: 9600bps, No Parity, Data Length: 8 bits; Stop Bit Length: 1 bit

Communication format: STX (02h) Command (3Byte) ETX (03h)
Only 1 command valid per communication.
Data format: For input commands, only ASCII-compliant all-uppercase alphanumeric characters supported.

It shows the most popular commands, i.e. Power On = PON

So... if I wanted to create my command code within the program and NOT grab it from a textbox, would my code look something like this:

Expand|Select|Wrap|Line Numbers
  1. Dim WithEvents moRS232 As New SerialPort()
  2.  
  3. With moRS232
  4.             .PortName = "COM1"
  5.             .BaudRate = 9600
  6.             .DataBits = 8
  7.             .StopBits = StopBits.One
  8.             .Parity = Parity.None
  9.             .Handshake = Handshake.None
  10.             .ReadTimeout = 1000
  11.             .WriteTimeout = 1000
  12. End With
  13.  
  14. moRS232.Open
  15. Dim msg As Byte() = New Byte(5) {}
  16. msg(0) = &H02  ' start (STX) bit
  17. msg(1) = &H50  ' for "P"
  18. msg(2) = &H4f   ' for "O"
  19. msg(3) = &H4e  ' for "N"
  20. msg(2) = &H03  ' stop (ETX) bit
  21. moRS232.Write(msg, 0, 5)
Jan 27 '10 #4
alexis4
113 100+
At line 20 you should change msg(2) to msg(4). The rest of the code looks OK.
If it won't work, I'm telling you again to verify serial traffic. You do it in 5 minutes and it could save you hours of work. For ASCII-compliant characters hyper terminal is fine.
Jan 28 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dan | last post by:
I wnat to see in browser an status from an device connected on rs232 port The java class for read from serial port is: //Serial.java import java.io.*; import java.util.*; import...
4
by: nchap99 | last post by:
hello, Does anybody know if Microsoft Dot Net supports the RS232 type of connection. As far as I know Visual basic 6 supports RS232 connection format. Thanks,
6
by: Przemo | last post by:
Hi, Do you know some good RS232C class? There is one in VB.NET 101 Examples, but I think it is poor. 1. I can't for e.g. read into my application all data received. I must tell how many...
2
by: AlirezaH | last post by:
Any sample program for rs232 communication?
8
by: Terry Olsen | last post by:
I'm trying to use the RS232 class that was in the Platform SDK (i think). Has anyone else used this with events successfully? Here's what i've got: ====================== Public WithEvents...
13
by: jay.dow | last post by:
I want to write to the pins of an RS232 without using the serial protocol. The use would be every pin could act to complete a circuit in customized hardware. I could use python to communicate...
4
by: Dave Harry | last post by:
I found the RS232 class from MS's 101 VB samples. Writing to the port works fine. (I've got hyperterminal on the other comm port and a crossover cable between COM1 and COM2) The port is opened...
6
by: Henning M | last post by:
Hi all, Im trying to send a command to my uprocessor project, but when i try to read the answer for the uPU I get the same commed I just send to it??? It is as if the command isn't send before I...
3
by: ad | last post by:
I am using VS2005 to develop Web application. How can I receive the data from RS232 of client's computer?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.