File: /Home/Netza/Ubuntupc/Home/Twentytwo - Py Page 1 of 2: Gamelogic Bge Bge Pymodbus - Client.Sync
File: /Home/Netza/Ubuntupc/Home/Twentytwo - Py Page 1 of 2: Gamelogic Bge Bge Pymodbus - Client.Sync
py Page 1 of 2
#!/usr/bin/env python
import bge
import math
#import aud
from GameLogic import globalDict as G
from bge import logic as g, events
from bge import logic
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
#sound = aud.Factory.file("/home/netza/lmms/projects/motorsound.ogg")
#device = aud.device()
scene = logic.getCurrentScene()
G['s']=scene
G['O'] = G['s'].objects
G['K'] = bge.logic.keyboard
G['E'] = bge.events
G['O3']=G['O']['Cube.003']
def myconnect():
import logging
#logging.basicConfig()
#log = logging.getLogger()
#log.setLevel(logging.DEBUG)
client = ModbusClient(host='127.0.0.1', port=5567)
testconnect = client.connect()
print(testconnect)
rr = client.read_holding_registers(0, 4)
print(rr.registers[0])
print(rr.registers[1])
print(rr.registers[2])
print(rr.registers[3])
G['O3']['d']= rr.registers[0]
rc = client.read_coils(0, 1)
print(rc.bits[0])
G['O3']['c']= rc.bits[0]
client.write_register(5,G['O3']['a'])
client.write_coil(1, G['O3']['b'])
client.close()
myconnect()
G['Sensor3'] = G['O']['Cube.003'].sensors["Ray"]
print("Sensor3",G['Sensor3'].positive)
G['Sensor4'] = G['O']['Cube.004'].sensors["Ray"]
print("Sensor4",G['Sensor4'].positive)
move =G['O3']['d']/2000
loc = 0.0
rot = 0.0
G['O']['Sphere'].replaceMesh('Sphere.001')
G['s'].lights["Lamp.002"].color=[1,1,1]
G['O']['Cube.003'].color=[1,1,1,1]
G['O']['Cube.004'].color=[1,1,1,1]
if G['O3']['c']:
G['s'].lights["Lamp.002"].color=[1,0,0]
G['O']['Sphere'].replaceMesh('Sphere.002')
if G['Sensor3'].positive:
rot = -move
G['O3']['a'] = 20
File: /home/netza/ubuntupc/Home/twentytwo.py Page 2 of 2
G['O3']['b'] = True
G['O']['Cube.003'].color=[1,0,0,1]
if G['Sensor4'].positive:
rot = -move
G['O3']['a'] = 25
G['O3']['b'] = False
G['O']['Cube.004'].color=[1,0,0,1]
#if move != 0 :
# device.play(sound)
if G['O3']['c']:
angle = math.pi/2
G['O']["Empty"].worldOrientation = [0.0, 0.0,angle]
G['O']["Cylinder.012"].worldOrientation = [angle, 0.0, 0.0]
G['O']["Cylinder.011"].worldOrientation = [angle, 0.0, 0.0]
G['O']["Cylinder.008"].worldOrientation = [angle, 0.0, 0.0]
G['O']["Cylinder.007"].worldOrientation = [angle, 0.0, 0.0]
G['O']["Cylinder.004"].worldOrientation = [angle, 0.0, 0.0]
G['O']["Cylinder.001"].worldOrientation = [angle, 0.0, 0.0]
G['O']["Cylinder.002"].worldOrientation = [angle, 0.0, 0.0]
rot = move
if not G['O3']['c']:
angle = math.pi/2
G['O']["Empty"].worldOrientation = [0.0, 0.0,0]
G['O']["Cylinder.012"].worldOrientation = [0.0, angle, 0.0]
G['O']["Cylinder.011"].worldOrientation = [0.0, angle, 0.0]
G['O']["Cylinder.008"].worldOrientation = [0.0, angle, 0.0]
G['O']["Cylinder.007"].worldOrientation = [0.0, angle, 0.0]
G['O']["Cylinder.004"].worldOrientation = [0.0, angle, 0.0]
G['O']["Cylinder.001"].worldOrientation = [0.0, angle, 0.0]
G['O']["Cylinder.002"].worldOrientation = [0.0, angle, 0.0]
rot = -move
if move == 0.0:
G['O']["Cylinder.012"].setAngularVelocity((0.0, 0.0, rot), 1)
G['O']["Cylinder.011"].setAngularVelocity((0.0, 0.0, rot), 1)
G['O']["Cylinder.008"].setAngularVelocity((0.0, 0.0, rot), 1)
G['O']["Cylinder.007"].setAngularVelocity((0.0, 0.0, rot), 1)
G['O']["Cylinder.004"].setAngularVelocity((0.0, 0.0, rot), 1)
G['O']["Cylinder.001"].setAngularVelocity((0.0, 0.0, rot), 1)
G['O']["Cylinder.002"].setAngularVelocity((0.0, 0.0, rot), 1)