Skip to content

Instantly share code, notes, and snippets.

View ASolchen's full-sized avatar

Adam Solchenberger ASolchen

  • WI, USA
View GitHub Profile
import time, struct
import numpy as np
import matplotlib.pyplot as plt
path = 'E:/big_ass.rdd'
ptr = 0
np_ptr = 0
buff = np.zeros([2,2000000], np.float64)
t = time.time()
with open(path, 'rb') as f:
@ASolchen
ASolchen / interp.py
Created April 18, 2018 18:56
numpy interp1d
from scipy.interpolate import interp1d
import numpy as np
old_time = np.linspace(0, 10, num=11, endpoint=True)
old_vals = np.sin(old_time)
f = interp1d(old_time, old_vals)
f2 = interp1d(old_time, old_vals, kind='cubic')
new_time = np.linspace(0, 10, num=1000, endpoint=True)
@ASolchen
ASolchen / pyads_window.py
Created January 9, 2019 17:45
Basic window to talk to a Beckhoff controller using PyGObject and pyads
#local ip is 10.10.10.11
#PLC ip is 10.10.10.10
#route setup on PLC's ADS router AmsNetID 10.10.10.11.1.1 and IP 10.10.10.11
import gi, shutil, os
import pyads
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gdk
def setup_ads():
@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">
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:
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 = ''
@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,
@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 / 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 / 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__()