Perl module for decoding tekpower TP4000ZC

April 7th, 2020

I didn’t see one of these lying around so I banged this together in a few minutes to be able to use the TP4000ZC with a raspberry pi.. the intention is to use this to monitor the main bus voltage of my solar array.

This is provided, obviously, with no warranty, and is based on information found at tek’s web site. It seems to match the display.


package tekpower;

use Device::SerialPort;
use Data::Dumper;
use strict;

sub new {
my $self = {};
my $type = shift;
my $port = shift;

$self->{'debug'} = 0;
$self->{'port'} = $port;
$self->{'dev'} = Device::SerialPort->new($port, 1) || die "Failed to open $port";
$self->{'dev'}->baudrate(2400);
$self->{'dev'}->parity('none');
$self->{'dev'}->databits(8);
$self->{'dev'}->stopbits(1);
$self->{'dev'}->dtr_active(1);

$self->{'dev'}->debug($self->{'debug'}) if($self->{'debug'});
$self->{'dev'}->write_settings;
$self->{'dev'}->read_const_time(3000);
my $r = bless($self, $type);

return $r;
}

sub read {
my $self = shift;
$self->{'dev'}->reset_error;
my ($count,$buf) = $self->{'dev'}->read(32);
print "count: $count\n" if($self->{'debug'});
my @array = split(//,$buf);
my $notOk = 1;
while($notOk && @array) {
my $z = shift(@array);

print "z: " . ord($z) if($self->{'debug'});

my $checksum = (ord($z) & 0xF0) >> 4;
print "checksum: $checksum\n" if($self->{'debug'});
if($checksum == 1) {
unshift(@array,$z);
$notOk = 0;
}
}
my @v_array;
# first check high order bits
my ($i, $checksum);
for($i=0;$i<14;$i++) { $checksum = ord($array[$i]) & 0xF0; $v_array[$i] = ord($array[$i]) & 0x0F; $checksum = $checksum >> 4;
if($checksum != ($i+1)) {
print "Checksum mismatch at $i ($checksum)\n" if($self->{'debug'});
return undef;
}

}

# second decode reading;
my $mode;

$self->{'smode'} = "AC" if($v_array[0] & 8);
$self->{'smode'} = "DC" if($v_array[0] & 4);
# bit 2 is auto ranging, do we care?
# bit 1 is RS232, um, if you don't know that, what are you doing here?
$self->{'sign'} = "+";
$self->{'sign'} = "-" if($v_array[1] & 8);
$self->{'digit1'} = $self->convert_digit($v_array[1], $v_array[2], 0 );
$self->{'digit2'} = $self->convert_digit($v_array[3], $v_array[4], 1 );
$self->{'digit3'} = $self->convert_digit($v_array[5], $v_array[6], 1 );
$self->{'digit4'} = $self->convert_digit($v_array[7], $v_array[8], 1 );

$self->{'number'} = $self->{'sign'} . $self->{'digit1'} . $self->{'digit2'} . $self->{'digit3'} . $self->{'digit4'};

$self->{'range'} = 'u' if($v_array[9] & 8);
$self->{'number'} *= 0.000001 if($v_array[9] & 8);

$self->{'range'} = 'n' if($v_array[9] & 4);
$self->{'number'} *= 0.000000001 if($v_array[9] & 4);
$self->{'range'} = 'k' if($v_array[9] & 2);
$self->{'number'} *= 1000 if($v_array[9] & 2);

# 1 is diode, do we care?
$self->{'range'} = 'm' if($v_array[10] & 8);
$self->{'number'} *= 0.001 if($v_array[10] & 8);

$self->{'range'} = '%' if($v_array[10] & 4);
$self->{'range'} = 'M' if($v_array[10] & 2);
$self->{'number'} *= 1000000 if($v_array[10] & 2);

$self->{'mode'} = "farad" if($v_array[11] & 8);
$self->{'mode'} = "ohm" if($v_array[11] & 4);
$self->{'mode'} = "delta" if($v_array[11] & 2);

# bit 1 is hold, do we care?

$self->{'mode'} = "amps" if($v_array[12] & 8);
$self->{'mode'} = "volts" if($v_array[12] & 4);
$self->{'mode'} = "hz" if($v_array[12] & 2);

return $self->{'smode'} . ' ' . $self->{'mode'} . " " . $self->{'sign'} . " " . $self->{'digit1'} . $self->{'digit2'} . $self->{'digit3'} . $self->{'digit4'} . ' ' . $self->{'range'};

}

sub convert_digit {
my $self = shift;
my $lhs = shift;
my $rhs = shift;
my $include_decimal = shift;
my $decimal;

if($include_decimal) {
if($lhs & 8) {
$decimal = ".";
} else {
$decimal = "";
}
}

$lhs = $lhs & 7;

my $d;

# 000 0101 = 1
if($lhs == 0 && $rhs == 5) {
$d = 1;
# 101 1011 = 2
} elsif($lhs == 5 && $rhs == 11) {
$d = 2;
# 001 1111 = 3
} elsif($lhs == 1 && $rhs == 15) {
$d = 3;
# 010 0111 = 4
} elsif($lhs == 2 && $rhs == 7) {
$d = 4;
# 011 1110 = 5
} elsif($lhs == 3 && $rhs == 14) {
$d = 5;
# 111 1110 = 6
} elsif( $lhs == 7 && $rhs == 14) {
$d = 6;
# 001 0101 = 7
} elsif($lhs == 1 && $rhs == 5) {
$d = 7;
# 111 1111 = 8
} elsif($lhs == 7 && $rhs == 15) {
$d = 8;
# 011 1111 = 9
} elsif($lhs == 3 && $rhs == 15 ) {
$d = 9;
# 111 1101 = 0
} elsif($lhs == 7 && $rhs == 13 ) {
$d = 0;
} elsif($lhs == 6 && $rhs == 8) {
$d = "L";
} else {
return undef;
}

my $v = $decimal . $d;
print "V: $v\n" if($self->{'debug'});
return $v;
}

1;

Solar

April 4th, 2020

So, i’ve decided to stop waiting for the government to make some sort of ‘green new deal’ happen and put my money where my mouth is. It also helps reduce my paranoia to know that I will have backup water and power supplies if the government (who provides both things in the city of Seattle) experiences some sort of outage or other difficulties. So, I’m putting out 3.5kW divided as 1.6kW of monocrystalline and the rest amphorous (the idea here is to make power in both sunny and cloudy conditions). Realistically I expect to see maybe 1kW output except high noon on the brightest parts of summer, but that is still enough to keep my fridge and freezer running, and I can also add a grid intertie inverter to reduce my power bills when I’m not using the array for backup power or to charge my electric car.

I’m also putting in 10kW of backup energy storage, which can be charged either via the grid (I’ve got a 40 amp charger) or via the solar array. I will likely also experiment with solar towers and solar tracking. Those of you who know me know I often have hobbies-for-a-year – this is my hobby for 2020.

I am also adding numerous rain barrels to store rainwater and a 12 volt pumping system that can be used to pressurize my pipes via a water filter from the rainwater, as well as some 12 volt emergency lighting.

Companies, stop being so shortsighted

April 3rd, 2020

So, one of the problems I keep running into with $COMPANY is that they are making decisions which make short term profit at the cost of long term profit. They keep encouraging their employees to sell .. with increased commissions.. while not having equipped all the employees to sell online or having prohibited in person events. This is a really dumb thing to do, but it reminds me of my conversation with a carny who was setting up a ride at the Prince William County Fair.

He was being really intent, carefully checking every bolt, every cotter pin, and he told me “Kid, you never want to kill a mark. You want them to come back next year so you can fleece them. Kill one mark, and a thousand marks won’t come next year because they will be too afraid. I check my ride until I’d be willing to let my own kids ride on it.”

The logic which doesn’t escape carnies but does seem to escape $COMPANY is that encouraging selling right now if it risks in person interfacing is potentially killing both customers and employees and therefore costing long term profits. I understand that we are not mentally adaptable enough to switch to a alternate RAS just for this emergency and then switch back – that we’d literally rather die than do anything that smacks of collectivism. All I can do is sit back and watch the carnage. Lately I’m thinking the USA will be 5x the deaths of the nearest competitor.

For Vicky..

March 24th, 2020

(Toto : I’ll be over you)
(todo: record cover and place link here)

Some people live their dreams
Some people close their eyes
Some people’s destiny
Passes by

There are no guarantees
There are no alibis
That’s how our love must be
Don’t ask why

[Pre-Chorus 1]
It takes some time
God knows how long
I know that I can forget you

[Chorus 1]
As soon as my heart stops breakin’
Anticipating
As soon as forever is through
I’ll be over you

[Verse 2]
Remembering times gone by
Promises we once made
What are the reasons why
Nothing stays the same

[Pre-Chorus 2]
There were the nights
Holding you close
Someday I’ll try to forget them

[Chorus 2]
As soon as my heart stops breakin’
Anticipating
As soon as forever is through
I’ll be over you

[Guitar Solo]

[Chorus 3 with repeats]
As soon as my heart stops breakin’
Anticipating
(Anticipating)
Someday I’ll be over you

As soon as my heart stops breakin’
Anticipating
(Anticipating)
Someday I’ll be over you
As soon as my heart
(As soon as my heart stops breakin’)
(Anticipating)

One more COVID post, aimed particularly at MLM folks

March 24th, 2020

MLM folks, *do not* have in person parties.

“But no one is sick!”

The problem is, COVID can

A: Be totally asymptomatic.. you feel just fine, but you are shedding – releasing hundreds of billions of copies of the virus

B: Be shedding before it’s symptomatic.

And

C: The test probably false-negatives fairly often, based on the number of people I know who got the test negative but are obviously sick with it. One thing I suspect also is that whether a person believes they have it or not may affect what answer they *hear* regardless of what the actual answer *is*. The human brain is a very tricky animal especialyl when death is involved.

“But I need to pay the rent”

Look, if the landlords evict us, we will *end* them. All we have to do is a special type of general strike where we give them all the money. Once all the tokens are in one group’s possession, they are totally worthless and then we will create a new type of money. Remember, we make the value, they don’t. Go back and read resource allocation as a group, especially the last part.

More COVID thoughts

March 24th, 2020

So, let me just address a few of the most obvious points here, in order.

#1: Yes, I have COVID. No, I don’t meet the diagnostic criteria, but that doesn’t mean I don’t have it, it means the diagnostic criteria are wrong. In a few minutes I’ll explain a bit more about that, but first let’s address the next point..

#2: NO I AM NOT GOING TO GET TESTED. THIS IS A STUPID THING TO DO. IF YOU THINK YOU HAVE IT – shelter in place. IF YOU THINK YOU DON’T HAVE IT – shelter in place. Me getting tested would just potentially expose health care workers to it and get me a whopping big bill from our – let’s face it, evil – health care system. It wouldn’t change anything. I wouldn’t live my life any differently if I had it or if I didn’t.

So, I’ve never had a fever for longer than a week in my life. I’ve had low grade fevers every night for the past 2.5 weeks. The odds of me having something that is *not* COVID while the world is having a pandemic are vanishingly small.

#3: No, doctors are not that great at what they do. Actually, they’re pretty terrible. This is a inevitable consequence of having health care be for profit – the system ends up optimizing for profit instead of for good hea#4: Having a criterion for a fever is a *Stupid* thing. Look, if you’re over 30, you *know* your body by now. You know what it’s regular core temp is. You know when it’s elevated. The *reason* it’s elevated is that information theory tells us comparing a lot of strings of information on billions of cells is a energy-expensive operation. Please don’t let the doctors confuse you. Most of the other symptoms are because systems are being damaged because cells that should be doing something useful are being hijacked to instead be replicators of the virus.

If you’re sick right now, odds are you have COVID. On the other paw, if you’re the type of person who has an easier time staying inside because you believe you’re not sick with it and you might catch it, by all means, believe you’re not sick. but in reality.. I watched many many many of my friends all get sick at the same time. Don’t kid tourself.

#4: We’re gonna get through this by working together, trusting each other, and sharing. If we keep holding onto our old ideas – about all sorts of things – we’re going to have a much rougher time of it than if we start accepting some new ideas. The world is going to change. It pretty much has to. I hope that COVID makes us all realize that we have *always* been throwing 3% of our population under the bus for no good reason – the bottom 3%. I also hope that we learn how to unbrainwash the conservatives.. at this point surely no one can really claim that we don’t have enough for everyone to eat and live indoors, or that it’s a good idea to use a resource allocation system that results in people starving to death while we have plenty of food and freezing to death while we have plenty of houses.

#5: We need to invite the chinese team that beat htis to temporarily control the USA. This is no time for stupid patriotism, stupid me-first-ism, or stupid “i’m a stable genuis”. They have a proven track record, they are only having a few cases a day. they beat it. We need their help. Yes, we’re going to temporarily lose all privacy as to our location, and that’s a *good thing*. The government needs to admit that after this we are having a constitutional convention, and that we are actively destroying all for-profit organizations related to health.

#6: Going forward, if we are going to keep increasing the population of earth, we *need* to have a trustworthy government. Our form has obviously failed. We need something new. That we could *get* to the point of electing Trump makes it obvious that what we were doing simply does not work.

#7: As far as I know I’m going to live through this. It doesn’t seem to be getting any worse and actually the fever has been going down.

For Jennifer And Vicky

March 22nd, 2020

The Living Years, by Mike and the Mechanics

Every generation
Blames the one before
And all of their frustrations
Come beating on your door

I know that I’m a prisoner
To all my Father held so dear
I know that I’m a hostage
To all his hopes and fears
I just wish I could have told him in the living years

Crumpled bits of paper
Filled with imperfect thought
Stilted conversations
I’m afraid that’s all we’ve got

You say you just don’t see it
He says it’s perfect sense
You just can’t get agreement
In this present tense
We all talk a different language
Talking in defence

Say it loud, say it clear
You can listen as well as you hear
It’s too late when we die
To admit we don’t see eye to eye

So we open up a quarrel
Between the present and the past
We only sacrifice the future
It’s the bitterness that lasts

So Don’t yield to the fortunes
You sometimes see as fate
It may have a new perspective
On a different day
And if you don’t give up, and don’t give in
You may just be OK.

Say it loud, say it clear
You can listen as well as you hear
It’s too late when we die
To admit we don’t see eye to eye

I wasn’t there that morning
When my Father passed away
I didn’t get to tell him
All the things I had to say

I think I caught his spirit
Later that same year
I’m sure I heard his echo
In my baby’s new born tears
I just wish I could have told him in the living years

Say it loud, say it clear
You can listen as well as you hear
It’s too late when we die
To admit we don’t see eye to eye

Some proof that we’re being stupid

March 22nd, 2020

#1: Some hackers start 3D-printing and sharing shapefiles for medical equipment. They promptly get sued.
#2: Tesla is told it can’t keep making cars. EVERY CAR IS 30kwh ON THE HOOF. If the grid goes down.. and it might, disasters don’t always come at you one at a time.. they could run oxygen concentrators and ventilators just by attaching a inverter to the 12V battery and leaving the car turned on but in park. Think of a electric car as a ‘bucket’ for carrying power from the grid to places that might have lost it. Tesla is one of the few mfgrs who should be scaling up.. along with makers of solar panels, batteries, and wire. We don’t know how bad this is gonna be, but.. if naught else, we’ll be better prepared next time.

Jeff Lane

March 22nd, 2020

So, a long time ago, when I first wandered into Epoch and said, as I recall, “Um, I think I work here now?”, I met this guy – Jeff Lane. He was the first friend that I made at Epoch (back when it was HLC internet), and we used to come in on weekends even though it wasn’t our shift and have bagels and barqs rootbeer and talk about stuff. I taught him some things about how the internet works, and he taught me some things about how life works. He was a really bighearted, great guy. I can’t really say enough about how friendly, likable, and enjoyable to be around he was.

We played a lot of warcraft2 and answered a lot of customer phone calls, and we remained friends throughout the years. The last time I saw him was way too long ago, seven or eight years I think, but we still chatted on facebook regularly.

Recently, he left earth – logged out, as I like to say – his body failed him. I will write more about that and how I think the health care system contributed to it later. But.. I wrote some music for him, and I thought I’d share it with you all.

Jeff Lane.

Godspeed and au revoir, Jeff. Until we meet again… you will be missed.

You Idiots, You’re Not Hoarding Wealth, You’re Hoarding Pointers!

March 21st, 2020

So, as I’ve talked about before, money is a pointer in the C sense of the word. It isn’t the actual value, it’s a token that represents the value. If you missed that part, go back to the top of http://moneynotvalue.sheer.us and come back and join us when you’re done.

Okay, so, here’s how our current resource allocation system can actually make real value disappear.

At some point, some jackass who didn’t understand that money is a pointer invented the idea of “interest”. Call it what you like, vig, whatever. Once you have interest in the system, several things happen:

1) The “wealthy” i.e. those who already have too many of the fucking pointers.. get more pointers. Which they can then use to capture even more pointers. However, if the pointer dissapears, the value is not gone. If you destroy the value, the pointer points to nothing. Go ahead, grab a C compiler and try it. I’ll wait.

