Skip to content

Instantly share code, notes, and snippets.

View ASolchen's full-sized avatar

Adam Solchenberger ASolchen

  • WI, USA
View GitHub Profile
@ASolchen
ASolchen / py_print_test.py
Created April 23, 2024 16:12
Print PDF Report
from subprocess import Popen, PIPE
import os, time, datetime
cwd = os.getcwd()
ACROBAT = "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe"
PDF = os.path.join(cwd, 'sample.pdf')
TEMP_FILE = os.path.join(cwd, 'Temp.html')
from pyhtml2pdf import converter
HTML = """
@ASolchen
ASolchen / py_mod_sim.py
Created April 12, 2024 01:57
Kivy UI for testing modbus TCP clients
#!/usr/bin/env python3
#pip install kivy and pyModbusTCP
__version__ = '1.0'
import kivy
kivy.require('2.2.0')
from kivy.app import App
from kivy.clock import Clock
@ASolchen
ASolchen / traffic.py
Created March 17, 2023 16:11
Get SNMP 5 min average switchport traffic on a 48-port Cisco 2960
"""
!add this to the switch config:
snmp-server community public RO
snmp-server location in some closet
snmp-server contact email@server.com
"""
from pysnmp.hlapi import *
@ASolchen
ASolchen / cip_server.py
Last active January 14, 2022 05:06
cip_server basic example
#!/usr/bin/env python3
import socket, struct, time
from pycomm3.packets.base import ResponsePacket, RequestPacket
from pycomm3.packets.ethernetip import RegisterSessionResponsePacket, DataItem
from pycomm3.cip.services import Services, EncapsulationCommands
class CIPServer(object):
def __init__(self) -> None:
super().__init__()
@ASolchen
ASolchen / raC_Dvc_E300_Rung.L5X
Created December 14, 2021 20:17
e300 Rung import
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RSLogix5000Content SchemaRevision="1.0" SoftwareRevision="31.02" TargetType="Rung" TargetCount="1" ContainsContext="true" ExportDate="Thu May 20 03:25:02 2021" ExportOptions="References NoRawData L5KData DecoratedData Context RoutineLabels AliasExtras IOTags NoStringData ForceProtectedEncoding AllProjDocTrans">
<Controller Use="Context" Name="PowerDiscreteDeviceObjects">
<DataTypes Use="Context">
<DataType Name="raC_UDT_Event" Family="NoFamily" Class="User">
<CustomProperties>
<Provider ID="ACM" Ext="0">
<Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Maj="1" Min="0" OExt="-1" UExt="1">
<Libs>
<LibHdr CatalogNumber="raC_Dvc_AS281E" Guid="0D88D226-393F-4D0F-8F3F-B04A585A2698" />
@ASolchen
ASolchen / alarm_duration.py
Created August 31, 2021 16:31
python script to compute alarm duration in FactoryTalk View SE database and update the Tag1Value column of the "out of alarm" row
import pyodbc
TICKS_PER_SEC = 10000000.0 # Factorytalk Alarm and Event ticks / sec
server = 'localhost\SQLEXPRESS'
database = 'FTVSE_AE'
username = 'python' # using SQL credentials
password = 'python_pw'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password+';Trusted_Connection=no;')
cursor = cnxn.cursor()
@ASolchen
ASolchen / ftvse_db_backup.py
Last active October 13, 2020 15:51
FactoryTalk Veiw Site Edition Alarm and Event SQL Server backup to SQLite
import sqlite3
import pyodbc
TABLES = {
"FTAEInstance": """
CREATE TABLE IF NOT EXISTS [FTAEInstance](
[lFTAEInstanceId] [int] NOT NULL,
[sProduct] [varchar](255) NOT NULL,
[sCatalogNumber] [varchar](255) NULL,
[lMajorVersion] [int] NOT NULL,
const { Controller, Tag, EthernetIP } = require("ethernet-ip");
const { SINT, DINT } = EthernetIP.CIP.DataTypes.Types;
const PLC = new Controller();
const readString = (name)=>{
return new Promise(async (res, rej)=>{
try{
str = ''
import struct
from ctypes import *
import numpy as np
def get_timespan(fn):
with open(fn, "rb") as fp:
fp.seek(1024)
data = True
first = None
last = None
while data:
@ASolchen
ASolchen / logo.html
Created August 4, 2019 14:02
Testtech Logo SVG
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>widget</title>
</head>
<body>
<svg width="400" height="400">
<path fill="#AAA" d="M0,0 V400 H400 V0 H0" stroke="#000" stroke-width="4" />
<circle stroke="#000" stroke-width="10" fill="#FFF" cx="200" cy="200" r="100">