i have a serial monitor program for my fez spider , but debugging it , it only starts after adding or deleting a breakpoint in vs2010 ?
New project? Latest SDK?
new projekt, sdk 4.1.
Very unusual. Maybe try 4.2
so here’s a sequence, can you tell us how it works? Deploy your code, that contains debug.print statements. Once it’s running, unplug device. Open MFDeploy. Connect device. Then, in MFDeploy, connect to the USB device and see if your debug print statements appear; I am expecting them to.
here is the code, it is a simple bridge between a usbserialport and a usbhost. with a sniffer on the cdc serialport to read the trafffic on the computer in a serial program, i used serialport in vb.net from codeplex in a serial port next to debugging on 1 usb port.
program generated
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by the Gadgeteer Designer.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using Gadgeteer;
using GTM = Gadgeteer.Modules;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.USBClient;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.System;
namespace SerialUsbClientmodule
{
public partial class Program : Gadgeteer.Program
{
// GTM.Module defintions
static Gadgeteer.Modules.GHIElectronics.UsbSerial usbSerial;
Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClient;
//Gadgeteer.Modules.GHIElectronics.UsbHost usbHost;
public static void Main()
{
//Important to initialize the Mainboard first
Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
Program program = new Program();
program.InitializeModules();
program.ProgramStarted();
program.Run(); // Starts Dispatcher
}
private void InitializeModules()
{
// Initialize GTM.Modules and event handlers here.
usbClient = new GTM.GHIElectronics.UsbClientDP(1);
//usbHost = new GTM.GHIElectronics.UsbHost(3);
usbSerial = new GTM.GHIElectronics.UsbSerial(8);
}
}
}
using System.Threading;
using System;
using System.Text;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.USBClient;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.System;
// http://www.tinyclr.com/codeshare/entry/335
// http://www.tinyclr.com/codeshare/entry/335
namespace SerialUsbClientmodule
{
partial class Program
{
//static USBC_CDC cdc = USBClientController.StandardDevices.StartCDC_WithDebugging(); // adds cdc next to debug on usb
//static USBH_SerialUSB serialUSBHost; // adds usbhost as serial port = declares cdc
private Thread USBSerRX, USBSerTX;
static byte HostorClient;
static USBC_CDC cdc = USBClientController.StandardDevices.StartCDC_WithDebugging(); // adds cdc next to debug on usb
static USBH_SerialUSB serialUSBHost; // adds usbhost as serial port = declares cdc
static bool jilles = true;
void ProgramStarted()
{
Debug.Print("Program Started");
usbSerial.Configure(115200,
GT.Interfaces.Serial.SerialParity.None,
GT.Interfaces.Serial.SerialStopBits.One,
8);
usbSerial.SerialLine.ReadTimeout = 0;
usbSerial.SerialLine.Open();
// declare usbhost
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
USBSerRX = new Thread(clienttohost);
USBSerTX = new Thread(hosttoclient);
USBSerRX.Start();
USBSerTX.Start();
}
private static void clienttohost()
{
int NumberOfBytesToRead ;
byte[] readInputBuffer = new byte[256];
HostorClient = 1;
while (jilles)
{
NumberOfBytesToRead = usbSerial.SerialLine.Read(readInputBuffer, 0, 256);
if (NumberOfBytesToRead > 0)
{
serialUSBHost.Write(readInputBuffer, 0, NumberOfBytesToRead);
serialUSBHost.Flush();
cdcwrite1(readInputBuffer, NumberOfBytesToRead, HostorClient);
}
}
}
private static void hosttoclient()
{
while (jilles)
{
byte[] UsbHostReadBuffer = new byte[256];
byte HostorClient = 2;
int NumberOfReadBytes;
NumberOfReadBytes = serialUSBHost.Read(UsbHostReadBuffer, 0, 256);
if (NumberOfReadBytes > 0)
{
usbSerial.SerialLine.Write(UsbHostReadBuffer, 0, NumberOfReadBytes);
cdcwrite1(UsbHostReadBuffer, NumberOfReadBytes, HostorClient);
}
}
}
private static void cdcwrite1(byte[] readinputbuffer, int bufferlength, byte HostorClient)
{
if (USBClientController.GetState() != USBClientController.State.Running)
{
Debug.Print("Waiting to connect to PC...");
}
else
{
byte[] output = new byte[bufferlength + 1];
output[0] = HostorClient ; // 1 gives terminal the info that it is coming from usbserial 2 from usbhost
Array.Copy(readinputbuffer, 0, output, 1, bufferlength);
cdc.Write(output, 0, output.Length);
}
}
static void DeviceConnectedEvent(USBH_Device device)
{
Debug.Print("Device connected");
switch (device.TYPE)
{
case USBH_DeviceType.Serial_FTDI: // FTDI connected
serialUSBHost = new USBH_SerialUSB(device, 115200,
System.IO.Ports.Parity.None, 8,
System.IO.Ports.StopBits.One);
serialUSBHost.Open();
//serialUSBThread = new Thread(SerialUSBThread);
//serialUSBThread.Start();
break;
case USBH_DeviceType.Unknown: // SiLabs but not recognized
// force SiLabs
USBH_Device silabs = new USBH_Device(device.ID,
device.INTERFACE_INDEX,
USBH_DeviceType.Serial_SiLabs, device.VENDOR_ID,
device.PRODUCT_ID, device.PORT_NUMBER);
serialUSBHost = new USBH_SerialUSB(silabs, 9600,
System.IO.Ports.Parity.None, 8,
System.IO.Ports.StopBits.One);
serialUSBHost.Open();
//serialUSBThread = new Thread(SerialUSBThread);
//serialUSBThread.Start();
break;
}
} // void
}
}
indeed it works with netmf 4.2 , i am glad i ordered one serial client to much because the cdc isnt supported anymore on the usb debug port, my laptop has only ther usb ports.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by the Gadgeteer Designer.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using Gadgeteer;
using GTM = Gadgeteer.Modules;
namespace UsbToSerialNetMf42
{
public partial class Program : Gadgeteer.Program
{
// GTM.Module definitions
Gadgeteer.Modules.GHIElectronics.UsbSerial usbSerial;
Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClientDP;
Gadgeteer.Modules.GHIElectronics.UsbSerial usbSerial1;
public static void Main()
{
//Important to initialize the Mainboard first
Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
Program program = new Program();
program.InitializeModules();
program.ProgramStarted();
program.Run(); // Starts Dispatcher
}
private void InitializeModules()
{
// Initialize GTM.Modules and event handlers here.
usbClientDP = new GTM.GHIElectronics.UsbClientDP(1);
usbSerial1 = new GTM.GHIElectronics.UsbSerial(4);
usbSerial = new GTM.GHIElectronics.UsbSerial(8);
}
}
}
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHI.Premium.USBHost;
using GHI.Premium.USBClient;
using GHI.Premium.System;
namespace UsbToSerialNetMf42
{
public partial class Program
{
private Thread USBSerRX, USBSerTX;
static byte HostorClient;
static USBH_SerialUSB serialUSBHost; // adds usbhost as serial port
static bool Hconnected = false;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
/*******************************************************************************************
Modules added in the Program.gadgeteer designer view are used by typing
their name followed by a period, e.g. button. or camera.
Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
button.ButtonPressed +=<tab><tab>
If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
timer.Tick +=<tab><tab>
timer.Start();
*******************************************************************************************/
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
usbSerial.Configure(115200,
GT.Interfaces.Serial.SerialParity.None,
GT.Interfaces.Serial.SerialStopBits.One,
8);
//usbSerial.SerialLine.ReadTimeout = 0;
usbSerial.SerialLine.Open();
usbSerial1.Configure(115200,
GT.Interfaces.Serial.SerialParity.None,
GT.Interfaces.Serial.SerialStopBits.One,
8);
//usbSerial.SerialLine.ReadTimeout = 0;
usbSerial1.SerialLine.Open();
// declare usbhost
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
USBSerRX = new Thread(clienttohost);
USBSerTX = new Thread(hosttoclient);
USBSerRX.Start();
USBSerTX.Start();
} // programstarted
private void clienttohost()
{
int NumberOfBytesToRead;
byte[] readInputBuffer = new byte[256];
HostorClient = 1;
while (Hconnected)
{
NumberOfBytesToRead = usbSerial.SerialLine.Read(readInputBuffer, 0, 256);
if (NumberOfBytesToRead > 0)
{
serialUSBHost.Write(readInputBuffer, 0, NumberOfBytesToRead);
serialUSBHost.Flush();
cdcwrite1(readInputBuffer, NumberOfBytesToRead, HostorClient);
}
}
}
public void hosttoclient()
{
while (Hconnected)
{
byte[] UsbHostReadBuffer = new byte[256];
byte HostorClient = 2;
int NumberOfReadBytes;
NumberOfReadBytes = serialUSBHost.Read(UsbHostReadBuffer, 0, 256);
if (NumberOfReadBytes > 0)
{
usbSerial.SerialLine.Write(UsbHostReadBuffer, 0, NumberOfReadBytes);
cdcwrite1(UsbHostReadBuffer, NumberOfReadBytes, HostorClient);
}
}
}
private void cdcwrite1(byte[] readinputbuffer, int bufferlength, byte HostorClient)
{
if (USBClientController.GetState() != USBClientController.State.Running)
{
Debug.Print("Waiting to connect to PC...");
}
else
{
byte[] output = new byte[bufferlength + 1];
output[0] = HostorClient; // 1 gives terminal the info that it is coming from usbserial 2 from usbhost
Array.Copy(readinputbuffer, 0, output, 1, bufferlength);
usbSerial1.SerialLine.Write(output, 0, output.Length);
}
}
static void DeviceConnectedEvent(USBH_Device device)
{
Debug.Print("Device connected");
switch (device.TYPE)
{
case USBH_DeviceType.Serial_FTDI: // FTDI connected
serialUSBHost = new USBH_SerialUSB(device, 115200,
System.IO.Ports.Parity.None, 8,
System.IO.Ports.StopBits.One);
serialUSBHost.Open();
Hconnected = true;
//serialUSBThread = new Thread(SerialUSBThread);
//serialUSBThread.Start();
break;
case USBH_DeviceType.Unknown: // SiLabs but not recognized
// force SiLabs
USBH_Device silabs = new USBH_Device(device.ID,
device.INTERFACE_INDEX,
USBH_DeviceType.Serial_SiLabs, device.VENDOR_ID,
device.PRODUCT_ID, device.PORT_NUMBER);
serialUSBHost = new USBH_SerialUSB(silabs, 9600,
System.IO.Ports.Parity.None, 8,
System.IO.Ports.StopBits.One);
serialUSBHost.Open();
//serialUSBThread = new Thread(SerialUSBThread);
//serialUSBThread.Start();
break;
}
} // void
}
}