Fez Hydra and RS-232 module

I am experiencing a weird problem, with Fez Hydra and GHI RS-232 module. I am trying to send some data from PC to the board, just to test the serial connection. I have checked all serial parameters to be the same on both ends. But, had no luck to fire DataReceived event of serial port on the board. I put a check point at the first line of the method to catch if the method runs, but it never happened. I used a sniffer cable between the PC and the boards, to make sure that the PC sends data properly to the port. What made me confused is when the cable is disconnected from RS-232 Module, the sniffer application shows data transmission from PC out. As soon as I connect the cable to the RS-232 module it stops sending, unless I unplug the cable again from the module. Here is my code:

        void ProgramStarted()
        {

            RunProgram();
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
            
        }

        void RunProgram()
        {
            rs232.Initialize(19200, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 8, GT.Interfaces.Serial.HardwareFlowControl.NotRequired);
            rs232.serialPort.Open();
            rs232.serialPort.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(sp_DataReceived);
        }

        DateTime dateTimeStart;
        public void sp_DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData data)
        {
            dateTimeStart = DateTime.Now;

            if (rs232.serialPort.BytesToRead > 0)
            {
                byte[] byteRxBuffer = new byte[rs232.serialPort.BytesToRead];
                rs232.serialPort.Read(byteRxBuffer, 0, byteRxBuffer.Length);
            }
        }

I have attached a picture of my setup as well, if it helps. Any ideas or suggestions about what is happening here? Thanks.

@ Afshin - This issue has been logged, and is awaiting verification.

Hi Afshin,

I figured out your problem - there’s only wires on ONE of those Hydra’s ! :slight_smile:

Nice family of boards you have!

Hi Brett,

I wish it was the problem.

Thanks by the way :wink:

Sounds like a classic null-modem vs straight cable issue: I suspect that the Tx pin from your computer is wired to the Hydra’s Tx pin instead of its Rx pin.

That’s why it works until you plug in the board, which shorts the Tx pin to the Rx pin (I suspect).

Try flipping Tx and Rx on one side of the cable and you should be good to go!

I have the same problem with the DataReceived event on the same board.

Now if I use the following loop I can data that has been sent to the bord:

while (true)
{
byte[] b = new byte[rs232.serialPort.BytesToRead];
rs232.serialPort.Read(b, 0, b.Length);
foreach (var b1 in b)
{
Debug.Print(b1.ToString());
}
}

I’m using the netmf4.3 package.

EDIT: For some reason you have to set: rs232.serialPort.AutoReadLineEnabled = true;

After that the datareceived event works just great!

Also you might not need:

void RunProgram()
{
rs232.Initialize(19200, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 8, GT.Interfaces.Serial.HardwareFlowControl.NotRequired);
rs232.serialPort.Open();
rs232.serialPort.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(sp_DataReceived);
}

instead use:

void RunProgram()
{
rs232.Initialize(19200, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 8, GT.Interfaces.Serial.HardwareFlowControl.NotRequired);
rs232.serialPort.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(sp_DataReceived);
}

by default when you use:

rs232.Initialize(19200, GT.Interfaces.Serial.SerialParity.None, GT.Interfaces.Serial.SerialStopBits.One, 8, GT.Interfaces.Serial.HardwareFlowControl.NotRequired);

it will open the port.

Thanks. Did wonder how to format the code :slight_smile: