Hi, I want to get my fez cobra in the internet, I have written following code:
public class Modem
{
private USBH_Device modem;
public Modem()
{
USBHostController.DeviceConnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceConnectedEvent);
USBHostController.DeviceDisconnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceDisconnectedEvent);
}
private void USBHostController_DeviceDisconnectedEvent(USBH_Device device)
{
if (PPP.IsEnabled)
{
PPP.Disable();
}
}
private void USBHostController_DeviceConnectedEvent(USBH_Device device)
{
if (device.PRODUCT_ID == 22 && device.VENDOR_ID == 6610 && device.INTERFACE_INDEX == 2)
{
modem = device;
Thread tInit = new Thread(new ThreadStart(this.InitilizeModem));
tInit.Priority = ThreadPriority.BelowNormal;
tInit.Start();
}
}
private static bool Write(USBH_SerialUSB device, string command, string response)
{
return Write(device, Encoding.UTF8.GetBytes(command + "\r\n"), response);
}
private static bool Write(USBH_SerialUSB device, byte[] command, string response)
{
string read_buffer = string.Empty;
byte[] buffer = new byte[1024];
byte[] temp = new byte[1];
int index = 0;
byte count = 0;
device.Write(command, 0, command.Length);
device.Flush();
while (true)
{
device.Read(temp, 0, 1);
if (temp[0] == '\r' || temp[0] == '\n')
{
string temptext = new string(Encoding.UTF8.GetChars(buffer));
if (response == temptext)
{
return true;
}
else
{
if (count == 3)
{
return false;
}
else
{
count++;
index = 0;
buffer = new byte[1024];
}
}
}
else
{
buffer[index] = temp[0];
index++;
}
}
}
private void InitilizeModem()
{
USBH_Device zte = new USBH_Device(this.modem.ID, this.modem.INTERFACE_INDEX, USBH_DeviceType.Serial_FTDI, this.modem.VENDOR_ID, this.modem.PRODUCT_ID, this.modem.PORT_NUMBER);
USBH_SerialUSB serialUSB = new USBH_SerialUSB(zte, 921600, Parity.None, 8, StopBits.One);
serialUSB.Open();
bool return0 = Write(serialUSB, "AT", "OK");
bool return1 = Write(serialUSB, "ATV1", "OK");
bool return2 = Write(serialUSB, "ATE0", "OK");
bool return3 = Write(serialUSB, "AT&F&D2&C1S0=0", "OK");
bool return4 = Write(serialUSB, "ATS7=60S30=0", "OK");
bool return5 = Write(serialUSB, "AT+CGDCONT=1,\"IP\",\"bob.at\"", "OK");
bool return6 = Write(serialUSB, "ATDT*99#", "CONNECT 3600000");
if (return1 && return2 && return3 && return4 && return5 && return6)
{
if (!PPP.IsEnabled)
{
PPP.Enable(serialUSB);
}
if (!PPP.IsLinkConnected)
{
PPP.ConnectionStatus status = PPP.Connect("data@ bob.at", "ppp");
if (status == PPP.ConnectionStatus.Connected)
{
Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);
}
if (status == PPP.ConnectionStatus.Authentication_Faild)
{
Debug.Print("Auth failed");
}
if (status == PPP.ConnectionStatus.Connection_Faild)
{
Debug.Print("Conn failed");
}
}
}
}
}
Iam using a ZTE MF180 usb-modem, its one of the “flipflop” things, but I have disabled that and the modem is visible since I plug it in.
My problem is that I allways get a connection failed from the PPP class.
Can any buddy give me a advice whats wrong?
Some of the AT-Commands I have reverse engineered from windows.
thanks