Serialport via PHP is broken by design.
(PHP dont support iocontrols)
Fix in python
Greetings
---------
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import serial, time, sys
#-------------------------------------------------------------------
SerialPort = "/dev/ttyUSB0"
SerialBaudrate = 2400
#-------------------------------------------------------------------
# serial docu: http://pyserial.sourceforge.net/pyserial.html
#-------------------------------------------------------------------
def SerialAuslesen(serObject):
while True:
try:
# Remove newline character '\n'
serObject.write('QPIGS\xb7\xa9\x0d')
#response = serObject.readline().strip()
response = serObject.readline()
if response:
#print("Serial-> "+str(response)),
# ...do something with it...
f = open("/tmp/rs232daten.txt","w")
f.write(str(response))
f.close()
except serial.SerialException as e:
print("Could not read serial port '{}': {}".format(SerialPort, e))
except (KeyboardInterrupt, SystemExit):
sys.exit()
serObject.close()
#-------------------------------------------------------------------
def main():
#initialization and open the port.
#possible timeout values:
# 1. None: wait forever, block call
# 2. 0: non-blocking mode, return immediately
# 3. x, x is bigger than 0, float allowed, timeout block call
ser = serial.Serial()
ser.port = SerialPort
ser.baudrate = SerialBaudrate
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
#ser.timeout = None #block read
ser.timeout = 1 #non-block read
#ser.timeout = 2 #timeout block read
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
ser.writeTimeout = 2 #timeout for write
try:
ser.open()
except Exception as e:
print("Error open serial port: " + str(e))
sys.exit()
if ser.isOpen():
try:
ser.flushInput() #flush input buffer, discarding all its contents
ser.flushOutput() #flush output buffer, aborting current output and discard all that is in buffer
SerialAuslesen(ser)
except Exception as e:
print("Error...: " + str(e))
except (KeyboardInterrupt, SystemExit):
print("\nSchliesse Programm..\n")
if ser: ser.close()
sys.exit()
if __name__ == '__main__':
main()
python code for serialport
Re: python code for serialport
Hi,
I don't get the sense of this message
I don't get the sense of this message

Re: python code for serialport
> Serialport via PHP is broken by design.
> (PHP dont support iocontrols)
https://fr.wikipedia.org/wiki/Ioctl
https://en.wikipedia.org/wiki/Ioctl
?
// $fp = fopen("/dev/ttyUSB0", "w+"); //xxxx serialport com1 com2 ...
// $byte = fgetc($fp);
both will hung "sometimes", and if... than forever.
Greetings
Tron
> (PHP dont support iocontrols)
https://fr.wikipedia.org/wiki/Ioctl
https://en.wikipedia.org/wiki/Ioctl
?
// $fp = fopen("/dev/ttyUSB0", "w+"); //xxxx serialport com1 com2 ...
// $byte = fgetc($fp);
both will hung "sometimes", and if... than forever.
Greetings
Tron
Re: python code for serialport
Hi tron,
I still don't understand, what do you wanna do ?
I still don't understand, what do you wanna do ?
Re: python code for serialport
Greetings
I have heavy modified the effecta code from project to work with
ISolarSMV II 3kW Inverter
connected to Raspberry via USB <--> RS - Serialport.

// $fp = fopen("/dev/ttyUSB0", "w+"); //xxxx serialport com1 com2 ...
// $byte = fgetc($fp);
and this php don't work stabil.
I have sended the python workaround... (works stabil nonstop since 6 weeks)
i think (?) modpoll is an equivalent in compiled-code.
The ISolarSMV II 3kW Inverter supports isle - mode... means: it can load / unload an DC accumulator and transform 230V~ AC.
Currently i am adding accu-status / loadlevel to the Gfx... but i am very busy ....
Can you me explain what values Grid-Ph1 exact "means"?

6 Values and and they dont match together.
But i check this php-code.
One leek is here in the Inverter-Data. if accus loading then this "energy" is not "explicit" in the Data, (i have to calculate this von Accu )
The monitoring of the accus is main-goal here.
Is there a place where i can upload my changes? in the next 1-2 months?
Greeting and thanks for you work
Tron
--
This python code fetches the Datarecord from Inverter and wrote it to /tmp than can php read it from there.
/tmp is mounted as tmpfs (RAM-Disk, no SD-Card)
#vi /etc/fstab
tmpfs /tmp tmpfs rw,nosuid,nodev 0 0
I have heavy modified the effecta code from project to work with
ISolarSMV II 3kW Inverter
connected to Raspberry via USB <--> RS - Serialport.

// $fp = fopen("/dev/ttyUSB0", "w+"); //xxxx serialport com1 com2 ...
// $byte = fgetc($fp);
and this php don't work stabil.
I have sended the python workaround... (works stabil nonstop since 6 weeks)
i think (?) modpoll is an equivalent in compiled-code.
The ISolarSMV II 3kW Inverter supports isle - mode... means: it can load / unload an DC accumulator and transform 230V~ AC.
Currently i am adding accu-status / loadlevel to the Gfx... but i am very busy ....
Can you me explain what values Grid-Ph1 exact "means"?

6 Values and and they dont match together.

But i check this php-code.

One leek is here in the Inverter-Data. if accus loading then this "energy" is not "explicit" in the Data, (i have to calculate this von Accu )
The monitoring of the accus is main-goal here.
Is there a place where i can upload my changes? in the next 1-2 months?
Greeting and thanks for you work
Tron
--
This python code fetches the Datarecord from Inverter and wrote it to /tmp than can php read it from there.
/tmp is mounted as tmpfs (RAM-Disk, no SD-Card)
#vi /etc/fstab
tmpfs /tmp tmpfs rw,nosuid,nodev 0 0
Re: python code for serialport
Hi,
It's now a bit clearer for me
I can add new protocols files if needed.
Grid-Ph1 is the grid values (AC), Power, Voltage and Current on phase 1.
You can put your app in http://sourceforge.net, https://github.com, ..
It's now a bit clearer for me

Grid-Ph1 is the grid values (AC), Power, Voltage and Current on phase 1.
You can put your app in http://sourceforge.net, https://github.com, ..
Who is online
Users browsing this forum: No registered users and 2 guests