Reading and writing serial port data with PowerShell

Posted on by 0 comment

List com ports

To see a list of available com ports,

PS C:\> [System.IO.Ports.SerialPort]::getportnames()

Read or write data

To read or write data with given details, such as port, Baudrate etc.

$port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
$port.WriteLine("some string data")

Write unix time

I have a clock which accepts unix time for syncing the time, so I use script below to sync the time if the clock being off for few minutes after some time.

$time='T'+[string]([int](New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date)).TotalSeconds)
$port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
Category: PowerShell, uart

Download UFT script from ALM

Posted on by 0 comment

Usually we use ALM to manage our test cases, test script and resource files, which works very well, but when we consider to host the script in git, we have to download them to local and commit to git.

In this exercise, I try to download UFT scripts and resource files in UFT with using ALM OTA , the OTA api reference can be found here, and here is the code.

Dim locPath
locPath= "c:\uft\script" 


Function DownloadTestsFromALM(SaveToFolderPath)

	Dim qcCon, testList, testStorage
	Set qcCon= QCUtil.QCConnection 
	If qcCon.ProjectConnected Then 
		Set testFilter = qcCon.TestFactory.Filter
		testFilter.Filter("TS_TYPE") = "QUICKTEST_TEST"
		Set testList = qcCon.TestFactory.NewList(testFilter.text)
		For each t in testList 
			Set testStorage= t.ExtendedStorage 
	        testStorage.ClientPath= SaveToFolderPath&"\" & t.Field("TS_SUBJECT").Path & "\" & t.Name
			on error resume next
			testStorage.Load "Action0\*.*, Action1\*.*, Action2\*.*, Action3\*.*, Action4\*.*, Action5\*.*, default.cfg, default.usp, Default.xls,, Test.tsp, *.usr", True 
	        if Err.Number <> 0  then
	           reporter.ReportEvent micWarning, t.Field("TS_SUBJECT").Path & "\" & t.Name & " -- File download fFAILED. error:=" &  Err.Description,""
	           reporter.ReportEvent micPass, t.Field("TS_SUBJECT").Path & "\" & t.Name & " -- File download successful.", ""
	        end if
	End If
	Set qcCon= Nothing
	Set testList= Nothing
	Set testStorage= Nothing

End Function

Function DownloadResourceFromALM(SaveToFolderPath)
	Dim qcCon,CurrentResObj,ObjResFactory,ResObjList
	Set qcCon = QCUtil.QCConnection
	Set ObjResFactory = qcCon.QCResourceFactory
	Set ResObjList = ObjResFactory.NewList("")
	For each CurrentResObj in ResObjList 
		on error resume next
		CurrentResObj.DownloadResource SaveToFolderPath& "\" & CurrentResObj.path & "\" & CurrentResObj.Name,True

        if Err.Number <> 0  then
           reporter.ReportEvent micWarning, CurrentResObj.path & "\" & CurrentResObj.Name & " -- File download FAILED. error:=" &  Err.Description,""
           reporter.ReportEvent micPass, CurrentResObj.path & "\" & CurrentResObj.Name & " -- File download successful.", ""
        end if
	Set ResObjList = Nothing
	Set CurrentResObj = Nothing
	Set ObjResFactory = Nothing 
	Set qcCon = Nothing

End Function

Category: UFT

Firebase login in docker toolbox

Posted on by 0 comment

The exercise is trying to resolve the Firebase login callback issue in docker; my system setup is VirtualBox with Docker toolbox.
Let’s start with the login command:

# firebase login
Visit this URL on this device to log in:

Waiting for authentication…

Then I copy the long URL, and paste it to a browser window in host machine, allow the FirebaseCLI access, the authentication is working fine, but failed at callback. That is due to the setup is docker with VirtualBox, so localhost is not same as the docker machine, which in my case is, and HTTP://localhost:9005 is not accessible. If I try to modified the URL with replacing the localhost with docker machine IP, a 400 OAuth2 error will be returned.

Error: invalid_request
device_id and device_name are required for private IP:

After some trying, and managed to get it working with steps below,

  • Copy the long URL and paste it to a browser window in host machine
  • Follow the steps to complete the authentication
  • The callback failed with URL HTTP://localhost:9005?state=…..
  • Replace localhost with the docker machine IP in the URL and click enter

Now you will receive a successful message in the browser window and docker terminal.

Category: Docker

Add make to Git Bash on Windows

Posted on by 1 comment

Recently I need to use make command which is not packaged with Git Windows by default, and come across this git hub page, which mentioned how to add few commands to Git Bash on windows, this is quite handy and solved my problem.


  • Go to ezwinports.
  • Download (get the version without guile).
  • Extract zip.
  • Copy the contents to your Git\mingw64\ merging the folders, but do NOT overwrite/replace any existing files.

Category: git

Software installation on multiple systems with PowerShell

Posted on by 0 comment

In this exercise, I will try to install a software on multiple systems with PowerShell, which could reduce some maintenance effort when we need to install or patch some software regularly. The way here is to copy installation file to c:\temp first to remote systems, then install it with remote session, and then check registry and see the installation details.

Category: PowerShell