11/09/2014

The given port name does not start with COM/com or does not resolve to a valid serial port.

一般来说,不管是什么样的串口(硬件形成真实存在的/软件虚拟的VSP——Virtual Serial Port),不同的编程语言对其操作应该不会有太大的问题。但是也有例外,如下文。

一直以来使用com0com软件虚拟串口,然后编程对其操作都没有出现过什么问题,今天换用C#写一个简单的小程序测试一下,结果出现问题了,具体表现就是:只要选择的串口是com0com虚拟出来的默认名称的串口(如CNCA0),在执行open方法时都会提示
The given port name does not start with COM/com or does not resolve to a valid serial port.
谷歌一下,针对这种出错提示,大致有两种解决方法:

1.若端口名称是正常的形式(以COM开头的),可能是分配的端口号已被其他设备占用,由于串口资源的独占性,所以这种端口暂时不能再被其他应用访问,更改端口设定即可。

参考:http://stackoverflow.com/questions/11605429/c-sharp-serialportopen-method-throws-argumentexception-because-of-port-name

2.若端口名称不是正常的形式(不是以COM开头的,如com0com虚拟出来的端口号默认就是CNCA*、CNCB*),由于C#的SerialPort类的open方法在执行时会对端口名称作进一步的检查,发现不是以“COM”开头的就直接throw上面的exception。而对名称的这一点要求一般不会引起大家的注意。

解决办法:在com0com中更改虚拟端口号为COM开头且暂时未被系统使用的名称即可。

参考:http://stackoverflow.com/questions/18230826/c-sharp-opening-a-virtual-serial-port-throws-argumentexception


---附:---
1.com0com (开源免费的VSP):http://com0com.sourceforge.net/
2..NET SerialPort Woes(作者提到System.IO.Ports.SerialPort目前是有点buggy!!!):http://zachsaw.blogspot.com/2010/07/net-serialport-woes.html

7/18/2014

关于EmEditor的几个小站

关于EmEditor的几个小站,干货颇多,记录与此,或有裨益。




大部分为日文,请结合Google翻译或Bing翻译查看。

5/01/2014

记录Android学习中遇到的问题及解决方法

问题:导入项目到Eclipse提示:“the type R is already defined”
解决方法:删掉src文件夹下的R.java文件,刷新工程即可
参考:http://bbs.csdn.net/topics/350161951?page=1#post-352784398


问题:在安卓模拟器中运行时提示“PANIC: Could not open”
解决方法:设置ANDROID_SDK_HOME环境变量及修改eclipse\configuration.settings\org.eclipse.ui.ide.prefs内容。
参考:http://blog.csdn.net/top_code/article/details/12008269


问题:Eclipse关联JAVA源文件后,双击JAVA源文件提示“Failed to create the Java Virtual Machine”
解决方法:修改eclipse解压目录下的配置文件eclipse.ini内的”--launcher.XXMaxPermSize 256M“改为”--launcher.XXMaxPermSize 128M“(共两处)
参考:http://blog.csdn.net/rflyee/article/details/8958165

问题:安装到真机测试,提示“Installation error: INSTALL_CANCELED_BY_USER”
解决办法:在手机上需要手动点击确定才可以安装。
参考:http://bbs.xiaomi.cn/thread-8072542-1-1.html


生成jar包供调用:http://www.cnblogs.com/vivid-stanley/archive/2012/02/18/2357182.html

10/28/2013

Tips & Tricks for web service query via Tasker

Sometimes we want to retrieve useful information from internet via Tasker, e.g. weather forecast, phone number area etc. We can use “HTTP POST/GET” action ATM. In general, the specific information which we want, embedded in the webpage we query from. It will need much more seconds and data traffic, and we have to use some complicated and annoyed steps, e.g. “Variable Split” or “Variable Search Replace” etc., to extract the specific information from it. Now I have some tips and tricks for this situation. Here I suppose you have known how to use “HTTP POST/GET” action via Tasker. Here we go.

-------------------------------------------------------------

Almost all webpages we retrieved, consist a lot of useless parts. So why not use other professional web services with API documented? These professional web services often provide specific API and refined output, e.g. output in XML, JSON format. Make good use of Google Search to find these professional web services first, guys.

