1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import serial
- from serial import SerialException
- import _thread
- import struct
- import numpy as np
- import math
- import time
- from matplotlib import pyplot as plt
- ser = None
- portName="COM6"
- while not ser:
- try:
- ser = serial.Serial(portName, 115200)
- except serial.SerialException:
- print(portName, " not available")
- portName="COM" + input("COM")
- print("Connected to ", ser.name)
- def read():
- while 1:
- if ser.inWaiting()>0:
- print(ser.read(ser.inWaiting()).decode("utf-8"))
- time.sleep(.1)
- _thread.start_new_thread( read, () )
- def write(val):
- ser.write((int(val)&0xFF).to_bytes(1, byteorder='big', signed=False))
- def writeInt(val):
- ser.write((int(val)&0xFFFF).to_bytes(2, byteorder='big', signed=False))
- def writeLng(val):
- ser.write((int(val)&0xFFFFFFFF).to_bytes(4, byteorder='big', signed=False))
- ser.write(b'~t~c"')
- for i in range(64):
- ser.write(b'~b')
- write(i)
- writeLng(i*65536/64)
- writeLng(65536/64)
- time.sleep(0.2)
- """
- time.sleep(.5)
-
- for i in range(65535):
- for k in range(4):
- ser.write(b'~a')
- for n in range(4):
- for m in range(16):
- write(i+32+n*8-m*3)
- time.sleep(0.015 / 4)
- ser.write(b'~y')
- write(k)
- time.sleep(0.02)
- ser.write(b'~z')
- writeInt(i)
- time.sleep(0.02)
- ser.write(b'~s')
- # close stream
- """
|