2) The “poor” i.e. those who don’t have all the tangible resources they need but don’t have the tokens.. get less real stuff, and more of it sits on the shelf. Some types of stuff LOSE VALUE – REAL VALUE – as they sit on the shelf. I gesture you to milk as a prime example. So we end up wasting resources – real resources – because of these stupid clowns who don’t understand the difference between the map and the territory.

2.5) A reminder.. when the creators can’t get enough tokens they can’t create wealth. So by hoarding pointers, the “wealthy” are making us all – *INCLUDING YOURSELVES* – less wealthy. Real wealth isn’t a million dollars, it’s a bunch of friends and a holodeck. And, as I’ve talked about before, if we work together we can write neurological software that will give us all a holodeck! without draining the planet’s resources at all and while our bodies continue to keep the lights on.

3) The “wealthy” become increasingly afraid someone will steal their hoarde. Because we were designed by evolution in a world where resources were scarce and we were competing with tigers and other things that outclassed us until we became tool users, we have built in fear about losing resources because in most of the race’s lifespan, losing resources meant starving to death. That’s hardwired in.

4) The “poor” become increasingly afraid to take risks, which results in less of the ACTUAL VALUE. For example, musicians who end up flipping burgers instead of recording all that great stuff because they’re afraid they won’t be able to eat and live indoors, and thusly afraid they will die.

