USB Host of FEZ Spider as Serial USB

All you need to do now is con_Read and or com_Write. What is difficult?

I have to send send differnent commands like

sendCommand("SCIP2.0", (int)Timeout.First, true);

To tell the LRF to send me data and than to read the data
and the writte and read command always wants to know the size of the buffer
this is not realy clear to me

Is there a wiki for read and writte havn’t found it

what are the components in the “SendCommand” you showed above?

Since you’ve already communicated to the LRF when you had it connected to your PC and with your Windows app, show us the commands that talk to the serial port - that’s what you’re going to need to alter to work on the serial port on the Fez.

Depending on the command structure and response mechanisms, you might need something like this:

                    command = "YourOutputSerialCommandGoesHere";
                    Debug.Print("about to send " + command);
                    response = SendReceive(com1, command);
                    Debug.Print("Got back " + response);

In this case SendRecieve does all the hard work of sending the command and waiting for the response (or timing out) but it just does com1.Write and com1.Read.

public static bool Connect(string device, int baudrate)

            con_.PortName = device;
            con_.BaudRate = baudrate;
            // !!!

            int[] available_baudrate = new int[] { 19200, 115200, 38400 };
            foreach (int try_baudrate in available_baudrate)

                int ret = sendCommand("SCIP2.0", (int)Timeout.First, true);



            sendCommand("BM", (int)Timeout.First, true);

            return true;

this a little part of my windows programm. I have to send SCIP2 that the LRF works with that and wait if the connection is ok then I should send the mode in which he should work and then reading the data and decoding it.

When you say only com1 do you mean that it is not possible with USB host because USBH is com0

The next few days are exams so I’m not able to have much time to work on it but I will keep thinking of ot :slight_smile:

Maybe on this site its getting more clear how the LRF has to communicate

you still didn’t disclose what sendCommand does?!

My com1 example was just an example. I haven’t set up a USB connection but it should just be a serial port.

The sendcommand should send the LRF the mode like “Laser on” or “start measuring” and then read the data.

There are I think some mistakes in the program, but the function stayes the same.

private static int sendCommand(string command, int timeout, bool read_lf)
            con_.ReadTimeout = timeout;


                string line = con_.ReadLine();

                if (line.CompareTo(command) != 0)

                    return -1;

                line = con_.ReadLine();

                if (read_lf)

                if (line.Length >= 3)
                    return Convert.ToInt32(line.Substring(0, 2), 16);
            catch (TimeoutException)
            return -2;

The last few weeks I had no time to work on my project
but now I start again :smiley:

Now I would like to send a string to my LRF but if I write serialUSB.Write its only possible to send bytes
is there a way to send a string over USB host??


I think that I have a connection to my Laser range finder but my problem is now that I receive data and would need to read it line per line but there is no Readline command.
Maybe somebady knows how to solve that??


the picture shows the send command

the way to debug this is to write the serial characters into a buffer and make sure you get them (in fact, if you just debug.print everything you read, you’ll at least see the text is arriving correctly.

The way to handle the reading will depend on what your data comes in like. Since you cant just “Readline” you need to read until you hit something you recognise and handle that. Here’s a good thread that has something you can probably use pretty easily (look for reply 5 from William to me and you’ll probably have exactly what you want)

good luck now!


Is there a way to see if the command was send ??
If I execute the code and debugg it the programm writtes that some code was passed and I’m not sure if the LRF gets the commands