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()
COM1
COM2
COM3

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.open()
$port.WriteLine("some string data")
$port.ReadLine()
$port.Close()

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
$port.open()
$port.WriteLine($time)
$port.Close()
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" 

DownloadTestsFromALM(locPath)
DownloadResourceFromALM(locPath)

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, Parameters.mtr, 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,""
	        else
	           reporter.ReportEvent micPass, t.Field("TS_SUBJECT").Path & "\" & t.Name & " -- File download successful.", ""
	        end if
		Next
	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,""
        else
           reporter.ReportEvent micPass, CurrentResObj.path & "\" & CurrentResObj.Name & " -- File download successful.", ""
        end if
   
	Next
	
	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:

https://accounts.google.com/o/oauth2/auth?client_id=5635aa84335869-fgrhgmd47baqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&scope=email%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloudplatformprojects.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ffirebase%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&state=547585715&redirect_uri=http%3A%2F%2Flocalhost%3A9005

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 192.168.99.100, 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: http://192.168.99.100:9005

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.

make

  • Go to ezwinports.
  • Download make-4.1-2-without-guile-w32-bin.zip (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