So, all the brokenness will go away if we make a few basic changes to money, which I’ll talk about in a future article. For now, you assholes who are hoarding too many tokens.. you know who you are.. those tokens are not value, and the only type of power they give you is the power to cause something like the current COVID-19 crisis to blow up enourmously. We can safely bet the USA will be on the *top* of the cases and deaths list, because people are afraid to leave their jobs, because you assholes couldn’t get your shit together to have a plan, and talk it over *before* the next pandemic, where we would temporarily switch to a simple go/no go system for resource allocation instead of dollars in the bank. See “This Perfect Day” for a example of how this can work. (Yes, I know it’s a dystopia, but that part is pretty utopic)

I will also mention, as a side note, that resource allocation systems are like operating systems or any other type of tool, YOU USE THE RIGHT ONE FOR THE JOB! We *need* full on collectivism right now. However, we can’t get there from here, because:

A) No one realizes what time it is. To me, it is obvious that whenever we punch the brakes on the disease, it’s going to be two weeks before we see the output side of that. Procject a moving average filter of the number of cases per day into the future two weeks and tell me that our “built for profit” health care system is even going to be able to pretend to cope. And yet, people are still billing and suing each other. Guys, I am declaring a emergency. Pilots out there will know that at this point we have three priorities – Aviate, Navigate, Communicate. All three are directly related to keeping us alive to fly another day. No one wants to bend a airplane but if you kill yourself trying to save the airframe you are a moron who does not understand we mass produce these things in factories all day long and they are replacible, we are not.

