Can't seem to send out data via Serial on Spider

I tried the following two test codes for sending data on FEZ Spider socket 8, pin 4, but I can’t seem to be picking up any data on the pin. I have the pin connected to a USB to TTL module that I have tested to work, both send and receive. No conpilation or runtime errors.


            GT.Socket socket = GT.Socket.GetSocket(8,true,null,null);
            GTI.Serial serial = new GTI.Serial(socket, BAUDRATE, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired, null);
            serial.Open();
            //good idea to pause a bit before writing
            Thread.Sleep(200);
            serial.Write("hello");
            serial.WriteLine("test.");
            serial.Close();

=======================================================


            SerialPort UART2 = new SerialPort("COM3", 9600);
            UART2.DataBits = 8;
            UART2.Parity = Parity.None;
            UART2.StopBits = StopBits.One;

            int counter = 0;


            while (!done)
            {
                // create a string
                string counter_string = "Count: " + counter.ToString() + "\r\n";
                // convert the string to bytes
                byte[] buffer = Encoding.UTF8.GetBytes(counter_string);
                // send the bytes on the serial port
                UART2.Open(); 
                UART2.Write(buffer, 0, buffer.Length);
                UART2.Close();
                // increment the counter;
                counter++;
                //wait...
                Thread.Sleep(1000);

            }

Just putting this out there… any chance you have RX and TX crossed? Or baud rate on the PC set wrong?

Second suggestion, link RX and TX on your Fez and see if you get echo characters back to your app.

The other thing I would not do is open and close the UART so much (in your 2nd code snippet). Open before the loop, close after the loop. Maybe a pause before the close() in your first example will help too - it’s possible the UART isn’t flushing the data before it gets closed and it may not like that…

I have not tried to receive with the spider yet. I did the tx-rx cross on the PC side and it works.
I had originally opened and closed outside the loop. It didn’t work, so I put it inside to see if the buffer would flush.

did you try flush() method to flush the data? :slight_smile:

I’d fire up a quick read/write test and send from one side and make sure you get the data come in when bridging RX/TX, to prove that it’s working. That way you can focus elsewhere, and you can also send data from the PC and know it’s visible.

Are you testing with a terminal program on the PC side? If not, I’d suggest trying that too, more flexibility while you’re sorting this out.

Can you make sure you send a BIG packet of data (over 64 bytes) as I’ve seen problems with USB/serial converters that have a buffer in them that doesn’t flush cleanly either.

I’ll try that next.
I’m using a terminal program on the PC. With the lines crossed, I get data when I type. With echo on I get 2 of every letter typed.
Thank you.