Thanks for the code which I have "tweaked" to display the Optismart meter readings from my two units.
Code:
### DisplayENVI.ps1 ############################################
#
# Routine to display power recorded by a Current Cost Monitor.
#
################################################################
$loop_forever = $true
$CommPort_in="COM3"
$BaudRate=57600
$Sensor1=9
$Sensor2=8
#$template=[xml]("<msg><src></src><dsb></dsb><time></time><tmpr></tmpr><sensor></sensor><id></id><type></type><ch1><watts></watts></ch1><ch2><watts></watts></ch2><ch3><watts></watts></ch3></msg>")
[SINGLE]$CH1 = 0
[SINGLE]$CH2 = 0
[SINGLE]$CH3 = 0
[SINGLE]$Meter1 = 62745
[SINGLE]$Meter2 = -71
[SINGLE]$Total1 = 0
[SINGLE]$Total2 = 0
$TimeNow=" "
#########################################3######################
$port_in= new-Object System.IO.Ports.SerialPort $CommPort_in,$BaudRate,None,8,one
$port_in.Open()
$data=$port_in.Readline() #Discard a possibly partial msg
#
do {
$data=$port_in.Readline()
#Write-Host ($data)
#Remove any chars (probably noise) received before <msg
if ((!$data.StartsWith("<msg>")) -or (!$data.EndsWith("</msg>")))
{$Data =$data.substring($data.IndexOf("<"),$data.LastIndexOf(">") - $data.IndexOf("<")+1)
}
[xml]$data_in=$data #may still have noise inside the message. trap error and continue
#---------------------------------------------------
if ($data_in.msg.sensor -eq $Sensor1)
{$CH1=$data_in.msg.imp
$CH2=$data_in.msg.ipu
$CH3=$data_in.msg.id
$Total1 = ($CH1 / $CH2) + $Meter1
$TimeNow=$data_in.msg.time
# Cls
Write-Host ("Sensor=$Sensor1, Time=$TimeNow Meter Reading=$Total1, Impulse Count=$CH1")
}
elseif ($data_in.msg.sensor -eq $Sensor2)
{$CH1=$data_in.msg.imp
$CH2=$data_in.msg.ipu
$CH3=$data_in.msg.id
$Total2 = ($CH1 / $CH2) + $Meter2
$TimeNow=$data_in.msg.time
Write-Host ("Sensor=$Sensor2, Time=$TimeNow Meter Reading=$Total2, Impulse Count=$CH1")
}
else
{
# All other sensors ignored
}
#----------------------------------------------------
} While ($loop_forever='true')
$port_in.close()
Write-Host ("DisplayENVI completed")
Meter1 and Meter2 are to set the display to match my electric meters. (odd that one seems to have a stored value higher than my meter).
Automan.
SeekerAfterTruth wrote:
Automan wrote:
I have not played with C++ since we were rolling out Advanced Novell Netware which needed 640kb rather than 256kb of workstation RAM.
Showing your age olld boy! If we're swapping war stories, my first mainframe had 40K core memory.
Quote:
(I am after a dashboard program that shows in near real time all channels at once on a PC screen).
Compatibility with the new Optismart would also be nice .
Apparently no takers on this. I needed something similar so I tweaked some existing code I had, to display what I needed. At the moment it extracts Ch1->Ch3 from one sensor and displays it on a console. It is rough and ready but you may find it meets some of your need.
My code is written in powershell, because makes manipulating xml a doddle, it but that shouldn't be a problem if you're running Win7 or Vista as the powershell interpreter is built into the OS. (It is also built into XP since SP2, for anything earlier you would need to download powershell from Microsoft).
to use it:
- download DisplayENVI.ps1 from http://pastebin.com/KTcE26p9.
- Correct the com port, baudrate and Sensor to be displayed on lines 9-11.
- execute in a command window using command "powershell .\DisplayENVI.ps1"
- Stop by keying Ctrl-break or Ctrl-C
Powershell scripts require authorisation to run. The command can be entered manually, but is easier to download DisplayENVI.bat from
http://pastebin.com/Snyd60RP. Save this in the same directory as DisplayENVI.ps1 and double-click to execute.
HTH