I am wrting an app that needs to take the NMEA 183 GPS sentences from the GPS to process. I have set my serial port connection to port COM4 with a baud rate of 4800, 8 data bits, no parity, and one stopbit. Althougth a get a connection to the comm port I do not get any NMEA messages from the port.
Please could somebody advise on the settings for the internal GPS device.
Thanks in advance.
COM 4, 57600, 8, None, 1.
Sorry for the offtopic, is it possible to communicate with the internal GPS using .Net framework? What language are you working with?
Still no luck reading the GPS
I,ve tried the settings, but I still do not get and data.
I have looked in the registry, but could not see any of the settings as described in http://msdn.microsoft.com/en-us/library/bb202016.aspx
does anybody else have any ideas. The rom version on the device is 1.14.405.3, and I know the GPS works using another app. Or does anybody have a bit of c# code that I could use.
The code I am using looks like this
using (SerialPort sp = new SerialPort())
{
sp.PortName = "COM" + Port.ToString();
sp.BaudRate = BaudRate;
sp.DataBits = 8;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
sp.ReadTimeout = 1000;
try
{
sp.Open();
}
catch (Exception)
{
}
while(true)
{
string data = "";
bool gotLine = false;
while (!stopping && !gotLine)
{
try
{
data = sp.ReadLine();
gotLine = true;
}
catch (TimeoutException)
{
}
}
// Process the data line
}
The code throws due to the timeout, I never get a line of data.
Thanks.
Related
Hi!
I've create an application that detect Gprs Connection and check how much traffic is genereted on a Smartphone WM2003 and WM5.
On WM2003 it's all right, but in WM5 the RasEnumConnections() function always return 0 with 0 connection active...
The code for detect Connection is:
DWORD isConnection = false;
RASCONN rgrc[4];
DWORD dwSize = sizeof(rgrc);
DWORD dwConn = 0;
DWORD dwREC;
dwREC = RasEnumConnections(rgrc, &dwSize, &dwConn);
if (dwREC == ERROR_SUCCESS)
{
DWORD i;
RASENTRY rasEntry;
rasEntry.dwSize = sizeof(RASENTRY);
for (i = 0; i < dwConn; i++)
{
if(!RasGetEntryProperties(NULL,
rgrcIdea.szEntryName,
&rasEntry,
&rasEntry.dwSize,
NULL,
NULL))
{
if(wcsstr(rasEntry.szLocalPhoneNumber, L"~GPRS!") != NULL)
{
isConnected = true;
break;
}
}
else{
Debug(TEXT("Error RasGetEntryProperties"));
}
}
}
else {
Debug(TEXT("Error RasEnumConnections [%d]", dwREC));
}
return isConnected;
How can I detect the Gprs Connection in native code for this goal in WM5?
Can anyone help me?
Thanks!!!
I experience the same problem on the P3300, but on the P3600, there is an application in the windows folder named datadisconnect.exe .. And i looked into it with a dissasembler... And it uses RasEnumConnections and RasHangup to disconnect.. So my question to you is... What device are you using? This might be bug of some sort.. I also see that there is a difference between the datadisconnect.exe on the p3300 and on the p3600.. so i'll look into them and see if i can find anything there...
SaSHje
Follow up
Hi .. i've looked into what the P3300 does.. and it seems like RAS isn't used at all.. When you are connected with i.e. GPRS, the connection adapter and connection name is stored in the registry under HKLM\System\State\Connection\Cellular.. The datadisconnect.exe on this device use these and the GetAdaptersInfo function from Iphlpapi.h. Based on the information from both... They call IpReleaseAddress from Iphlpapi.h .. So .. I'm gonna try to make my own datadisconnect where i do not use the info in the registry, but instead use GetInterfaceInfo from Iphlpapi.h, where i'll fill a PIP_INTERFACE_INFO structure, and based on the adapterindexmap in this structure, release the IP adress assigned to the adapter.
Hope this helps you a bit.. But .. strangely.. on the P3600, the RasHangup works.. I know we are trying to do different things here.. but the problems a similar... Ras doesn't function well ..
Hi!
Sorry to interupt this tread, but this may explane why the standard Spb GPRS Monitor does not work on the P3300. On the CD shipped with the device there is a spesial version of Spb GPRS monitor that works.
Regards
PK
No problem PK.. Thanks for letting me know.. i'll take a look at it when i have time.. FYI, using the GetInterfaceInfo and IpReleaseAddress works like a charm..
azatoth: I do not know how we can use the Iphlp API to find statistics regarding traffic etc... If you manage to solve this, please let me know.. I will do the same if i stumble over something which could resolve this issue..
Hello,
I have the same problem and try to disconnect an active GPRS connection
with IpReleaseAddress(). I have found the adapter with GetInterfaceInfo()
but IpReleaseAddress() always fails with an unknown error code.
Can you give me an example how you got this working?
Thanks.
Houser
This worked for me..
I used this link http://msdn2.microsoft.com/en-us/library/aa366056.aspx .. and f.ex this worked:
PIP_INTERFACE_INFO pInfo;
pInfo = (IP_INTERFACE_INFO *) malloc( sizeof(IP_INTERFACE_INFO) );
ULONG ulOutBufLen = sizeof(IP_INTERFACE_INFO);
DWORD dwRetVal = 0;
// Make an initial call to GetInterfaceInfo to get
// the necessary size in the ulOutBufLen variable
if ( GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
{
free(pInfo);
pInfo = (IP_INTERFACE_INFO *) malloc (ulOutBufLen);
}
// Make a second call to GetInterfaceInfo to get
// the actual data we need
if ((dwRetVal = GetInterfaceInfo(pInfo, &ulOutBufLen)) == NO_ERROR )
{
for (int i=0; i<pInfo->NumAdapters; i++)
{
IpReleaseAddress(&pInfo->Adapter);
}
}
free(pInfo);
Thanks. Now it works. My mistake was that I call IpReleaseAddress()
for PPP connection. For ethernet connections it works well.
Houser
OK I am writing my first Mobile 6 App, based on compact framework 2, obviously finding some differences from Framwork vs compact when dealing with reading and writting simple values to xml;
Here is what I want to do: write two textbox values to xml as follows:
<settings>
<hostip>192.168.0.14</hostip>
<hostport>8011</hostport>
</settings>
So I got the above accomplished using the following code:
--------------------
string hstip = "";
string hstport = "";
hstip = this.HostIP.Text.ToString();
hstport = this.HostPort.Text.ToString();
XmlWriterSettings xml_settings = new XmlWriterSettings();
xml_settings.Indent = true;
xml_settings.OmitXmlDeclaration = false;
xml_settings.Encoding = Encoding.UTF8;
xml_settings.ConformanceLevel = ConformanceLevel.Auto;
using (XmlWriter xml = XmlTextWriter.Create(GetApplicationDirectory() + @"\settings.xml", xml_settings))
{
xml.WriteStartElement("settings");
//xml.WriteStartAttribute("hostip", "");
xml.WriteElementString("hostip", hstip);
//xml.WriteString(hstip);
//xml.WriteEndAttribute();
xml.WriteElementString("hostport", hstport);
//xml.WriteStartAttribute("hostport", "");
//xml.WriteString(hstport);
//xml.WriteEndAttribute();
xml.WriteEndElement();
//ds.WriteXml(xml);
xml.Close();
}
-----------end of write code------------
Now the part I am stumped on as I have tried all varietions to get the data back into the textboxes, I either get and exception or blank values in the textboxes.
Here is the code:
------------------
private void SrvSettings_Load(object sender, EventArgs e)
{
XmlReaderSettings xml_settings = new XmlReaderSettings();
xml_settings.IgnoreComments = true;
xml_settings.IgnoreProcessingInstructions = true;
xml_settings.IgnoreWhitespace = true;
xml_settings.CloseInput = true;
try
{
using (XmlReader xml = XmlTextReader.Create(GetApplicationDirectory() + @"\settings.xml", xml_settings))
{
xml.ReadStartElement("settings");
xml.Read();
xml.ReadElementString(,,)
//xml.ReadToFollowing("hostip");
this.HostIP.Text = xml.GetAttribute("hostip","");
//this.HostIP.Text = xml.GetAttribute("hostip");
//xml.ReadToFollowing("hostport");
this.HostPort.Text = xml.GetAttribute("hostport","");
// Close it out----------------
xml.ReadEndElement();
xml.Close();
//ds.ReadXml(xml);
// }
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(
ex.ToString(), "Error Loading IP settings");
}
}
------------end of read code
obviously I get an exception with this:
"System.xml.xmlexception:
"Text" is an invalid XmlNoteType. Line 2, posistion 11 at
System.xml.xmlReader.ReadEndElement()"
-----
I suspect I need to use ReadElementString, but I have tried and no workie...
Somebody have an example/class for both reading and writing per my requirements above, I would really appreciate the help..
Use XmlDocument
Try using the XmlDocument instead. It's alot easier to use for simple xml reading/writing.
Well Partially working now - I get the Hostport populated but for some reason hostip is blank even though it appears it falls through it in the case statement.. wierd..
DataSet ds = new DataSet();
XmlReaderSettings xml_settings = new XmlReaderSettings();
xml_settings.IgnoreComments = true;
xml_settings.IgnoreProcessingInstructions = true;
xml_settings.IgnoreWhitespace = true;
xml_settings.CloseInput = true;
try
{
using (XmlReader xml = XmlTextReader.Create(GetApplicationDirectory() + @"\settings.xml", xml_settings))
{
xml.MoveToContent();
xml.ReadStartElement("settings");
while (xml.Read())
{
//xml.Read();
switch (xml.Name)
{
case "hostip":
HostIP.Text = xml.ReadString(); <--I get Blank text
break;
case "hostport":
HostPort.Text = xml.ReadString(); <--POpulated OK
break;
default:
break;
}
// Close it out----------------
//xml.ReadEndElement();
}
xml.Close();
//ds.ReadXml(xml);
// }
}
}
Solved, Had to remove the line: xml.ReadStartElement("settings");
Thanks..
Just out of curiosity, what will your app do ?
I'm writing a WPF Windows App that monitors Server Services, IPs, Websites for up or down status; buiding a client server component to it, so the end goal will be to use the mobile app to connect to the host and download status on said servers being monitored and populate them in a listview whith thier up or done status.
Simple app but still in the works.
if you can make it customizable (to set up parametres, adreses) it wil be useful for many website administrators
a cool little app
Hello there,
To keep the story short, i want to make an IR Remote control software for my Windows Mobile 5.0 powered Asus A696 using the Serial port communication class from .NET Compact Framework 3.5 and i'm coding C#.
THIS IS WHEN THE FORM OPENS:
//Create and open serial port
Infrarosu = new SerialPort("COM3");
if (Infrarosu.IsOpen == false)
{
Infrarosu.BaudRate = 9600;
Infrarosu.Open();
if (Infrarosu.IsOpen)
this.statusBar1.Text="Am deschis portul!";
}
//Remote code for Power button on a WDTV
hexString = "900A 0068 0000 0001 8479 12ED";
//Transform from HEX STRING to BYTES[] using a class from CodeProject
byteArray = HexEncoding.GetBytes(hexString, out discarded);
THESE INSTRUCTIONS EXECUTE WHEN A BUTTON IS CLICKED:
try
{
this.statusBar1.Text = "";
Infrarosu.Write(byteArray, 0, byteArray.Length);
for (i=1;i<=byteArray.Length;i++)
this.statusBar1.Text = this.statusBar1.Text+""+byteArray.ToString();
}
catch (System.IO.IOException)
{
statusBar1.Text="Exception!";
}
The problem is that at first it threw me the IOException, then after implementing try-catch it said that it sent the data correctly but the wdtv wouldn't power on and now it threw me IOException again.
Does anyone have any ideas, advice or anything that can be useful?
Thanks a million!
Hello,
I'm trying to establish connection to the internet using the following code, but not sure that this code is good.
I want to keep my connection for hours (it's a voip program), but the tcp sockets in my application are dropped every one hour or two. Although there is a disconnection, the device still has IP and still shows that it's connected to internet in the status bar on the top. I tried on lots of HTC devices (HD2, Pro2, Pro, etc...)
Can somebody tell if there is something wrong in the code?
Thanks,
Emil.
Code:
void Connect()
{
CONNMGR_CONNECTIONINFO ConnectionInfo;
ZeroMemory (&ConnectionInfo, sizeof (ConnectionInfo));
ConnectionInfo.cbSize = sizeof (ConnectionInfo);
ConnectionInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ConnectionInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
ConnectionInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
ConnectionInfo.bExclusive = TRUE;
ConnectionInfo.guidDestNet = GetNetworkForURL (L"http://www.msn.com");
return ConnMgrEstablishConnectionSync (&ConnectionInfo, &m_hConnection, 30000, dwStatus);
}
void Disconnect()
{
HRESULT hr = ConnMgrReleaseConnection(m_hConnection, TRUE);
m_hConnection = NULL;
}
GUID ConnectionsManager::GetNetworkForURL (LPCTSTR url)
{
DWORD dwIndex = 0;
GUID rv;
if (!SUCCEEDED (ConnMgrMapURL (url, &rv, &dwIndex)))
rv = GUID_NULL;
return rv;
}
Hi,
I have write a VERY SIMPLE program for comunicate with my arduino uno r3 without host api and a lot of lines of code but with 2/3 simple unix command.
For this program you must have root.
Video for activate/deactivate one led:
http://www.youtube.com/watch?v=wwjkWzeUc6E
Arduino code:
Code:
int incomingByte = 0; // for incoming serial data
int led = 13;
boolean pinHIGH = false;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(led, OUTPUT);
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
if(! pinHIGH)
{
digitalWrite(led, HIGH);
pinHIGH = true;
}
else
{
digitalWrite(led, LOW);
pinHIGH = false;
}
}
}
Android project for eclipse:
http://clshack.com/wp-content/uploads/2013/07/SerialComunication.tar.gz
you have any suggestions?
My blog article:
http://clshack.com/java-android-serial-connection-nexus-7-arduino-uno.html
Thanks