Exemple #1
0
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from flask_wtf import FlaskForm
from wtforms import TextField, IntegerField, TextAreaField
from wtforms import SubmitField, RadioField, SelectField
from wtforms import validators, ValidationError
from wtforms import StringField
from wtforms.validators import DataRequired
from flask_script import Manager
from frame import Frame

from threading import Thread, Lock
from hksSer import serThread
import time

mySer = serThread()

app = Flask(__name__)
app.config['SECRET_KEY'] = 'hard to guess string'

bootstrap = Bootstrap(app)
moment = Moment(app)
manager = Manager(app)


class ControlForm(FlaskForm):
    gid = IntegerField("Group Id:   ",
                       [validators.Required("Please enter your name.")])
    pid = IntegerField("Private Id: ", [])
    # pid = IntegerField("Private Id: ",[validators.Required("Please enter your name.")])
    level = IntegerField("Level:     ", [])
Exemple #2
0
import socketserver
import time
from hksSer import serThread
from datetime import datetime
from frame import Frame

# port = '/dev/ttyS0'
# port = '/dev/ttyUSB0'
ttyS0 = serThread('COM7')
rs485Ser = serThread('COM30')
class MyTCPHandler(socketserver.BaseRequestHandler):
    myFrame = Frame()

    def FileSave(self,filename,content):
        import io
        with open(filename, "a+") as myfile:
            myfile.write(content)
    def procSerial(self, port):
        if port == 0:
            ser = mySer

    def handle(self):
        dt = datetime.now()
        # self.request is the TCP socket connected to the client
        print('Rasp-->------------------ server Start ----------------------')
        self.data = self.request.recv(1024).strip()
        self.myFrame.parseFrame(str(self.data,'utf-8'))
        print('Rasp-->Network Type:{}'.format(self.myFrame.micom1[0]))

        testStr = "Rasp-->{} wrote: when {}:{} \n".format(self.client_address[0],
        dt.date(), dt.time())