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!
Related
Does anyone know how to turn on and off the Widcomm bluetooth on a Blue Angel from within C/eVc? :?:
tia
The only official way to turn off the radio is to destroy the last of the BT objects using the stack (the stack is object orientated, creating an object turns it on, destroying the lst object turns it off, this assumes you have the widcomm SDK). The problem is that the BT app that runs in the system tray (and shows you that bluetooth icon in the bottom left) owns a stack object that you cant properly destroy, hence you can't turn the radio off.
hrm...
If the tray app wasn't running, theres a function in the wbtapiCE.dll called UnloadStack ([email protected]@@[email protected]@[email protected]) which should force the stack to unload and probably turn off the radio.
So we might be able to turn it OFF this way. And how do we turn in ON again ;-)
Theres a corrasponding LoadStack ([email protected]@@[email protected]@[email protected]) which would do the job.
Each of these accept two parameters, the first appears to be a pointer to a class, the second a numeric value.
For the class pointer, it appears that you can define an 8 byte array and call the constructor ( [email protected]@[email protected] ) on it, remember to call the destructor ( [email protected]@[email protected] ) when your done. The hex value appears to be 0x123456 for LoadStack and 0x654321 for UnloadStack.
I really don't know how successfull you would be starting the stack yourself, spinning up the BT tray app, then killing it and shutting down the stack, you may find you have to replace all the functionality of the tray app yourself.
Complicated stuff. I might be easier off doing FindWindow on the BtApp and find the ON and OFF buttons and programatically press them.
Hello All.
I call wbtapiCE.dll functions for on/off BT on dell axim x30.
I use, two dll metods
[email protected]@@[email protected]@[email protected] == public: enum WBtRc __cdecl CWBtAPI::UnloadStack(unsigned int)
and
>> [email protected]@@[email protected]@[email protected] == public: enum WBtRc __cdecl CWBtAPI::LoadStack(unsigned int)
But no positive effect.
Anybody know what i doing wrong?
Sample code below:
{
CString szDllPath = _T("wbtapiCE.dll");
HMODULE hMod = LoadLibrary(szDllPath);
if(hMod==NULL)
{
AfxMessageBox(_T("LoadLibrary Failed !!!"));
}
//__cdecl CWBtAPI::CWBtAPI(void)
typedef void (CWBtAPI::*PFNCreateCWBt)();
typedef void (CWBtAPI::*PFNDestructorOfCWBt)();
typedef int (CWBtAPI::*PFNLoadCWBt)(unsigned int);
typedef int (CWBtAPI::*PFNUnLoadCWBt)(unsigned int);
//>> >> [email protected]@@[email protected]@[email protected] == public: enum WBtRc __cdecl CWBtAPI::UnloadStack(unsigned int)
CWBtAPI* a1 = (CWBtAPI*)_alloca(sizeof(CWBtAPI));
PFNCreateCWBt pfnCreateWBt = force_cast<PFNCreateCWBt>(GetProcAddress(hMod, TEXT("[email protected]@[email protected]")));
(a1->*pfnCreateWBt)();
//////////////////////////////////////////////////////////////////////////
PFNUnLoadCWBt pfnUnLoadA = force_cast<PFNUnLoadCWBt>(GetProcAddress(hMod, TEXT("[email protected]@@[email protected]@[email protected]")));
AfxMessageBox(_T("Started pfnUnLoadA"));
int result = (a1->*pfnUnLoadA)( 0x654321);
CString err = _T("Done pfnUnLoadA");
AfxMessageBox(err );
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
PFNLoadCWBt pfnLoadA = force_cast<PFNLoadCWBt>(GetProcAddress(hMod, TEXT("[email protected]@@[email protected]@[email protected]")));
AfxMessageBox(_T("Started pfnLoadA"));
result = (a1->*pfnLoadA)(0x123456);
AfxMessageBox(_T("Done pfnLoadA"));
//////////////////////////////////////////////////////////////////////////
PFNDestructorOfCWBt pfnDestA = force_cast<PFNDestructorOfCWBt>(GetProcAddress(hMod, TEXT("[email protected]@[email protected]")));
(a1->*pfnDestA)();
/*************************************************************************/
FreeLibrary(hMod);
}
could some kind soul maybe write a script to do someth like that...
I make it BT on/off
Jn dell axim X30 exist btpwr.dll.
This dll export some interesting methods.
1 0 0000128C PowerDeInit
2 1 00001284 PowerInit
3 2 00001258 PowerOff
4 3 0000121C PowerOn
I call this methods directly from dll, and i turn on turn off bt !!
Sample code below:
void DoTrayOn()
{
CString szDllPath = _T("btpwr.dll");
HMODULE hMod = LoadLibrary(szDllPath);
if(hMod==NULL)
{
AfxMessageBox(_T("LoadLibrary Failed !!!"));
}
typedef int (*BTPowerOn)();
BTPowerOn bton = (BTPowerOn) GetProcAddress(hMod, TEXT("PowerOn"));
if (NULL != bton)
{
// AfxMessageBox(_T("Start DoTrayOn"));
(bton) ();
}else
{
// AfxMessageBox(_T("Error NULL DoTrayOn pointer"));
}
FreeLibrary(hMod);
}
void DoTrayOff()
{
CString szDllPath = _T("btpwr.dll");
HMODULE hMod = LoadLibrary(szDllPath);
if(hMod==NULL)
{
AfxMessageBox(_T("LoadLibrary Failed !!!"));
}
typedef int (*BTPowerOff)();
BTPowerOff bton = (BTPowerOff) GetProcAddress(hMod, TEXT("PowerOff"));
if (NULL != bton)
{
// AfxMessageBox(_T("Start DoTrayOn"));
(bton) ();
}else
{
// AfxMessageBox(_T("Error NULL DoTrayOn pointer"));
}
FreeLibrary(hMod);
}
Bluetooth turn on/turn off
Hello
Have you a solution for turn on and turn off bluetooth by code?
I have a widcomm stack and I use c# .net
i'm searching for a solution for my Touch Pro 2 with Widcomm BT Stack.
i can turn on BT by creating an object of CBtIf, but can't turn of BT by deleting the object.
someone has an idea?
regards
IceFire
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
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.
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