Similarly, companies are replaceable, individuals are not. The company I work for (a multilevel marketing firm i.e. a system where you sell to your friends, usually at in-person “parties”) who will remain nameless has not yet announced they are turning off minimums (the value under which you get no commission for your team and may also be kicked off the island) and they encourage people to prioritize survival above selling. Not only that, they want to raise commissions, incentivizing people to continue to sell. The big risk here is a lot of these people have believed the lies of the president and other conservatives and therefore will have in-person MLM parties, encouraging the spread of the virus and costing us lives. I ask you, if even one employee has to die, is it not better that the company die instead? We can always build another of those. We can’t replace ANY of the people. (To their credit, they do have a option to do the parties virtually. But even though I’ve put them in a position to release it to everyone, to the best of my knowledge they have not done so)

Look at the exponential growth curve on this thing and grow up. It’s time we prioritize survival, we will figure out the bills when we’re done. And if any hospital is still running their billing department, hopefully their charter will be lifted and they will be handed to the government when we’re done. They have failed to understand that as a species, we are all connected, and the thing they are collecting isn’t the value, it’s a bunch of stupid, potentially worthless pointers – but most people are not exposed enough to all the ideas I have been exposed to to be able to see money that way.

B) The milgram effect keeps a lot of the people who *do* see the situation for what it is from doing the right thing. I talk about elsewhere in this journal how we are a loosely confederated collection of subnets and most of those subnets have no great way to authenticate information sources or the validity of information. Therefore, when people project authority and claim authority we tend to follow their directions even when we know they are wrong.

C) Beyond this, a deeply wired fear about starving to death and freezing to death kicks in whenever our ‘Jobs’ are threatened, because the wealthy (who would be far more wealthy if they hadn’t done this) hoarded a bunch of pointers that in fact are just pointers and have no real value. Hint for you rich folks: you *need* the rest of us. Go read my essay on resource allocation as a group, and let me know how you’re going to be more wealthy after the crash you’re causing right now by not just announcing “here, take it all, spread it as needed, avert those people’s fears so they can stay home instead of spreading this fire further and faster.

This is a fast moving wildfire, folks. We gotta smarten up if we’re going to come out of it ahead.