For example, how to get the attribution and operator information from specific phone number in China? I can do it with with the free web service here, and it provide detailed API. With “HTTP GET(URL: http://www.sososjw.com/json?Tel=13888888888)”, we can get refined output in internal variable “%HTTPD” about the phone number 13888888888. Here is the content of “%HTTPD” for it:

{"Tel":"1388888","Province":"云南","City":"昆明","AreaCode":"0871","PostCode":"650000","Corp":"中国移动","Card":"GSM"}

It’s in JSON format, and it’s very simple and useful. Here I suggest that you’d better use “Javascript(let)” action to parse the value of element. The script below will flash ‘昆明’ , the value of “City” element for former ouput.

var info = JSON.parse(global("HTTPD"));
flash(info.City);

Also we can get weather forecast from professional web service.

e.g.
for city ‘大连(Da lian)’ in China http://m.weather.com.cn/data/101070201.html

A example for San Franciso http://api.wunderground.com/api/Your_Key/forecast/q/CA/San_Francisco.json

Perhaps you need learn some tutorial lessons about JSON and javascript from online W3School. Maybe you can use app “JOSN Viewer” to format raw JSON data and view the elements in tree structure.



"JSON Viewer" online: http://www.jsoneditoronline.org/
"JSON Viewer" for Win: http://jsonviewer.codeplex.com/  http://tomeko.net/software/JSONedit/index.php
"JSON Viewer" for Android: https://play.google.com/store/apps/details?id=eu.borzaindustries.jsondroid&hl=zh_CN

---------------------------------------------------

Sometimes you couldn’t find any web service with API.
There is a little trick that you can try its WAP service for help. Usually, some webpage use a refined WAP page for lower end mobile browser. You’ll feel lucky if the specific web service with a WAP page provided and you find it really available.

e.g. A weather forecast WAP page about Shanghai in China: http://www.weather.com.cn/wap/weather/101020100.shtml

For those who are not so lucky, there is another trick that you can use online RSS service to extract specific information from webpage and burned it into RSS feed URL. Here I strongly recommend you’d better use ‘feed43’ or ‘Yahoo Pipes’ to do the work. The ‘Yahoo Pipes’ is much more powerful than the former one. I’ve use the feed43 service to extract and burn a RSS feed about MIUI daily motto in my another article.

----------------------------------------------

Sometimes you’ll find the output of web service is useful, but not so concise, especially a little webpage with lots of useless HTML tags. I suggest that you can use “Variable -> Variable Convert –‘Html to text’” function to convert ‘%HTTPD’ into Text, then you can process the text more concisely.

OK. That’s all from my experience. Although I haven’t share you a plenty of online web service, you’ll find things become much more easier if you know the tricks. Principle or thoughts goes first, I always believe in this.

Reference:
1. something wrong with JSON.parse()?
2. Tasker来电归属地设置
3. 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供)
4. Sickbeard today's shows to pebble (Android+Tasker)


10/07/2013

Homemade Tasker Creations for Home Use

Here is some of my homemade tasker creations using scenes for home use.

Screenshots:

Wifi Password Viewer:

Shell Command Debugger:

Lyrics Show for PowerAMP:

Calculator:

Tasks Search & Run:

Special Symbols Pad:

Screen Filter:

9/22/2013

Mark Unread Sms As Read Thoroughly via Tasker

For quite some time, I use a task to mark unread sms as read programmatically via Tasker. But these method worked not so effectively.

Firstly, I adopt the database-process-directly way. With a specific SQL syntax, I can mark all unread sms as read. Like this:

Run Shell [ Command: sqlite3 /data/data/com.android.providers.telephony/databases/mmssms.db "update sms set read=1 where read=0" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: Continue Task After Error:On ]

Yes, it mark the unread sms as read. But it can’t refresh the unread count in “Messaging” app. And it can’t clear the unread notification in notification bar.


Then I tried the “SL4A+Python” method(refer here). Yes, it can mark unread sms as read and reset the unread count in “Messaging App”. But it can’t clear the unread notification too.


With the “SL4A+Python” method, we made a step forward. But it’s not very perfect. As for notification problem, I had looked up some information. It’s not allowed to clear notification of other app programmatically in android. The notification can be cleared by the tapping of user or by the app itself. We will be taken to the main window of app when we tapped the specific notification normally. And it seems not to be a friendly way. So we can consider about the other way. But app will not clear its notification at our sweet will. I’ve been stuck here for a long time.

Until recently, the principle behind "Launch Camera App" inspired me to try to do something similar about the package of "Messaging" app.



I tried it and it proves me right on MIUI 3.9.6. Now I can mark unread sms as read thoroughly via Tasker! Here is the flowchart:


More: Clear An App's Notification

Launch Camera App With Predefined Settings via Tasker

During the mid-autumn vacation, someone requested help in my QQ troop of Tasker (ID: 333174356), about how to launch camera app with predefined parameters(e.g. picture size, picture quality, and so on) for specific situation. Because of some other reason, I just give him an idea to try, and I haven’t put it into effect. After the vacation, I have chance to try my idea and it turns out the idea is right. Realized the principle behind the idea may be helpful to more similar situations, hereinafter I will explain the idea in detail, and take the “picture size” parameter of rear camera for example.




Firstly, we know that the “Media -> Take Photo” action will open the camera with custom parameters and then take photo automatically. Unfortunately, we can’t use this action to open the camera with custom parameters just for preview, then take photo manually.


I know a specific intent, which named “android.media.action.IMAGE_CAPTURE” in android, can launch the camera app with preview window. I’ve tried it before. And I find it not support camera parameters. I mean that it only open the camera window with default settings which we can’t change it programmatically.

Below shows the intent I tried:

Send Intent [ Action:android.media.action.IMAGE_CAPTURE Cat:Default Mime Type: Data: Extra: Extra: Package:com.android.camera Class:com.android.camera.Camera Target:Activity ]

As everyone knows, most settings are stored in the format of file, even databases. After some digging, I found the file (data/data/com.android.camera/shared_prefs/com.android.camera_xiaomi_preferences_0.xml) contains the “picture size” setting. We can change the value of “pref_camera_picturesize_key” node in the xml file programmatically. Then we launch the camera app. At last, we can restore the “picture size” setting.


Be careful! If you only follow these steps, the loaded camera app will not meet the desired effect. Because the camera app maybe can’t realize some settings changed, I think. There is a trick that you can disable and enable the app to take into effect. It’s very probably that the app will re-read the preferences file after the disable and enable operation. I guess the camera app read the settings and always runs in background when the device boots. We can disable and enable an app manually in android.


Of course, we can do this with the “Secure Setting” plugin for Tasker.



As for how to change the setting string in the preferences file, you can use shell script(especially “sed”, “awk” command) or use two files for renaming and swapping.

Here is the flowchart of the whole idea. (I've tried it successfully in MIUI 3.9.6)