1

So I'm stuck and i need to turn to you experts once more to get me out of my jam.

I have a c# forms project that is going to move a camera via serial port (rs232). (VISUAL STUDIO 2010)

When I use hyperterminal the camera responds as it should.

The device uses ASCII for communiation. I think that the serialPort class converts strings to ASCII when it sends the bytes. If I am wrong about this, Please correct me. When I load my forms project the device does not react. I have tried building the form two ways,

I have used

 SerialPort com = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);  
com.Open();

private void button1_Click(object sender, EventArgs e)
{
com.Write("move left" + "/r/n")
}

I have also used the serialport tool by dropping it into my form and calling the function with

serialPort1.Write("move left" + "/r/n");

I have tried different handshaking and different baud rates. I have made sure that the settings match the settings on the camera too.

I need your help. Can someone explain to me why the device does not respond? It acts as if its not connected.

Does the serial link require some sort of negotiation before it begins (like though a telnet connection)? id so can you point me to that?

I have also tried

serialPort1.write("move left"+serialPort1.newline)

//and

serialPort1. write("move left"+"/n")
eatumup
  • 525
  • 12
  • 26
  • You only posted code that writes, not the code that reads. It is better to post code that you actually have a problem with. – Hans Passant Dec 09 '11 at 00:18
  • 1
    In the code you provide, your slashes are backwards "/n" should be "\n" – TJD Dec 09 '11 at 00:30
  • @eatumup Can you see the signal change with and oscilloscope? Or have you tried connecting another PC with a null modem cable to make sure the software is transmitting? – Jeff Dec 09 '11 at 15:20
  • I wish i had one of those devices for checking. However I don't. but i would think it should work given that if i open hyperterminal it works fine. VS also does successfully open the com port. – eatumup Dec 09 '11 at 16:44

2 Answers2

1

In hyper terminal do you press enter after a command? If so you will need to send the \r\n which is effectively the same as a hitting enter in hyper terminal.

smitec
  • 3,049
  • 1
  • 16
  • 12
  • Oh thank you for mentioning that. I forgot to include that. However same result... Also I have enabled both Dtr and Rts – eatumup Dec 09 '11 at 00:16
  • so you have sent "move left\r\n" with no result? – smitec Dec 09 '11 at 00:17
  • @eatumup Have you tried using the [WriteLine](http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.writeline.aspx) Method. – Mark Hall Dec 09 '11 at 00:25
  • looking at your addition above you haven't added \r and your /n should be \n – smitec Dec 09 '11 at 00:25
  • I was just trying the method but it is causing the application to crash (so for some reason it wont).... It also needs to talk in ascii. from what I've read I get the impression that the method auto converts the string to ascii. Am I right in assuming that? – eatumup Dec 09 '11 at 00:45
  • 1
    slashes should be \ and not / – smitec Dec 09 '11 at 01:04
  • @smitec Well now, don't i just feel silly. I hope that solves my issue. I don't have the camera with me so I have to wait till tomorrow to try that out.. I do have a concern though. Since serialport.newline didn't work i wonder if it will do the trick.. – eatumup Dec 09 '11 at 02:23
  • I fixed the "\" problem but it still does not work. I went to [link]http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx[/link] and downloaded the code and ran that application. I got the same result. Im completely stumped. is there a setting in windows i need to change? I am running windows 7 64 bit. – eatumup Dec 09 '11 at 16:46
1

OK, so I guess i was just too burned out on it. After walking away from the project for a couple of days i found the problem. The DiscardNull property was set to false. It needed to be set to true. Thank you all for your help.

eatumup
  • 525
  • 12
  • 26