none
Strange serial data at my PC hyperterminal, sending data from laptop using VS 2008 RRS feed

  • Question

  • Greetings !

     I am using Visual Studio 2008 and running the following code for serial communication of my laptop to PC. I copied this code from the following link  System.IO.SerialPort sample in V C++ Express

    // moe.cpp : main project file.
    
    #include "stdafx.h"
    
    using namespace System;
    using namespace System::IO::Ports;
    
    
    int main()
     {
         SerialPort^ serialPort = gcnew SerialPort(
             L"COM27",
             57600,
             Parity::None,
             8,
             StopBits::One);
    
             serialPort->Open();
    int y =1;
         serialPort->WriteLine("Hello World" );
    
         serialPort->Close();
    
         return 0;
     }
    Problem is that I recieve weird charachters on my hyperterminal. How should I remove this error? What might be the posible mistake I am making? Thanks !
    • Moved by Helen Zhao Monday, June 18, 2012 10:03 AM (From:Visual C++ General)
    Saturday, June 16, 2012 2:59 PM

All replies

  • Try a lower and more common bitrate (19200, 38400, 9600). Still see garbage?

    (this is besides of a common mistake of not exactly matching the settings on the other side :)

    Also, try to insert a delay before serialPort->Close()  in case the Write in the CLI library works asynchronously; so the port won't be closed while the data is still going. 

    -- pa



    Dear Pavel A, I tried using different baud rates, But I havent been able to troubleshoot the problem yet. Sometimes I see no data on the terminal, I executed the code several times.

    By changing various baudrates, like 2400 and 38400, sometimes I see garbage and sometimes nothing at all.

    I have even tried it with delays, for instance I modified the code a bit,using Sleep() function defined in windows.h

    // moe.cpp : main project file.
    
    #include "stdafx.h"
    #include<windows.h>
    #include"stdio.h"
    
    using namespace System;
    using namespace System::IO::Ports;
    
    
    int main()
     {
         SerialPort^ serialPort = gcnew SerialPort(
             L"COM27",
             38400,
             Parity::None,
             8,
             StopBits::One
    		 );
             serialPort->Open();
    	     printf("Port Opens    ");
    
             Sleep(2);
             serialPort->WriteLine("hellooo");
    	     printf("3");
             printf("Hello World");	
    
    	 Sleep(1); //this is the delay u suggested to insert
         serialPort->Close();
    	
         return 0;
     }


    I have even changed the settings From Device Manager>USB to Serial Port 27>Properties>Port setting> 38400

    and   Device Manager>USB to Serial Port 27>Properties>Port setting>Advanced>Transmit and Receive Buffer to 1(low).

    I did this on both sides, my laptop the sender, and PC , the receiver.

    Please guide me further and help me solve the problem. Thanks a lot !




    Sunday, June 17, 2012 3:04 PM
  • For COM ports above COM9 you probably need a device name like

    ""\\\\.\\COM27"

     

    Sunday, June 17, 2012 4:23 PM
  • For COM ports above COM9 you probably need a device name like

    ""\\\\.\\COM27"

     

    I tried using that , but I get the following error :

    "Additional information: The port name cannot start with '\'."

    But the problem has finally been solved. I replaced my USB to serial Converter with a new one and it works Great :) I am getting correct data now with the latest code that I posted. Thanks everyone for your help :)Stay blessed 

    Sunday, June 17, 2012 4:49 PM
  • Hi Ready_to_Send,

    According to your description, I'd like to move this thread to .NET Base Class Library forum for better support.

    Thanks for your understanding.
    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 10:02 AM
  • Hi Ready_to_Send

    What flow control are you using if any?

    The default property value for the SerialPort component is 'None'

    The values for the HandShaking Property are

    None, XonXoff. RequestToSend and RequestToSendXonXoff.

    This setting, like the baud rate must be the same for both for the DTE and DCE.

    Also check the cable between your laptop and PC , it must be a Null Modem Cable. 

    Here's a link that may help you understand more about serial port communications

    http://www.lvr.com/serport.htm

    Milton


    MFN

    Tuesday, June 19, 2012 10:37 PM