''16-12-2018 ' rajout jour calendaire ' recup de clui ci dans Joursemaine() '15-12-2018 ' modif pour Grafique Glissant '14-12-2018 ' rajout temperature moyenne avec KWH journalier ' avec simulation : Vbray_Script_Simulation_envoi_Trame_EDF_181214.tsc Const LongMini=90 ' en reel ' Const LongMini=100 '08/12/2018 'reelle '*C050222059498*;*W00050714221*;*K 1549.221*;*R00011*;*A00005*,*G00005,00011*;*T 11.8*;*O 49165000* 'ou simulée avec TRAME FIXE 'Vbray_macro_simule_1_Trame_EDF_181207.tmf 'MACRO 'C050222059498*;*W00051714221*;*K 1549.221*;*R00011*;*A00005*,*G00005,00011*;*T 11.8*;*O 49165000*#013 'Edfinfo_Vbray_scipt_Trame_simulee_181208.tsc 'simulee '*C050222059498*;*W00049904164*;*K 739.164*;*R19*;*A00009*,*G00009,19*;*T19.0*;*O 49165000* $Apptype GUI Application.Title = "EdfInfo_via_BT" Const Version= "15-12-2018 (Win10)" $TYPECHECK ON $OPTIMIZE ON '$Include "QLed.inc" $Include "inc\Rapidq.inc" $Include "QCanvasEx.inc" $INCLUDE "inc\MyQChart.inc" ' convertisseur image -> icone ' http://image.convertstandard.com/ToICO32x32.aspx $option Icon "ico\mylogo1.ICO" ' ICON file required 766 bytes. ' rajout table KWH/24H '01-12-2018 ' rajout stockage Temperature amb1 journaliere ' usage de valeur "dernier releve EDF" pour afficher la conso en KWH ' dernier relevé EDF , en fin de EDF_BT.Ini ' remplacé Msgbox bloquant par un label affiché pendant 5sec '23-11-2018 rajour QCHART Grafique Amperes ' et stockage Amps moyen par minute ' 21-11-2018 ' 4 plantage ecran bleu de windows avec probleme de Signature driver COM Prolific ' impossible de redemerrer ' apres mise hirs tension pendant 10mn => redemarrage OK driver prolifics OK ??? ' Reception OK sur COM3 .. mais impossible avec COM16, 17,19 ' ' 17-11-2018 ne marche plus !! ' redvient OK en triturant le port COM3, driver, passage sur COM17 puis retour sur COM3 => OK ' pas clair !!!! '16-11 ' melasse dans les Qbutton ' rajout option +CR ou +LF sur envoi message ' recup valeur Temp Ambiante et amperes ..OK ' trame emise par PIC16F1847+RN416DB49 (esclave) ' trame PIC16F Edfinfo : longueur = 103 caracteres, émises toutes les 1,2 sec ' reçue coté PC par RN41-EEEC (maitre) '*C050222059498*;*W00050714221*;*K 1549.221*;*R00011*;*A00005*,*G00005,00011*;*T 11.8*;*O 49165000* 'Problemo 13-11-2018 ' Que des zeros dans l'echange de datas ???? ' verif avec SDA Anlayser Stat et Stop bit OK mais Datas toutes à 0 ?? ' recherche de bug ..en long et enlarge ....rien ' test direct cables croisés : COM3 TX-> COM17 RX et COM17 TX-> COM3 RX ' entre les 2 terminaux COM3 et COM17 ..OK ' mais suite à une MAJ de windows (intempestive et impossible à bloquer) ' check des drivers Prolifics .. un driver sur COM3 a été modifié par une ' version prolific pilote du 12/07/2018 au lieu de pilote 17/07/2009 ' modif manuelle du pilote et redemearrage ' test Echange datas entre programme (COM3) et terminal COM17 ..OK ' 'rev 12 nov 2018 ' correction bug sur reception ' rajout timeout reception apres 15 secondes ( 30x500mS) ' rajout ruban progression buffer reception ' Rajout commande MAJ RTC .. au format trame appli PIC18F 'reste PB sur DayofWeek 'rev 11 nov 2018 'fichier *.ini pour setup COM '177 ' Top window '1237 ' left Window '4 ' 19200 bds '0 ' NO parity '1 ' Nb datas 8 '0 ' 1 stop '2 ' COM3 Declare Function SetFocus Lib "user32"Alias "SetFocus" (ByVal hwnd As Long) As Long Declare Function GetFocus LIB "user32" alias "GetFocus" () as Long Declare Function OPENCOM Lib "Dll\RSCOM.dll" alias "OPENCOM"(ByVal OpenString$) As Integer 'ouvre le port Declare Sub CLOSECOM Lib "Dll\RSCOM.dll"alias "CLOSECOM" () 'fermer le port com Declare Sub TXD Lib "Dll\RSCOM.dll" alias "TXD" (ByVal b%) 'broche 3 envoie, Emission de données Declare Sub DTR Lib "Dll\RSCOM.dll" alias "DTR" (ByVal b%) 'broche 4 envoie, Terminal prêt. Declare Sub RTS Lib "Dll\RSCOM.dll" alias "RTS" (ByVal b%) 'broche 7 envoie, Demande d'emmission Declare Function DCD Lib "Dll\RSCOM.dll" alias "DCD" As Integer 'broche 1 lecture, Dectection de porteuse Declare Function DSR Lib "Dll\RSCOM.dll" alias "DSR" As Integer 'broche 6 lecture, Emmission prête Declare Function CTS Lib "Dll\RSCOM.dll" alias "CTS" As Integer 'broche 8 lecture, Prêt à emettre Declare Function RI Lib "Dll\RSCOM.dll" alias "RI" As Integer 'broche 9 lecture, Indicateur de sonnerie Declare Sub CLEARBUFFER Lib "Dll\RSCOM.dll" alias "CLEARBUFFER"() 'Nettoye le buffer en entrée Declare Function INBUFFER Lib "Dll\RSCOM.dll" alias "INBUFFER" () As Integer 'Nombre de caractère dans le buffer d'entré Declare Function OUTBUFFER Lib "Dll\RSCOM.dll" alias "OUTBUFFER" () As Integer'Nombre de caractère dans le buffer de sortie ? Declare Sub BUFFERSIZE Lib "Dll\RSCOM.dll" alias "BUFFERSIZE" (ByVal b%) 'Change la taille du buffer Taille du buffer Declare Sub DELAY Lib "Dll\RSCOM.dll" alias "DELAY" (ByVal ms As Double) 'delai en micro seconde // duree d'un bit Declare Function INPUTS Lib "Dll\RSCOM.dll" alias "INPUTS" () As Integer '? Declare Sub REALTIME Lib "Dll\RSCOM.dll" alias "REALTIME" () '? Declare Function READSTRING Lib "Dll\RSCOM.dll" alias "READSTRING" () As String 'Relire une chaine Declare Function READBYTE Lib "Dll\RSCOM.dll" alias "READBYTE" As Integer 'Lire un caratère Declare Sub NORMALTIME Lib "Dll\RSCOM.dll" alias "NORMALTIME" () Declare Sub SENDBYTE Lib "Dll\RSCOM.dll" alias "SENDBYTE" (ByVal Dat%) 'Envoyer un caratère Declare Sub SENDSTRING Lib "Dll\RSCOM.dll" Alias "SENDSTRING" (ByVal Dat$)'Envoyer une chaine Declare Sub TIMEINIT Lib "Dll\RSCOM.dll" alias "TIMEINIT" () 'Reinit le temps Declare Sub TIMEOUTS Lib "Dll\RSCOM.dll" alias "TIMEOUTS" (ByVal b%) 'depassement du temps ? 'Declare Function TIMEREAD Lib "Dll\RSCOM.dll" alias "TIMEREAD" () As Double 'donne le temps d'ouverture du port ? Declare sub Activer_Port_COM() Declare Function Trim(Datum As String) As String Declare Function JourSemaine() AS INTEGER Declare Sub Initialise() declare SUB JourCalendaire 'declare Sub Decortique_Date(x$ as string) Declare sub Message(Situation as single) Declare Sub EDF_BTShow(Sender as QForm) Declare Sub EDF_BTClose(Action AS INTEGER) ' 4 boutons Declare Sub Send_ButtonClick(Sender as QCoolBtn) Declare Sub Help_buttonClick(Sender as QCoolBtn) Declare Sub MAJ_RTCClick(Sender as QCoolBtn) Declare Sub SortieClick(Sender as QButton) Declare Sub RAZ_ReceptionClick(Sender as QButton) Declare Sub Raz_Zone_EmissionClick(Sender as QButton) Declare Sub Raz_Zone_DebugClick(Sender as QButton) ' choix parametre COM Declare Sub Port_Combo1Change(Sender as QComboBox) Declare Sub Speed_Combo2Change(Sender as QComboBox) Declare Sub Parity_Combo3Change(Sender as QComboBox) Declare Sub Nb_Datas_Combo4Change(Sender as QComboBox) Declare Sub Nb_StopChange(Sender as QComboBox) Declare SUB Read_COMx() Declare SUB TimerOver() Declare Sub Wh_NowClick(Sender as QLabel) Declare Sub AmperesClick(Sender as QLabel) Declare Sub Origine_CompteurClick(Sender as QLabel) Declare Sub Adding_CRClick(Sender as QRadioButton) Declare Sub Adding_LFClick(Sender as QRadioButton) Declare Sub Add_CRClick(Sender as QCheckBox) Declare Sub TRMNClick(Sender as QLabel) '================ Declare Sub EDF_BTResize (SENDER As QFORM) declare Sub DrawOrig() Declare Sub Initialise() Declare Sub Save_EDFinfo_to_File 'Const MB_NOFOCUS = &H8000& Const Logiciel = "EDF_BT" Const Vir = "EDF_BT.vir" Const Exe = "EDF_BT.exe" Const Ini = "EDF_BT.ini" ' Const SaveAmps="SaveAmps.txt" const TIMEOUT_Trame=250 ' Const Son = "Son\Alerte.wav" dim month$(12) as string dim month(12) as integer ' libell‚ et nb de jours des mois dim JourSem$(8) as string ' Jours de la semaine data Lundi,Mardi,Mercredi,Jeudi,Vendredi,Samedi,Dimanche,Lundi data " ",0,"Janvier",31,"Fevrier",28,"Mars",31,"Avril",30,"Mai",31 data "Jun",30,"July",31,"Aout",31,"Septembre",30,"Octobre",31,"Novembre",30 data "Decembre",31 Dim String_Comm As String ' DIM Information AS STRING Dim Variable$ Dim x as integer Dim infoCom As Integer Dim Com as string Dim Baud as string Dim Parite as string Dim Nb_Datas as string dim Nb_Stop as string Dim Chemin as string Dim Deja as single Dim Fichier as QFilestream Dim Nombre as integer Dim A$ as string ' Dim B1$ as string DIM C$ as string dim Nbytes as integer dim Jt as integer ' Timer1 count DIM dd$ as string DIM DOW$ as string Dim JourSem as integer Dim mm as integer Dim dd as integer Dim yy as integer DIM i as integer Dim j as integer Dim k as integer Dim L1 as long dim L2 as integer Dim Trame_EDF$ as String Dim NumCompteur$ as string Dim NbWattActuel as long dim Last_Releve as single DIm OrigineCompteur as Long Dim Prix_KWH as single ' pour graphiques Dim Table(600) as single Dim Table_T(600) as single dim HH as integer dim Mn as integer dim ss as integer dim Nb_Trame as integer dim Old_Nb_Mn as integer dim Nb_Mn as integer dim Old_HH as integer dim Numjour as integer ' jour calendaire ' dim simulation as integer Dim KWh as Single Dim Amps as single Dim Amps_Moyen as single Dim TemperAmb1 as single ' temper instantannée Dim Temper_Moyen as single ' temper.moyenne sur 1 minute 'valeur horaires Dim Nb_mes_Temp as integer DIm Temper_Heure as single DEFINT maxV = 6001 DIM xdata(0 TO maxV) AS SINGLE DIM ydata(0 TO maxV) AS SINGLE DIM tdata(0 TO maxV) AS SINGLE DIM th AS SINGLE DIM n AS INTEGER DEFINT maxc = 10 'max columns DEFINT maxr = 20 'max rows DIM myTime AS SINGLE Dim Index_Chart as Integer 'pour stockage dans fichiers Dim Amps_Store(1441) as single ' 1 journéee de stockage Dim Temper_Store(1441) as single Dim KWH_Day_Store(25) as single Dim KWH_Year_Store(8786) as single ' 24x366 Dim OldNbWatt as single Dim Delta_KWH as single Dim Temper_Day(24) as single Dim Once as integer Dim Drapeau_Save as integer Declare Sub CoolBtn2Click(Sender as QCoolBtn) Declare Sub RadioButton1Click(Sender as QRadioButton) Declare Sub RadioButton2Click(Sender as QRadioButton) Declare Sub CheckPrixClick(Sender as QCheckBox) Declare Sub Dernier_ReleveChange(Sender as QEdit) Declare Sub Edit1_Prix_KWHChange(Sender as QEdit) Declare Sub Edit1_Prix_KWHKeyPress(Key AS BYTE) Create EDF_BT as QForm Caption = "EDF_BT" Top = 91 Left = 161 Width = 1122 Height = 968 OnShow = EDF_BTShow OnClose = EDF_BTClose BorderStyle = 1 DelBorderIcons = 2 ' Icon = "D:\RapidQ\icon\mylogo.ico" ShowHint = True END CREATE ' voir //D:/RapidQ/examples/qchart/QChart.htm Create Graph1 As QCHART 'Create a copy of the new object Top =300 : Left =50 Height=500 Width=1200 OnPaint = Graph1.PaintChart 'This line REQUIRED to process Repaints cols=4 'Set .Data.ColCount to the number of XY pairs * 2 End Create' Graph1 Create Groupe1 as QGroupBox Parent = EDF_BT Top = 40 Left = 8 Width = 201 Height = 81 Caption = "Port de communication inconnu" Color = -2147483648 End Create Create Send_Button as QCoolBtn Parent = Groupe1 Top = 16 Left = 16 Width = 92 Height = 25 Caption = "Send Msg" OnClick = Send_ButtonClick Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 10 Font.AddStyles fsBold Enabled = False End Create Create MAJ_RTC as QCoolBtn Parent = Groupe1 Top = 48 Left = 16 Width = 92 Height = 25 Caption = "MAJ RTC" OnClick = MAJ_RTCClick Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 12 Font.AddStyles fsBold Enabled = False End Create Create Help_button as QCoolBtn Parent = Groupe1 Top = 48 Left = 112 Width = 76 Height = 26 Caption = "help" OnClick = Help_buttonClick Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 10 Font.AddStyles fsBold End Create Create Sortie as QButton Parent = Groupe1 Top = 18 Left = 114 Width = 77 Height = 24 Caption = "Sortie" OnClick = SortieClick Align = alNone Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 8 Font.AddStyles fsBold End Create ' COM Setup Create Port_Combo1 as QComboBox Parent = EDF_BT Top = 16 Left = 8 Width = 81 Height = 22 Text = "" Color = &HFFFFFF Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 10 AddItems "Com1","Com2","Com3","Com4","Com5","Com6",_ "Com7","Com8","Com9","Com10","Com11","Com12","Com13",_ "Com14","Com15","Com16","Com17","Com18","Com19","Com20",_ "Com21","Com22","Com23","Com24","Com25","Com26","Com27" OnChange = Port_Combo1Change Style = csOwnerDrawFixed End Create Create Speed_Combo2 as QComboBox Parent = EDF_BT Top = 16 Left = 96 Width = 65 Height = 22 Text = "" Color = &HFFFFFF AddItems "1200",_ "2400",_ "4800",_ "9600",_ "19200",_ "38400",_ "57600",_ "115200" OnChange = Speed_Combo2Change Style = csOwnerDrawFixed Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 10 End Create Create Parity_Combo3 as QComboBox Parent = EDF_BT Top = 16 Left = 168 Width = 41 Height = 22 Text = "" Color = &HFFFFFF Style = csOwnerDrawFixed AddItems "N",_ "O",_ "E",_ "M',_ 'S" Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 10 OnChange = Parity_Combo3Change End Create Create Nb_Datas_Combo4 as QComboBox Parent = EDF_BT Top = 16 Left = 216 Width = 41 Height = 22 Text = "" Color = &HFFFFFF Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 10 Style = csOwnerDrawFixed AddItems ("7","8","9") OnChange = Nb_Datas_Combo4Change End Create Create Nb_Stop_Combo5 as QComboBox Parent = EDF_BT Top = 16 Left = 264 Width = 49 Height = 22 Text = "" Color = &HFFFFFF AddItems ("1","1.5","2") Style = csOwnerDrawFixed Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 10 OnChange = Nb_StopChange End Create Create Zone_Emission as QRichEdit Parent = EDF_BT Top = 150 Left = 8 Width = 296 Height = 25 Color = &HFFFFFF PlainText = True Align = alNone HideScrollBars = False ScrollBars = ssVertical Hint = "" ' OnChange = Zone_EmissionChange ShowHint = True Font.Name = "MS Sans Serif" Font.Color = 16711680 Font.Size = 8 End Create Create Label1 as QLabel Parent = EDF_BT Top = 8 Left = 336 Width = 76 Height = 13 Caption = "Time elapsed" Color = &HF0F0F0 Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 8 Font.AddStyles fsBold End Create Create Timer1 as QTimer Enabled = False Interval = 1000 End Create Create StatusBar1 as QStatusBar Parent = EDF_BT Top = 399 Left = 0 Width = 898 Height = 33 SimpleText = "Receive Status bar" SimplePanel = True SizeGrip = True End Create Create Zone_Reception as QRichEdit Parent = EDF_BT Top = 208 Left = 496 Width = 537 Height = 33 Color = -2147483624 ' OnChange = Zone_ReceptionChange PlainText = True ScrollBars = ssVertical HideScrollBars = False ReadOnly = False ShowHint = True Font.Name = "MS Sans Serif" Font.Color = 16711680 Font.Size = 8 End Create Create RX_Gauge1 as QGauge Parent = EDF_BT Top = 176 Left = 504 Width = 201 Height = 25 Color = &HF0F0F0 Max = 128 Position = 64 ForeColor = 16711680 End Create Create Raz_Zone_Emission as QButton Parent = EDF_BT Top = 120 Left = 8 Width = 129 Height = 25 Caption = "Raz buffer emission" OnClick = Raz_Zone_EmissionClick End Create Create Zone_Debug as QRichEdit Parent = EDF_BT Top = 200 Left = 8 Width = 473 Height = 41 Color = &HFFFFFF ScrollBars = ssVertical HideScrollBars = False PlainText = True End Create Create DateEnCours as QLabel Parent = EDF_BT Top = 8 Left = 512 Width = 23 Height = 13 Caption = "Date" Color = &HF0F0F0 End Create Create TimeEnCours as QLabel Parent = EDF_BT Top = 8 Left = 600 Width = 23 Height = 13 Caption = "Time" Color = &HF0F0F0 End Create Create Label7_wod as QLabel Parent = EDF_BT Top = 8 Left = 448 Width = 25 Height = 13 Caption = "WoD" Color = 16777215 AutoSize = False End Create Create Raz_Zone_Debug as QButton Parent = EDF_BT Top = 176 Left = 8 Width = 113 Height = 25 Caption = "Raz_Zone_Debug" OnClick = Raz_Zone_DebugClick End Create Create RAZ_Reception as QButton Parent = EDF_BT Top = 176 Left = 720 Width = 105 Height = 25 Caption = "RAZ_Reception" OnClick = RAZ_ReceptionClick End Create Create GroupBox1 as QGroupBox Parent = EDF_BT Top = 48 Left = 216 Width = 169 Height = 49 Caption = "Numero de compteur" Color = &HF0F0F0 End Create Create Num_Compteur as QLabel Parent = GroupBox1 Top = 14 Left = 10 Width = 134 Height = 24 Caption = "Num_Compteur" Color = &HF0F0F0 Font.Name = "MS Sans Serif" Font.Color = 0 Font.Size = 14 End Create Create GroupBox2 as QGroupBox Parent = EDF_BT Top = 48 Left = 392 Width = 145 Height = 49 Caption = "Valeur de base" Color = &HF0F0F0 End Create Create Origine_Compteur as QLabel Parent = GroupBox2 Top = 14 Left = 6 Width = 155 Height = 24 Caption = "Origine_Compteur" Color = &HF0F0F0 Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 14 End Create Create GroupBox3 as QGroupBox Parent = EDF_BT Top = 112 Left = 312 Width = 185 Height = 57 Caption = "Nb de W/H en cours" Color = 65280 ShowHint = False Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 10 Font.AddStyles fsBold End Create Create Wh_Now as QLabel Parent = GroupBox3 Top = 14 Left = 14 Width = 144 Height = 37 Caption = "00000000" Color = 65280 Font.Name = "Arial" Font.Color = 0 Font.Size = 24 Font.AddStyles fsBold LowerColor = 536870911 Cursor = -21 ShowHint = True End Create Create GroupBox4 as QGroupBox Parent = EDF_BT Top = 104 Left = 672 Width = 185 Height = 65 Caption = " (Kwh)" Color = 65535 ShowHint = False Font.Name = "MS Sans Serif" Font.Color = 0 Font.Size = 10 Font.AddStyles fsBold End Create Create Conso_KWH as QLabel Parent = GroupBox4 Top = 15 Left = 7 Width = 167 Height = 43 Caption = "Cons_KWH" Color = 65535 Font.Name = "Arial Narrow" Font.Color = 0 Font.Size = 28 Font.AddStyles fsBold Align = alNone ShowHint = True End Create Create GroupBox5 as QGroupBox Parent = EDF_BT Top = 32 Left = 744 Width = 73 Height = 65 Caption = "Amperes" Color = 16777215 End Create Create Amperes as QLabel Parent = GroupBox5 Top = 20 Left = 12 Width = 72 Height = 30 Caption = "A" Color = &HFFFFFF Font.Name = "NI7SEG" Font.Color = 16711680 Font.Size = 24 Font.AddStyles fsBold End Create Create GroupBox7 as QGroupBox Parent = EDF_BT Top = 104 Left = 512 Width = 137 Height = 65 Caption = "Temper.Ambiante Garage" Color = 8421504 End Create Create Tamb_G as QLabel Parent = GroupBox7 Top = 16 Left = 24 Width = 86 Height = 41 Caption = "19.99" Color = 8421504 Font.Name = "Arial" Font.Color = 65280 Font.Size = 26 Font.AddStyles fsBold Alignment = taRightJustify End Create Create Add_CR as QCheckBox Parent = EDF_BT Top = 120 Left = 144 Width = 73 Height = 25 Caption = "Add_CR" ' OnClick = Add_CRClick End Create Create Add_LF as QCheckBox Parent = EDF_BT Top = 120 Left = 216 Width = 65 Height = 25 Caption = "Add_LF" Caption = "Add_LF" ' OnClick = Add_LFClick End Create Create Visu_Trame as QCheckBox Parent = EDF_BT Top = 176 Left = 832 Width = 89 Height = 25 Caption = "Visu_Trame" End Create Create CoolBtn1 as QCoolBtn Parent = EDF_BT Top = 224 Left = 1144 Width = 17 Height = 1 Caption = "" End Create Create Simulation as QCheckBox Parent = EDF_BT Top = 176 Left = 928 Width = 73 Height = 25 Caption = "Simulation" End Create Create Label5 as QLabel Parent = EDF_BT Top = 378 Left = 690 Width = 168 Height = 29 Caption = "Sauve Fichier " Color = &HF0F0F0 Transparent = False Enabled = False Visible = False Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 18 Font.AddStyles fsBold End Create Create GroupBox6 as QGroupBox Parent = EDF_BT Top = 24 Left = 864 Width = 161 Height = 145 Caption = "EDF constante" Color = 16776960 End Create Create Label6 as QLabel Parent = GroupBox6 Top = 34 Left = 106 Width = 52 Height = 16 Caption = "€/ KWH" Color = 16776960 Font.Name = "MS Sans Serif" Font.Color = 0 Font.Size = 10 Font.AddStyles fsBold LowerColor = 16776960 End Create Create Dernier_Releve as QEdit Parent = GroupBox6 Top = 96 Left = 10 Width = 145 Height = 45 Text = "Dernier_Releve" Color = &HC0C0C0 End Create Create GroupBox8 as QGroupBox Parent = EDF_BT Top = 32 Left = 552 Width = 177 Height = 65 Caption = "Facture Euro" Color = 65535 Font.Name = "MS Sans Serif" Font.Color = 16711680 Font.Size = 10 Font.AddStyles fsBold End Create Create Conso_Euro as QLabel Parent = GroupBox8 Top = 16 Left = 10 Width = 155 Height = 36 Caption = "Conso_Euro" Color = 65535 Font.Name = "MS Sans Serif" Font.Color = 16711680 Font.Size = 23 Font.AddStyles fsBold End Create Create Label2 as QLabel Parent = GroupBox6 Top = 72 Left = 8 Width = 90 Height = 13 Caption = "Dernier relevé EDF" Color = &HFFFF00 End Create Create Edit1_Prix_KWH as QEdit Parent = GroupBox6 Top = 24 Left = 16 Width = 81 Height = 28 Text = "Edit1_Prix_KWH" Color = &HFFFFFF Font.Name = "MS Sans Serif" Font.Color = -2147483640 Font.Size = 12 Font.AddStyles fsBold End Create Create CheckPrix as QCheckBox Parent = GroupBox6 Top = 56 Left = 104 Width = 49 Height = 17 Caption = "Valid" End Create Create Numero_Jour as QLabel Parent = EDF_BT Top = 8 Left = 680 Width = 63 Height = 13 Caption = "Numero_Jour" Color = &HF0F0F0 End Create Sub DrawOrig Dim j As Integer Dim i As Integer 'draw original data set With Graph1 .Initialize 'Set defaults .ChartType = ctXY 'XY Scatter Chart .ChartStyle = csLines 'just Lines, use csBoth for lines and Points .MainTitle.Text = "EDF Info Data" .XTitle.Text = "Nb Trames EDF" .YTitle.Text = "Amperes" .ChartBorder=1 .AxisBorder=True .GridColor=&H00FF00 .PlotAreaColor=&HF0F0F0 .Cols = 1 'Number of series .Rows = n-1 .XAxis.color=.Colors(0) .Series(1).COLOR=.Colors(5) 'Number of data points per series REDIM Graph1.XYData(.Cols,.Rows,2) .DoLegend = false .Series(1).LineWidth = 3 .Series(1).LineStyle=lsSolid .Missing=0 For j = 0 To .Rows .XYData(1,j,1) =j .XYData(1,j,2) =0 next j .AxisBorder=TRUE .XAxis.AutoScale=False .YAxis.AutoScale=False .YAxis.Max = 40.0 .XAxis.Max = n ' 6000 pour ~2H00 .DrawChart (False) 'Draw it! ' End With END SUB Sub Initialise() OrigineCompteur=49165000 Origine_Compteur.Caption=str$(OrigineCompteur) NumCompteur$= "50222059498" Num_Compteur.Caption=NumCompteur$ NbWattActuel=0 TemperAmb1=0.0 KWh=0.0 ' ecart watth en kw ' Trame_EDF$="......................................................................................................." Trame_EDF$="" NbWattActuel=0 OldNbWatt=0 Once=0 Amps=0 Amps_Moyen=0 Temper_Moyen=0 Nb_Trame=0 Index_Chart=0 TemperAmb1=19.99 Conso_KWh.Caption="0000" Tamb_G.caption="19.99" WH_Now.caption="0000" for i=0 to 600 Table(i)=0 next i for Nb_Mn=0 to 1440 Amps_Store(Nb_Mn)=0 Temper_Store(Nb_Mn)=0 next Nb_Mn Nb_Mn=0 Graph1.ClearAll n=600 EDF_BT.Caption="EDF_BT Version : "+Version Drapeau_Save=0 Simulation.Checked=False Numero_jour.caption=0 HH = val(left$(Time$,2)) Mn = val(Mid$(Time$,4,2)) ss = val(right$(Time$,2)) Nb_Mn=HH*60+Mn Old_Nb_Mn=Nb_Mn Old_HH=HH ' init tables 'for j=0 to 7:read JourSem$(J):next j 'for j=0 to 12 'read Month$(j) 'Read month(j) ' next j With EDF_BT .Top = 5 .Left = 5 .Width =1045 .Height = 850 END with with Graph1 .Top =250 .Left =10 .Height=525 .Width=900 End with with Label5 .Top = 496 .Left = 680 .Width = 328 .Height = 117 .Caption = "Sauve Fichier Data " .Color = &HF0F0F0 .Transparent = False .Enabled = False .visible=False end with With Dernier_Releve .Top = 90 .Left = 10 .Width =145 .Height =60 .text = "Dernier releve EDF " .Enabled = True .visible=True .Font.Size = 22 .Font.AddStyles fsBold .font.Color = 12632256 .OnChange = Dernier_ReleveChange .Font.Name = "MS Sans Serif" .Font.Color = 16711680 .Font.AddStyles fsBold .AutoSize = False end with End Sub SUB TimerOver() dim Iz as integer 'Communication Jt = Jt + 1 Label1.Caption = "Time ealpsed = " +STR$(jt) if Simulation.checked=False then NBytes=INBUFFER() RX_Gauge1.Position= NBytes StatusBar1.simpletext = "Bytes in buffer: " & STR$(NBytes) else NBytes=104 if (jt>28) then jt=0 end if 'if NBytes>100 and NBytes < 110 then ' 1 seule trame dans le buffer ! ' en simule 92 cars mini if NBytes>LongMini and NBytes < 110 then ' 1 seule trame dans le buffer ! 'Lecture buffer COM if Simulation.checked=False then Read_COMx() else Amps= Index_Chart*0.05 + rnd(200)*0.01 Amperes.caption=format$("%2.1f",Amps) end if Index_Chart=Index_Chart+1 JourSem=Joursemaine() 'JourCalendaire() Numero_Jour.caption="Jc="+str$(Numjour) TimeEnCours.Caption=Time$ dow$=mid$(dd$,(JourSem*3)+1,3) DateEnCours.Caption=str$(dd)+"/"+str$(mm)+"/2018" Label7_wod.caption=Dow$ HH = val(left$(Time$,2)) Mn = val(Mid$(Time$,4,2)) ss = val(right$(Time$,2)) Nb_Mn=HH*60+Mn ZOne_Debug.text=str$(Nb_mn) +chr$(13) if (Nb_Mn=0) then Drapeau_Save=0 Temper_Moyen=Temper_Moyen+TemperAmb1 Amps_Moyen=Amps_Moyen+Amps Nb_Trame=Nb_Trame+1 if (Nb_Mn<> Old_Nb_Mn) then Old_Nb_Mn=Nb_Mn if (Nb_Trame>2) Then Amps_Store(Nb_Mn)=Amps_Moyen/Nb_Trame Temper_Store(Nb_Mn)= Temper_Moyen/Nb_Trame 'rajout temp moyenne horaire Temper_Heure=Temper_Heure+ Temper_Store(Nb_Mn) Nb_mes_Temp=Nb_mes_Temp+1 else Amps_Store(Nb_Mn)=0 Temper_Store(Nb_Mn)=0 end if Nb_Trame=0 Amps_Moyen=0 Temper_Moyen=0 end if ' memo KWH if (HH <> Old_HH) then Delta_KWH= (NbWattActuel-OldNbWatt)/1000 OldNbWatt= NbWattActuel KWH_Day_Store(OLD_HH)= Delta_KWH if (Nb_mes_temp>0) then Temper_Day(OLD_HH)= Temper_Heure/Nb_mes_Temp end if Old_HH=HH Temper_Heure=0 Nb_mes_Temp=0 end if ' sauvegarde vers 23H59:56 sec if (Nb_Mn>1438) and (ss>50) and (Drapeau_Save=0) then Timer1.enabled=False ' cas particulier de minuit ZOne_Debug.text="Sauve KWH" Delta_KWH= (NbWattActuel-OldNbWatt)/1000 OldNbWatt= NbWattActuel KWH_Day_Store(23)= Delta_KWH Save_EDFinfo_to_File Drapeau_Save=1 while val(right$(Time$,2))>50 'attend passage à 00 sec wend Old_HH=0 Nb_Mn=0 Timer1.enabled=True end if ZOne_Debug.text=ZOne_Debug.text+ str$(Amps_Moyen) +chr$(13) ' taille à etendre !! if (Index_Chart>599) then ' Index_Chart=599 Once=1 end if if (Once=1) then with Graph1 Index_Chart=599 .Series(1).COLOR=.Colors(5) .Series(2).COLOR=.Colors(7) for i=1 to 599 Table(i-1)=Table(i) .XYData(2,i-1,2)= Table_T(i-1) .XYData(1,i-1,2)= Table(i-1) next i Table(599)=Amps Table_T(599)=TemperAmb1 .XYData(1,599,2)= Table(599) .XYData(2,599,2)= Table_T(599) .DrawChart (false) end with else with Graph1 .Series(1).COLOR=.Colors(5) .Series(2).COLOR=.Colors(7) Table(Index_Chart)=Amps Table_T(Index_Chart)=TemperAmb1 .XYData(1,Index_Chart,2)= Table(Index_Chart) .XYData(2,Index_Chart,2)= Table_T(Index_Chart) .DrawChart (false) end with end if else if (jt>30) then Zone_Reception.AddString ("TimeOut reception") jt=0 CLEARBUFFER end if end if if (CheckPrix.checked=True) then Prix_Kwh=val(Edit1_Prix_Kwh) CheckPrix.checked=False end if END SUB SUB Read_COMx() Dim L0 as integer Dim j as integer DIm i as integer Dim Lg as integer DIm Ax$ as string dim mn$ as string jt=0 Trame_EDF$=ReadString() Lg=len(Trame_EDF$) if (Visu_Trame.Checked = True) then Zone_Reception.AddString ( Trame_EDF$) End if ' traitement des datas reçues ' if((left$(Trame_EDF$,7)="*C05022") and (right$(Trame_EDF$,2)="0*") and (Lg>100) and (lg<110)) then if((left$(Trame_EDF$,7)="*C05022") and (right$(Trame_EDF$,2)="0*") and (Lg>LongMini) and (lg<110)) then i=0 j=0 while (Mid$(Trame_EDF$,i,1)<>";" ) i=i+1 if (i> L0) then exit while Wend NumCompteur$= Mid$(Trame_EDF$,j+2,i-3) Num_Compteur.caption=NumCompteur$ ' Nb de watts en cours i=i+2 j=i while (Mid$(Trame_EDF$,i,1)<>";" ) i=i+1 if (i> L0) then exit while Wend Ax$=Mid$(Trame_EDF$,j+2,i-4) NbWattActuel= val(Ax$) Ax$=Str$(NbWattActuel ) Wh_Now.caption=Ax$ Kwh=(NbWattActuel-Val(Dernier_Releve.text))/1000 ' en KWH if (Kwh<=0) then Conso_KWh.caption= "Erreur" else Conso_KWh.caption=format$("%8.3f",kwh) end if Conso_Euro.Caption= format$("%3.2f €",(Kwh*Prix_Kwh) ) ' recherche Amperes i=i+1 j=i while (Mid$(Trame_EDF$,i,1)<>"A" ) i=i+1 if (i> L0) then exit while Wend ' pass over "A" i=i+1 j=i while (Mid$(Trame_EDF$,i,1)<>";" ) i=i+1 if (i> L0) then exit while Wend Ax$= Mid$(Trame_EDF$,j,i-1) Amps=val(Ax$) Amperes.caption=str$(Amps) ' recherche valeur Temper i=i+1 j=i while (Mid$(Trame_EDF$,i,1)<>"T" ) i=i+1 if (i> L0) then exit while Wend 'pass Over "T" i=i+1 j=i while (Mid$(Trame_EDF$,i,1)<>";" ) i=i+1 if (i> L0) then exit while Wend Ax$= Mid$(Trame_EDF$,j,i-1) TemperAmb1=val(Ax$) Tamb_G.caption=format$("%4.2f",TemperAmb1) else Ax$="Erreur sur trame "+chr$(13) Zone_Debug.text=Ax$ CLEARBUFFER end if ' Trame_EDF$="" END SUB EDF_BT.ShowModal Sub EDF_BTShow(Sender as QForm) dim A1$ as string BUFFERSIZE(128) ' > à 2x la longueur trame de 103 cars CLEARBUFFER Initialise() Trame_EDF$="" 'n=maxV n=600 ' dimanche=Day week #0 dd$= "DimLunMarMerJeuVenSam" Nombre = 0 Chemin = left$(command$(0), rinstr(command$(0), "\")) IF FILEEXISTS(Chemin + "$$$$$.$$$" ) = 0 and Deja = 0 THEN Fichier.open(Chemin + "$$$$$.$$$" ,fmcreate) Fichier.close Deja = 1 elseif Deja = 0 then messagebox("Le programme est déja chargé ou alors il vous faut _ détruire le fichier $$$$$.$$$ qui se trouve dans le _ meme répertoire.","Achtung!",0) Application.terminate end end if IF FILEEXISTS(Chemin + Ini ) <> 0 THEN Fichier.open(Chemin + Ini, fmopenread) A1$= "Ouverture fichier "+chr$(13)+Chemin + Ini messagebox(A1$,"Init COM",0) DO Nombre = Nombre + 1 Variable$ = trim((fichier.readline())) IF Nombre = 1 AND variable$ <> "" THEN IF VAL(variable$) < 40000 THEN EDF_BT.Top = VAL(variable$) END IF END IF IF Nombre = 2 AND variable$ <> "" THEN IF VAL(variable$) < 40000 THEN EDF_BT.left = VAL(variable$) END IF END IF IF Nombre = 3 AND variable$ <> "" THEN Speed_combo2.ItemIndex = val(Variable$) baud = Speed_combo2.Text end if IF Nombre = 4 AND variable$ <> "" THEN Parity_Combo3.ItemIndex = val(Variable$) Parite = Parity_Combo3.Text end if IF Nombre = 5 AND variable$ <> "" THEN NB_Datas_Combo4.ItemIndex = val(Variable$) Nb_datas = Nb_Datas_Combo4.Text end if IF Nombre = 6 AND variable$ <> "" THEN Nb_Stop_combo5.ItemIndex = val(Variable$) Nb_Stop = Nb_Stop_Combo5.Text end if if Nombre = 7 AND variable$ <> "" THEN Port_Combo1.ItemIndex = val(Variable$) Com = Port_Combo1.Text end if if Nombre = 8 AND variable$ <> "" THEN Dernier_Releve.text=Variable$ Last_Releve=val(Dernier_Releve.text) end if if Nombre = 9 AND variable$ <> "" THEN Edit1_Prix_KWH.Text=Variable$ Prix_KWH=val(Variable$) end if LOOP UNTIL Fichier.Size = Fichier.Position if Com <> "" and Baud <> "" And Parite <> "" and Nb_Datas <> "" and Nb_Stop <> "" then ' tous les parametres setup COM sont present ' donc activer le port COM Activer_Port_COM() Send_Button.enabled=True MAJ_RTC.enabled=True Zone_Emission.text="Pret à recevoir des données.." if Simulation.checked=False then Timer1.interval=TIMEOUT_Trame else Timer1.interval=50 end if Timer1.Enabled= True Timer1.OnTimer= TimerOver HH = val(left$(Time$,2)) Mn = val(Mid$(Time$,4,2)) ss = val(right$(Time$,2)) Nb_Mn=HH*60+Mn Old_Nb_Mn=Nb_Mn end if Fichier.close Nombre = 0 END IF ' file exist DrawOrig END sub Sub Save_EDFinfo_to_File dim ia as integer dim C$ as string dim TT as long dim FileAnnuel$ as string dim FileAmps$ as string dim FileKwh$ as string dim Datum$ as string dim FileName$ as string Label5.Enabled = True Label5.Visible= True FileAnnuel$="EDFinfo_2018.txt" FileAmps$="EdfInfo_Amps_Temp_" Datum$=str$(mm) if dd<10 then Datum$=Datum$+"0" Datum$=Datum$+str$(dd)+".txt" FileAmps$=FileAmps$+ Datum$ IF FILEEXISTS(Chemin + FileAmps$) = 0 THEN Fichier.open(Chemin +FileAmps$,fmcreate) Fichier.close end if Fichier.open(Chemin + FileAmps$,fmopenwrite) C$= Date$+";"+Time$+";" Fichier.writeline(C$) for ia=0 to 1439 C$= format$("%3.2f",Amps_Store(ia))+";" + format$("%3.2f",Temper_Store(ia)) Fichier.WriteLine C$ Amps_Store(ia)=0 ' on le RAZ au fur et à mesure Temper_Store(ia)=0 next ia Fichier.close FileKwh$="EdfInfo_KWH_TemP_"+ Datum$ IF FILEEXISTS(Chemin + FileKwh$) = 0 THEN Fichier.open(Chemin +FileKwh$,fmcreate) Fichier.close end if Fichier.open(Chemin + FileKwh$,fmopenwrite) C$= Date$+";"+Time$+";" Fichier.writeline(C$) for ia=0 to 23 C$= format$("%6.3f", KWH_Day_Store(ia)) + ";"+format$("%3.2f",Temper_Day(ia)) Fichier.WriteLine C$ KWH_Day_Store(ia)=0 ' on le RAZ au fur et à mesure Temper_Day(ia)=0 next ia Fichier.close Label5.Visible= False Label5.Enabled = False end sub Sub EDF_BTClose(Action AS INTEGER) IF FILEEXISTS(Chemin + Ini) = 0 THEN Fichier.open(Chemin + Ini,fmcreate) Fichier.close ELSE KILL Chemin + Ini Fichier.open(Chemin + ini,fmcreate) Fichier.close END IF if Fileexists(Chemin + "$$$$$.$$$") <> 0 then kill Chemin + "$$$$$.$$$" end if Fichier.open(Chemin + Ini,fmopenwrite) Fichier.writeline(STR$(EDF_BT.top)) Fichier.writeline(STR$(EDF_BT.left)) Fichier.WriteLine str$(Speed_Combo2.ItemIndex) Fichier.WriteLine str$(Parity_Combo3.ItemIndex) Fichier.WriteLine str$(Nb_Datas_Combo4.ItemIndex) Fichier.WriteLine str$(Nb_Stop_Combo5.ItemIndex) Fichier.WriteLine str$(Port_Combo1.ItemIndex) ' Dernier releve de facturation EDF Fichier.WriteLine Dernier_Releve.text Fichier.WriteLine format$("%4.3f",Prix_Kwh) Fichier.close closecom Application.terminate end sub Sub Message(Situation as single) select case situation case 1 : messagebox( "Probleme sur votre port " + Com,"COM Setup",0) case 2 : messagebox("Selectionner un port Com1, Com2, Com3, ..COM20","COM Setup",0) case 3 : messagebox("Configuration incomplete, PROBLEMO! ","Aie ! Aie",0) case 4 : messagebox("Bye Bye ..","Info",0) case 5: messagebox("Chargement de HELP"+chr$(13)+"..à suivre","Information",0) case 10 : messagebox("Non implanté","info",0) case else end select end sub sub Activer_Port_COM() CLEARBUFFER CLOSECOM String_Comm = Com & "," & Baud & "," & Parite & "," & Nb_Datas & "," & Nb_Stop L2=len(String_Comm ) C$="Version "+ Version +chr$(13)+"chaine setup : "+chr$(13)+ string_Comm+chr$(13)+" Len=" + STR$(L2)_ +chr$(13)+Dernier_Releve.text +chr$(13)+ Edit1_Prix_Kwh.text messagebox(C$,"Info. COM",0) infoCom = OPENCOM(String_Comm) If infoCom = 0 Then message 1 Com = "" EDF_BT.caption = "Port de comm. non reconnu" Port_Combo1.ItemIndex = -1 else Groupe1.caption = "Port ouvert : "+ com + ", " + baud +", "+ Parite + ", "+ Nb_Datas + ", " + Nb_Stop CLEARBUFFER TXD 0 RTS 0 DTR 0 REALTIME end if End sub Sub Send_ButtonClick(Sender as QCoolBtn) ' if Com = "" or Baud = "" or Parite = "" or Nb_Datas = "" or Nb_Stop = "" then message 3 exit sub end if A$=Zone_Emission.text SENDSTRING (A$) if (Add_CR.checked=true) then SENDBYTE (13) end if if (Add_LF.checked=TRUE) then SENDBYTE (10) end if End Sub Sub Port_Combo1Change(Sender as QComboBox) Com = trim(Port_Combo1.Text) Activer_Port_COM End Sub Sub Speed_Combo2Change(Sender as QComboBox) Baud = trim(Speed_Combo2.Text) Activer_Port_COM End Sub Sub Parity_Combo3Change(Sender as QComboBox) Parite = trim(Parity_combo3.Text) Activer_Port_COM End Sub Sub Nb_Datas_Combo4Change(Sender as QComboBox) Nb_Datas = trim(Nb_Datas_Combo4.Text) Activer_Port_COM End Sub Sub Nb_StopChange(Sender as QComboBox) Nb_Stop = trim(Nb_Stop_combo5.Text) Activer_Port_COM End Sub Function Trim(Datum As String) As String if Datum = "" then exit function Trim = LTrim$(RTrim$(Datum)) End Function Sub Help_buttonClick(Sender as QCoolBtn) Message (5) End Sub Sub MAJ_RTCClick(Sender as QCoolBtn) dim Ad$ as string Ad$=" " if L2>0 then 'A$="#U;10;11;18;20;12;06;&" Ad$="#U:"+mid$( Date$,4,2) Ad$=Ad$+";" Ad$=Ad$+ left$(Date$,2) Ad$=Ad$+";" Ad$=Ad$+right$( Date$,2) Ad$=Ad$+";" Ad$=Ad$+left$( Time$,2) Ad$=Ad$+";" Ad$=Ad$+mid$(Time$,4,2) Zone_Emission.Addstring Ad$ 'copy dans zone debugging pour checking JourSem=JourSemaine() Ad$=Ad$+";0"+Str$(JourSem)+";&" SENDSTRING Ad$ SENDBYTE 13 SENDBYTE 10 Zone_Emission.text=Ad$ k=len(Ad$) Ad$=Ad$+chr$(13)+"L="+str$(k) ' Zone_Debug.Addstring= Ad$ dow$=mid$(dd$,(JourSem*3)+1,3) Label7_wod.caption=Dow$ end if End Sub Function JourSemaine() AS INTEGER dim c as integer dim n$ as string n$=date$ result=-1 mm = val(left$(n$,2)) dd = val(mid$(n$,4,2)) yy = val(right$(n$,4)) Zone_Debug.text=str$(mm)+" "+str$(dd)+" "+str$(yy) +chr$(13) if ( (mm>0) AND (mm<13) AND (dd>0) and (dd<32) and (yy>2000) and (yy<2100)) then c=0 ' c=c+(yy-1900)*365 + int((yy-1900)/4) Numjour=0 for i=1 to mm-1 select case i case 1,3,5,7,8,10 c=c+31 case 2 c=c+28 if ((yy-1900) mod 4 = 0) then c=c+1 case 4,6,9,11 c=c+30 end select next c=c+dd NumJour=c c=c+(yy-1900)*365 + int((yy-1900)/4) result = (c mod 7) ' Zone_Debug.text=chr$(13)+chr$(10)+"result="+str$(result) +chr$(13) else result=-1 end if END FUNCTION SUB JourCalendaire Dim j as integer if yy mod 4=0 then month(2)=29 else month(2)=28 end if j=0 Numjour=0 For j=1 to mm-1 Numjour=Numjour+month(j) Next j Numjour=Numjour+dd Numero_Jour.caption="Jc="+str$(Numjour) end Sub Sub Origine_CompteurClick(Sender as QLabel) OrigineCompteur=Origine_Compteur.caption End Sub Sub Raz_Zone_DebugClick(Sender as QButton) Zone_Debug.text="" End Sub Sub RAZ_ReceptionClick(Sender as QButton) Zone_Reception.text="" End Sub Sub Raz_Zone_EmissionClick(Sender as QButton ) Zone_Emission.text="" End Sub Sub SortieClick(Sender as QButton) Save_EDFinfo_to_File Message (4) EDF_BTClose(0) end End Sub Sub CoolBtn2Click(Sender as QCoolBtn) DrawOrig End Sub Sub Dernier_ReleveChange(Sender as QEdit) 'if(len(Dernier_Releve.text)<10) then msox(" PB","erreru",0) End Sub Sub Edit1_Prix_KWHChange(Sender as QEdit) if len(Edit1_Prix_KWH)>3 then Prix_Kwh=val(Edit1_Prix_Kwh) end if End Sub