From c07822fb2f758ebac7bf062fe6a759f7b155a84f Mon Sep 17 00:00:00 2001
From: GianluigiPappa90 <136473485+GianluigiPappa90@users.noreply.github.com>
Date: Tue, 13 Jun 2023 15:52:39 +0200
Subject: [PATCH 1/8] Add or update the Azure App Service build and deployment
workflow config
---
.github/workflows/master_phpserial.yml | 60 ++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
create mode 100644 .github/workflows/master_phpserial.yml
diff --git a/.github/workflows/master_phpserial.yml b/.github/workflows/master_phpserial.yml
new file mode 100644
index 000000000..12882e52f
--- /dev/null
+++ b/.github/workflows/master_phpserial.yml
@@ -0,0 +1,60 @@
+# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
+# More GitHub Actions for Azure: https://github.com/Azure/actions
+
+name: Build and deploy PHP app to Azure Web App - phpserial
+
+on:
+ push:
+ branches:
+ - master
+ workflow_dispatch:
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: '8.2'
+
+ - name: Check if composer.json exists
+ id: check_files
+ uses: andstor/file-existence-action@v1
+ with:
+ files: 'composer.json'
+
+ - name: Run composer install if composer.json exists
+ if: steps.check_files.outputs.files_exists == 'true'
+ run: composer validate --no-check-publish && composer install --prefer-dist --no-progress
+
+ - name: Upload artifact for deployment job
+ uses: actions/upload-artifact@v2
+ with:
+ name: php-app
+ path: .
+
+ deploy:
+ runs-on: ubuntu-latest
+ needs: build
+ environment:
+ name: 'Production'
+ url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
+
+ steps:
+ - name: Download artifact from build job
+ uses: actions/download-artifact@v2
+ with:
+ name: php-app
+
+ - name: 'Deploy to Azure Web App'
+ uses: azure/webapps-deploy@v2
+ id: deploy-to-webapp
+ with:
+ app-name: 'phpserial'
+ slot-name: 'Production'
+ publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_3802BA5F7DB1469F8E6A590AF17D87FA }}
+ package: .
From aedda3f433724532a19ccda5aff7cd12acb5b194 Mon Sep 17 00:00:00 2001
From: GianluigiPappa90 <136473485+GianluigiPappa90@users.noreply.github.com>
Date: Tue, 13 Jun 2023 15:55:11 +0200
Subject: [PATCH 2/8] Primo push
---
index.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/index.php b/index.php
index 82966e27a..466de2f49 100644
--- a/index.php
+++ b/index.php
@@ -1,3 +1,3 @@
Date: Tue, 13 Jun 2023 17:28:14 +0200
Subject: [PATCH 3/8] repo 2
---
index.html | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
create mode 100644 index.html
diff --git a/index.html b/index.html
new file mode 100644
index 000000000..41b735e11
--- /dev/null
+++ b/index.html
@@ -0,0 +1,93 @@
+
+
+
+Page Title
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
From b7a07ebd0b9e76aa77a6c6b5b5ce7d2e637659f2 Mon Sep 17 00:00:00 2001
From: GianluigiPappa90 <136473485+GianluigiPappa90@users.noreply.github.com>
Date: Tue, 13 Jun 2023 17:30:29 +0200
Subject: [PATCH 4/8] l
---
index.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/index.html b/index.html
index 41b735e11..80de6bc49 100644
--- a/index.html
+++ b/index.html
@@ -15,6 +15,7 @@
writeSerialData(port, txt)
}
+
// Richiedi l'accesso alla porta seriale
async function requestSerialPort() {
From 77808d5c965c68a6c8d63b39b455c62cc74e9a8e Mon Sep 17 00:00:00 2001
From: Gluigi75
Date: Tue, 18 Jun 2024 13:14:06 +0200
Subject: [PATCH 5/8] fix log e file js
---
index.php | 155 ++++++++++++++++++++++++++++++++++++++++++++++++-
jsSerialApi.js | 153 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 307 insertions(+), 1 deletion(-)
create mode 100644 jsSerialApi.js
diff --git a/index.php b/index.php
index 466de2f49..b1ffcccc0 100644
--- a/index.php
+++ b/index.php
@@ -1,3 +1,156 @@
Connect";
+ //echo ""
+ echo " ";
+
+
+ $tipoMsg = "113";
+
+ $tmp = "$tipoMsg~0008";
+/*
+ echo "\n";
+
+ echo "\n";
+
+}
+
+
+function hexToStr($hex){
+ $string='';
+ for ($i=0; $i < strlen($hex)-1; $i+=2){
+ $string .= chr(hexdec($hex[$i].$hex[$i+1]));
+ }
+ return $string;
+}
+
+
+if($_POST){
+
+
+ foreach ($_POST as $key => $value){
+ //echo "$key => $value";
+
+ $sel["$key"] = urldecode($value);
+ }
+
+
+ // $codeid = isset($sel['codeid'])?$sel['codeid']:null;
+ // $com = isset($sel['com'])?$sel['com']:null;
+ // $tipoMsg = isset($sel['tipoMsg'])?$sel['tipoMsg']:null;
+ // $risposta = isset($sel['risposta'])?$sel['risposta']:null;
+ $rispostaCom = isset($sel['rispostaCom'])?$sel['rispostaCom']:null;
+ //$richiesta = isset($sel['richiesta'])?$sel['richiesta']:null;
+ $pattern = '/^[a-fA-F0-9]{16,16}$/';
+
+ // $_SESSION['AWP']['id_ente_old']=isset($sel['idEnte'])?$sel['idEnte']:$_SESSION['AWP']['id_ente_old'];
+ // $_SESSION['AWP']['id_ver']=isset($sel['idVerifica'])?$sel['idVerifica']:$_SESSION['AWP']['id_ver'];
+
+ if($rispostaCom){
+
+ if($rispostaCom == 'prova' || $rispostaCom == null){
+
+ $rc="problemi con activex";
+ $fase = 4;
+ //$rc= getValue('help.txt',$fase);
+ }else{
+ //exit;
+ //$tmp1=explode('#',$richiesta);
+
+
+ $rispostaCom=hexToStr($rispostaCom);
+
+ $itemRis= explode('~',$rispostaCom);
+
+ // $data['CNTTOTIN'] = intval($itemRis[5]);
+ // $data['CNTTOTOT'] = intval($itemRis[6]);
+ // $data['CNTCL'] = intval($itemRis[7]);
+ // $data['CNTOT'] = intval($itemRis[9]);
+ // $data['CNTNP'] = intval($itemRis[10]);
+ // $data['CNTIN'] = intval($itemRis[8]);
+
+ // $message = 'CNTTOTIN:'. $data['CNTTOTIN'] .'
+ // CNTTOTOT:'. $data['CNTTOTOT'].'
+ // CNTCL:'. $data['CNTCL'] .'
+ // CNTOT:'. $data['CNTOT'] .'
+ // CNTNP:'. $data['CNTNP'] .'
+ // CNTIN:'. $data['CNTIN'] .'
';
+
+ //echo $message;
+
+
+ $response = "########################################
+ Id_messaggio: " . $itemRis[0] . "
+ L_messaggio: " . $itemRis[1] . "
+ DATA_Risposta: " . $itemRis[2] . "
+ CODEID: " . $itemRis[3] . "
+ ESITO: " . $itemRis[4] . "
+ Valore contatore CNTTOTIN: " . $itemRis[5] . "
+ Valore contatore CNTTOTOT: " . $itemRis[6] . "
+ Valore contatore CNTCL: " . $itemRis[7] . "
+ Valore contatore CNTIN: " . $itemRis[8] . "
+ Valore contatore CNTOT: " . $itemRis[9] . "
+ Valore contatore CNTNP: " . $itemRis[10] . "
+ ORA_Risposta: " . $itemRis[11] . "
+ Codice_autenticazione: " . $itemRis[12] . "
+ Esito_comunicazione: " . $itemRis[13] . "
+ ########################################
";
+
+ echo $response;
+
+ echo "\n";
+
+ //echo $rispostaCom;
+ //die();
+ }
+ }
+}
+
+
+
+?>
+
+
+
+
+Page Title
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jsSerialApi.js b/jsSerialApi.js
new file mode 100644
index 000000000..10d7f37b3
--- /dev/null
+++ b/jsSerialApi.js
@@ -0,0 +1,153 @@
+let port, ports, textEncoder, writer, writableStreamClosed = -1;
+
+function translateConvertedChar2ClearChar(inputString) {
+ var campoOut = "";
+ var byteOut = "";
+ var arr = new Array();
+ var campoWorking = inputString;
+
+ if (inputString == null || inputString == "") {
+ return campoOut;
+ }
+
+ for (i = 0; i < inputString.length; i++) {
+ codice = inputString.charCodeAt(i);
+ byteOut = d2h(codice);
+ byteOut = byteOut.toUpperCase();
+
+ if (byteOut == 1 || byteOut == 2 || byteOut == 3 || byteOut == 4 || byteOut == 5 || byteOut == 6 || byteOut == 7 || byteOut == 8 || byteOut == 9 || byteOut == 'A' || byteOut == 'B' || byteOut == 'C' || byteOut == 'D' || byteOut == 'E' || byteOut == 'F') {
+
+
+ byteOut = '0' + byteOut;
+
+ }
+ if (byteOut == 100) {
+ byteOut = '00';
+ }
+
+ campoOut = campoOut + byteOut;
+
+ arraylen = arr.push(byteOut);
+ }
+ return campoOut;
+}
+
+function sendData(){
+ let txt = document.getElementById("messaggio").value;
+ console.log("Messaggio: " + txt);
+ writeSerialData(txt)
+}
+
+
+navigator.serial.addEventListener('connect', e => {
+ alert("connected");
+});
+
+ // Richiedi l'accesso alla porta seriale
+async function requestSerialPort() {
+ if ("serial" in navigator) {
+ console.log("Web Serial API is supported.");
+ try {
+ port = await navigator.serial.requestPort();
+ await port.open({ baudRate: 19200 }); // Configura la velocità di baud rate appropriata
+ let settings = {};
+
+ if (localStorage.dtrOn == "true") settings.dataTerminalReady = true;
+ if (localStorage.rtsOn == "true") settings.requestToSend = true;
+ if (Object.keys(settings).length > 0) await port.setSignals(settings);
+
+ textEncoder = new TextEncoderStream();
+ writableStreamClosed = textEncoder.readable.pipeTo(port.writable);
+ writer = textEncoder.writable.getWriter();
+
+ return port;
+
+ } catch (error) {
+ console.error("Errore durante la richiesta della porta seriale:", error);
+ }
+ } else {
+ console.error("Web Serial API not supported.");
+ }
+}
+
+// Leggi dati dalla porta seriale
+async function readSerialData(port) {
+ const reader = port.readable.getReader();
+ let app = '';
+ let ricev = '';
+ while (true) {
+ try {
+ const { value, done } = await reader.read();
+ if (done) break;
+ console.log("");
+ let arr = value;
+
+ for (x = 0; x < arr.length; x++) {
+ if (arr[x] == 0) {
+ arr[x] = 256;
+ }
+ //conversione dei singoli byte da charcode a carattere
+ ricev = String.fromCharCode(arr[x]);
+ app = app + ricev;
+ }
+
+ //console.log("Ricevuto:" + app);
+
+
+ let translate = translateConvertedChar2ClearChar(app);
+ //console.log("translate: " + translate)
+ document.getElementById("rispostaCom").value=translate;
+ document.getElementById('form1').submit();
+ //------------------------------------------
+
+ } catch (error) {
+ console.error("Errore durante la lettura dati seriali:", error);
+ break;
+ }
+ }
+
+ reader.releaseLock();
+}
+
+// Scrivi dati sulla porta seriale
+async function writeSerialData(data) {
+ try {
+ await writer.write(data + "\n");
+ console.log("Dati seriali inviati con successo.");
+ } catch (error) {
+ console.error("Errore durante l'invio dati seriali:", error);
+ }
+}
+
+function stopSerialCommunication(){
+ writer.releaseLock();
+}
+
+// Esempio di utilizzo
+async function startSerialCommunication() {
+ port = await requestSerialPort();
+
+ if (port) {
+ console.log("Porta selezionata")
+ await readSerialData(port);
+ conaole.log("Lettura su porta selezionata!");
+ await writeSerialData(port, "Dati da inviare sulla porta seriale");
+ conaole.log("Scrittura su porta selezionata!");
+ }
+ else {
+ console.log("Porta non trovata!")
+ }
+}
+
+function h2d(h) { return parseInt(h, 16); }
+
+function d2h(d) { return d.toString(16); }
+
+const connBtn = document.getElementById('connectBtn');
+connBtn.addEventListener('click', () => {
+ connBtn.disabled = true;
+ const sendBtn = document.getElementById('sendBtn');
+ sendBtn.disabled = false;
+});
+
+
From addde27b2aaa119f8eaeb9340a92790eca46155b Mon Sep 17 00:00:00 2001
From: Gluigi75
Date: Fri, 13 Sep 2024 12:30:38 +0200
Subject: [PATCH 6/8] Update jsSerialApi.js - add log
---
jsSerialApi.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/jsSerialApi.js b/jsSerialApi.js
index 10d7f37b3..94d8208e0 100644
--- a/jsSerialApi.js
+++ b/jsSerialApi.js
@@ -78,6 +78,7 @@ async function readSerialData(port) {
while (true) {
try {
const { value, done } = await reader.read();
+ console.log("Conferma lettura da porta: "+ done);
if (done) break;
console.log("");
let arr = value;
@@ -91,11 +92,11 @@ async function readSerialData(port) {
app = app + ricev;
}
- //console.log("Ricevuto:" + app);
+ console.log("Ricevuto:" + app);
let translate = translateConvertedChar2ClearChar(app);
- //console.log("translate: " + translate)
+ console.log("translate: " + translate)
document.getElementById("rispostaCom").value=translate;
document.getElementById('form1').submit();
//------------------------------------------
From 0d63e82899e21612d30b44c617489617baf18840 Mon Sep 17 00:00:00 2001
From: Gluigi75
Date: Fri, 13 Sep 2024 12:37:55 +0200
Subject: [PATCH 7/8] Update index.html - add log script
---
index.html | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/index.html b/index.html
index 80de6bc49..4ee102a80 100644
--- a/index.html
+++ b/index.html
@@ -45,6 +45,7 @@
while (true) {
try {
const { value, done } = await reader.read();
+ console.log("lettura porta:" + done);
if (done) break;
// Elabora i dati letti
console.log("Dati seriali ricevuti:", new TextDecoder().decode(value));
@@ -91,4 +92,4 @@