Monday, 7 September 2020

Python DB Connectivity and Serial Port Connection

 HI,

Use this code


-----------------------------

import mysql.connector

import time;

import serial;

from mysql.connector import Error

from mysql.connector import errorcode

ser = serial.Serial('COM3', 9600, timeout=0,parity=serial.PARITY_EVEN, rtscts=1)


try:

   connection = mysql.connector.connect(host='localhost',

                             database='hupiot',

                             user='root',

                             password='hup')

   cur = connection.cursor()

   while True:

      s=ser.read();

      print(s);

      time.sleep(1);

      sql=("INSERT INTO timerecord (userid, recordtime, userrole ) VALUES (%s,%s,%s)")

      val=("1",s,"1")

      if s=="9":

         cur.execute(sql,val)

   connection.close()

except mysql.connector.Error as error :

    connection.rollback() #rollback if any exception occured

    print("Failed inserting record into python_users table {}".format(error))


7 comments:

  1. Nicely written and great information.
    We are technology/news/smartphone company, If you want to read such useful news then, Visit us: https://techmie.com/

    ReplyDelete
  2. Si Contact Form Plugin using for captcha to setup contact form in get it proper way it make properly

    ReplyDelete
  3. Woocommerce Floating Cart setup in woocommerce side cart in your ecommerce website

    ReplyDelete
  4. Frequently Bought Together For Woocommerce making to you can bought combo product in woocommerce with good discount in your website

    ReplyDelete
  5. Calculated Fields Form WordPress Plugin In Calculate Field to each other we can use wordpress plugin for calculation. let We explain you how to make Calculation Field in wordpress.

    ReplyDelete
  6. Phoenix Binary System is a professional Website Development Company in Anand Gujarat. Mobile App, SEO company in Anand, Web Design Company in Surat.

    ReplyDelete
  7. AI Patasala Python Course in Hyderabad is sure to be the ideal choice for those looking to gain insight into all the real-world challenges in this field. AI Patasala Python course is the best option for students to begin their career with the latest technology.
    AI Patasala Python Course

    ReplyDelete