Main Site Documentation

E-block serial2USB


#1

When you are using this e-block, what COM port is it hooked up to? I tried to use the couple of tutorial examples, and I am not having any success. Is there a better example for using the e-block with my Panda 2 board?


#2

Hook it up to whatever your code is using. It is probably COM21 which is D0 and D1.


#3

Below is the example code that was in the tutorial, I am not getting any thing on my terminal screen. The program below uses “SerialPort UART = new …” to set up COM1, System.IO.Ports reference knows about the FEZ Panda 2 location for Tx\Rx? The example program is not very clear as to how this works with the FEZ Panda 2 board. I think it needs some more explanation.


using System.Threading;
using System.IO.Ports;
using System.Text;

namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            SerialPort UART = new SerialPort("COM1", 115200);
            int read_count = 0;
            byte[] rx_byte = new byte[1];

            UART.Open();
            while (true)
            {

                // read one byte
                read_count = UART.Read(rx_byte, 0, 1);
                if (read_count > 0)// do we have data?
                {
                    // create a string
                    string counter_string =
                            "You typed: " + rx_byte[0].ToString() + "\r\n";
                    // convert the string to bytes
                    byte[] buffer = Encoding.UTF8.GetBytes(counter_string);
                    // send the bytes on the serial port
                    UART.Write(buffer, 0, buffer.Length);
                    //wait...
                    Thread.Sleep(10);
                }
            }
        }
    }
}



#4

What part is not clear? It uses COM1 as the code say s and you are using Panda II and here is the user manual (from Panda II page) http://www.ghielectronics.com/downloads/FEZ/Panda_II/FEZ_Panda_II_UserManual.pdf showing you exactly where COM1 pins are. Panda II also have COM1 pins labeled right on the circuit board http://www.ghielectronics.com/images/catalog/256-4_large.jpg

What else is missing?


#5

@ r_sad

Tell us about your setup. Do you use FEZ Connect shield?


#6

Yes, I have the e-block connected to the FEZ Connect shield on my Panda 2 board. The e-block Rx connector cable is plugged into the Di0 Rx connector, and the Tx connector cable is plugged into the Di1 Tx connector, on the Connect shield. When I plugged the USB cable into the e-block, Win 7 came up with with a COM11 port which is what I use for my terminal program, which shows it is a live port. When I have the Panda UART program running, and I am in the terminal program, hitting a key on the keyboard, the Tx LED on the e-block lights up, so that part of it is doing something. According to the example program, it is supposed to echo back a key stroke, I do not get anything on the screen.

The only thing that I did not try is connecting the e-block Rx connection to the Tx connection on the Connect shield. Since it was not mentioned in the tutorial, I did not try it. I also have the Connect shield set on the 5V selection. So at this point I am not sure what the next step is.


#7

Yes, try that.


#8

Yes, that made it work. Now the question is, did the e-block itself get wired incorrectly? If not, then that was a serious oversight in the tutorial. I made a terrible assumption, I thought that the e-block made the Rx/Tx connection conversion.

Now I have to figure how to get the program to show the actual key letter, and not the number value of the key. That should make it a little more intuitive for the beginners.


#9

Generally speaking the Tx of one device connects to the Rx of another device. It does seem counter intuitive as we are used to doing things like plugging ‘headphones’ into a ‘headphone’ jack. But when you think about it it makes sense connecting a transmitter of one device to the receiver of and other device.


#10

I am using a Fez domino with the connect shield. In visual studio it does not get past “preparing to deploy assemblies to the device”.

Also, do you still have to ground the MODE pin if your using this eblock. If so, where does the jumper wire go?


#11

@ TweedyMK

Lets start with something simple - default application that is created for you by visual studio.

Are you able to deploy that application?


#12

I started a new Fez Domino application, selected the COM1 Serial port in properties and ran a new instance of it. However, it still does not get past “preparing to deploy assemblies to the device”


#13

You have to use USB.


#14

I am trying to create a USBC_KEYBOARD project so I should be using the serial port not USB


#15

Ok, to use COM for deployment you need to connect MODE pin to ground.


#16

OK, how is it done if using the domino and connect shield? The domino has two holes for MODE.


#17

The domino has a location for a JUMPER. You solder in a twin-post header and then bridge those two posts. If you check the scematic you’d find one is GND


#18

Thank you, I have been able to resolve the problem


#19

When I go to the MSDN site for help, especially to get information about UART.Read(), and UART.Write(), I do not find anything useful. Where can I find the info?

Specifically what I am trying to do is grab a keypress (‘a’, or ‘1’, …, etc) from a terminal program, compare it within an if() loop, and then light an LED on the FEZ Panda 2 board. I can not get around the read_count = UART.Read(rx_byte, 0, 1) problem, it supplies an ‘int’ value which I cannot figure out as to how to compare it to ‘char’ value (‘a’, or ‘1’, …, etc) . Any help would be appreciated.


using System.Threading;
using System.IO.Ports;
using System.Text;
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

namespace MyUART1
{
    public class Program
    {
        static OutputPort MyLEDG = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.An3, false);

        public static void Main()
        {
           // MyLEDG.Write(false);
            SerialPort UART = new SerialPort("COM1", 115200);
           // int read_count = 0;
            int read_count;
            byte[] rx_byte = new byte[1];
           
            

            UART.Open();
            while (true)
            {

                read_count = UART.Read(rx_byte, 0, 1);
               // if (read_count > 0)
               
                if (read_count > 0)
                {
                 //   string counter_string =
                 //       "You typed: " + rx_byte[0].ToString() + "\r\n";
                 //   byte[] buffer = Encoding.UTF8.GetBytes(counter_string);
                 //   UART.Write(buffer, 0, buffer.Length);
                   
                   
                    MyLEDG.Write(true);
                    Thread.Sleep(300);

                    MyLEDG.Write(false);
                    Thread.Sleep(300);
                    
                }
            }
        }

    }
}



#20

You could not find anything useful on the serial port on MSDN. How did you search?

http://msdn.microsoft.com/en-us/library/ee436108.aspx

The read statement returns the number of chars read, not the character received. The byte value of the char is in rx_byte.

In the example you posted there is the following statement:

byte[] buffer = Encoding.UTF8.GetBytes(counter_string);

This statement converts a string into an array of bytes. Would it be nice if there was something like the following?:

char[] c_buffer = Encoding.UTF8.GetChars(rx_byte);