Compare commits
No commits in common. "e448f9a7142961b8d718077aa2c59c73e59edd4d" and "2af7800095ce0ea1172fd84e2bfaea8d03ddca0b" have entirely different histories.
e448f9a714
...
2af7800095
145
4N.html
145
4N.html
@ -1,145 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Qlogic Device User</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<div id="messagesList">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div>BCR Data:</div>
|
|
||||||
<div>
|
|
||||||
<textarea style="background-color: white" disabled=disabled id="BC-data" rows="5" cols="85"></textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div> </div>
|
|
||||||
<div>
|
|
||||||
<div>OCR Data:</div>
|
|
||||||
<div>
|
|
||||||
<textarea style="background-color: white" disabled=disabled id="OC-data" rows="3" cols="85"></textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div> </div>
|
|
||||||
<div>
|
|
||||||
<div>Boarding Pass Data:</div>
|
|
||||||
<div>
|
|
||||||
<textarea id="BP-data" rows="14" cols="85"></textarea>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<input id="BP-send" type="button" value="Send" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div> </div>
|
|
||||||
<div>
|
|
||||||
<div>Bag Tag Data:</div>
|
|
||||||
<div>
|
|
||||||
<textarea id="BT-data" rows="12" cols="85"></textarea>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<input id="BT-send" type="button" value="Send" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--Script references. -->
|
|
||||||
<script src="Scripts/jquery-3.7.1.min.js"></script>
|
|
||||||
|
|
||||||
<!-- Library required for SignalR Framework client -->
|
|
||||||
<script src="Scripts/jquery.signalR-2.4.3.min.js"></script>
|
|
||||||
|
|
||||||
<!-- Library required for SignalR Core client -->
|
|
||||||
<script src="Scripts/signalr.min.js"></script>
|
|
||||||
|
|
||||||
<!-- Wrapper that automatically implements the SignalR client that is compatible with the server -->
|
|
||||||
<script src="Scripts/qlogic-signal.js"></script>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
//
|
|
||||||
// QSS API callback class used to handle connection events (not required)
|
|
||||||
//
|
|
||||||
|
|
||||||
class QssApiCallback {
|
|
||||||
framework_starting() {
|
|
||||||
console.log('QSS Framework API: starting');
|
|
||||||
}
|
|
||||||
framework_received(data) {
|
|
||||||
console.log('QSS Framework API: received.');
|
|
||||||
}
|
|
||||||
framework_connectionSlow() {
|
|
||||||
console.warn('QSS Framework API: connectionSlow');
|
|
||||||
}
|
|
||||||
framework_reconnecting() {
|
|
||||||
console.warn('QSS Framework API: reconnecting');
|
|
||||||
}
|
|
||||||
framework_reconnected() {
|
|
||||||
console.log('QSS Framework API: reconnected');
|
|
||||||
}
|
|
||||||
framework_stateChanged(change) {
|
|
||||||
let oldStateStr = SIGNALR_CONNECTION_STATE_LABEL[change.oldState];
|
|
||||||
let newStateStr = SIGNALR_CONNECTION_STATE_LABEL[change.newState];
|
|
||||||
console.log('QSS Framework API: stateChanged - oldState:'
|
|
||||||
+ oldStateStr + '; newState:' + newStateStr);
|
|
||||||
}
|
|
||||||
framework_disconnected() {
|
|
||||||
console.warn('QSS Framework API: disconnected');
|
|
||||||
}
|
|
||||||
|
|
||||||
core_onreconnecting(error) {
|
|
||||||
if (error) {
|
|
||||||
console.error('QSS Core API: onreconnecting - Reconnecting after error:',
|
|
||||||
error);
|
|
||||||
} else {
|
|
||||||
console.log('QSS Core API: onreconnecting - Reconnecting');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
core_onreconnected(connectionId) {
|
|
||||||
console.log('QSS Core API: onreconnected - Connection ID: ' + connectionId);
|
|
||||||
}
|
|
||||||
core_onclose(error) {
|
|
||||||
if (error) {
|
|
||||||
console.error('QSS Core API: onclose - Closed due to an error:', error);
|
|
||||||
} else {
|
|
||||||
console.log('QSS Core API: onclose - Closed gracefully.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the client wrapper so that it can be used to make server-side calls and register
|
|
||||||
// client-side listeners.
|
|
||||||
$(document).ready(async function () {
|
|
||||||
|
|
||||||
// QSS API: set up API wrapper and connect
|
|
||||||
const qssApiCallback = new QssApiCallback();
|
|
||||||
await startSignalR(qssApiCallback);
|
|
||||||
|
|
||||||
// QSS API: server-side calls
|
|
||||||
$('#BP-send').on('click', function (event) {
|
|
||||||
const data = $('#BP-data').val();
|
|
||||||
console.info(data);
|
|
||||||
QSS_API_WRAPPER.invokeServerMethod('SendPrinterData', 'BP', data);
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#BT-send').on('click', function (event) {
|
|
||||||
const data = $('#BT-data').val();
|
|
||||||
console.info(data);
|
|
||||||
QSS_API_WRAPPER.invokeServerMethod('SendPrinterData', 'BT', data);
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
|
|
||||||
// QSS API: register client-side listeners
|
|
||||||
if (QSS_API_WRAPPER.connection !== null) {
|
|
||||||
QSS_API_WRAPPER.onClientMethod('OnReaderDataReceived', function (deviceType, data) {
|
|
||||||
if (deviceType == 'BC') {
|
|
||||||
$('#BC-data').append(data);
|
|
||||||
} else {
|
|
||||||
$('#OC-data').append(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -1,10 +1,2 @@
|
|||||||
# signal-code-samples
|
# signal-code-samples
|
||||||
|
|
||||||
## Instructions
|
|
||||||
See **4N.html** for sample code that demonstrates how to include the required libraries and use the client wrapper provided in **qlogic-signal.js**.
|
|
||||||
|
|
||||||
* JavaScript includes:
|
|
||||||
* JQuery
|
|
||||||
* JQuery SignalR (for Framework API)
|
|
||||||
* Microsoft's SignalR (for Core API)
|
|
||||||
* qlogic-signal.js (wraps Framework and Core clients)
|
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
# Internal Notes
|
|
||||||
|
|
||||||
## Created hard links to share files between projects
|
|
||||||
```
|
|
||||||
PS C:\Users\brian\source\repos\qlogic\signal-code-samples> New-Item -Itemtype HardLink -Path qlogic-signal.js -Target C:\Users\brian\source\repos\qlogic\signal-lib-dotnetframework\samples\DeviceUserWebApp\Scripts\qlogic-signal.js
|
|
||||||
|
|
||||||
Directory: C:\Users\brian\source\repos\qlogic\signal-code-samples
|
|
||||||
|
|
||||||
Mode LastWriteTime Length Name
|
|
||||||
---- ------------- ------ ----
|
|
||||||
-a--- 3/30/2026 8:29 PM 5244 qlogic-signal.js
|
|
||||||
|
|
||||||
PS C:\Users\brian\source\repos\qlogic\signal-code-samples> New-Item -Itemtype HardLink -Path 4N.html -Target C:\Users\brian\source\repos\qlogic\signal-lib-dotnetframework\samples\DeviceUserWebApp\4N.html
|
|
||||||
|
|
||||||
Directory: C:\Users\brian\source\repos\qlogic\signal-code-samples
|
|
||||||
|
|
||||||
Mode LastWriteTime Length Name
|
|
||||||
---- ------------- ------ ----
|
|
||||||
-a--- 3/30/2026 8:31 PM 11172 4N.html
|
|
||||||
```
|
|
||||||
167
qlogic-signal.js
167
qlogic-signal.js
@ -1,167 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
// Convert querystring name/value pairs into dictionary.
|
|
||||||
const QUERY_STRING = (function (a) {
|
|
||||||
if (a == '') return {};
|
|
||||||
const b = {};
|
|
||||||
for (let i = 0; i < a.length; ++i) {
|
|
||||||
const p = a[i].split('=', 2);
|
|
||||||
if (p.length == 1)
|
|
||||||
b[p[0]] = '';
|
|
||||||
else
|
|
||||||
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, ' '));
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
})(window.location.search.substr(1).split('&'));
|
|
||||||
function onReaderDataReceived(deviceType, data) {
|
|
||||||
console.log(data + '\n' + hexView(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name of group that the client will join on connection
|
|
||||||
const QSS_GROUP_NAME = 'DeviceUsers';
|
|
||||||
|
|
||||||
const SIGNALR_CONNECTION_STATE_LABEL = {
|
|
||||||
0: 'Connecting',
|
|
||||||
1: 'Connected',
|
|
||||||
2: 'Reconnecting',
|
|
||||||
4: 'Disconnected'
|
|
||||||
};
|
|
||||||
|
|
||||||
// A unified wrapper to handle both Framework and Core SignalR APIs.
|
|
||||||
const QSS_API_WRAPPER = {
|
|
||||||
connection: null,
|
|
||||||
type: null, // 'framework' or 'core'
|
|
||||||
deviceHubProxy: null, // only populated in 'framework'
|
|
||||||
|
|
||||||
// Map a server-side call
|
|
||||||
invokeServerMethod: function (methodName, ...args) {
|
|
||||||
if (this.type === 'framework') {
|
|
||||||
|
|
||||||
// Framework API call
|
|
||||||
return this.deviceHubProxy.invoke(methodName, ...args);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Core API call
|
|
||||||
return this.connection.invoke(methodName, ...args);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Map a client-side listener
|
|
||||||
onClientMethod: function (methodName, callback) {
|
|
||||||
if (this.type === 'framework') {
|
|
||||||
|
|
||||||
// Framework client-side listener
|
|
||||||
this.deviceHubProxy.on(methodName, callback);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Core client-side listener
|
|
||||||
this.connection.on(methodName, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function isNullEmptyOrWhitespace(value) {
|
|
||||||
if (value == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (typeof value === 'string') {
|
|
||||||
return value.trim().length === 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startSignalR(callback) {
|
|
||||||
if (!('qssUrl' in QUERY_STRING) || isNullEmptyOrWhitespace(QUERY_STRING['qssUrl'])) {
|
|
||||||
console.warn('Missing "qssUrl" in query string');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('Attempting SignalR ASP.NET Framework connection...');
|
|
||||||
|
|
||||||
//
|
|
||||||
// ASP.NET Framework
|
|
||||||
//
|
|
||||||
|
|
||||||
QSS_API_WRAPPER.connection = $.hubConnection(QUERY_STRING['qssUrl'], { useDefaultPath: false });
|
|
||||||
QSS_API_WRAPPER.deviceHubProxy = QSS_API_WRAPPER.connection.createHubProxy('deviceHub');
|
|
||||||
|
|
||||||
// Redirect Framework events to event handlers provided in callback class
|
|
||||||
QSS_API_WRAPPER.connection.starting(function () {
|
|
||||||
callback.framework_starting();
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.connection.received(function (data) {
|
|
||||||
callback.framework_received(data);
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.connection.connectionSlow(function () {
|
|
||||||
callback.framework_connectionSlow();
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.connection.reconnecting(function () {
|
|
||||||
callback.framework_reconnecting();
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.connection.reconnected(function () {
|
|
||||||
callback.framework_reconnected();
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.connection.stateChanged(function (change) {
|
|
||||||
callback.framework_stateChanged(change);
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.connection.disconnected(function () {
|
|
||||||
callback.framework_disconnected();
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
QSS_API_WRAPPER.connection.start()
|
|
||||||
.done(() => {
|
|
||||||
console.log("Connected to ASP.NET Framework SignalR!");
|
|
||||||
|
|
||||||
QSS_API_WRAPPER.deviceHubProxy.invoke('JoinGroup', QSS_GROUP_NAME)
|
|
||||||
.done(function () {
|
|
||||||
console.log('Joined group: ' + QSS_GROUP_NAME);
|
|
||||||
})
|
|
||||||
.fail(function (error) {
|
|
||||||
console.error('Invocation of JoinGroup failed. Error:', error);
|
|
||||||
});
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.fail((err) => {
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.type = 'framework';
|
|
||||||
|
|
||||||
} catch (frameworkErr) {
|
|
||||||
console.warn("Framework connection failed. Trying ASP.NET Core...", frameworkErr);
|
|
||||||
|
|
||||||
//
|
|
||||||
// ASP.NET Core
|
|
||||||
//
|
|
||||||
|
|
||||||
QSS_API_WRAPPER.connection = new signalR.HubConnectionBuilder()
|
|
||||||
.withUrl(QUERY_STRING['qssUrl'])
|
|
||||||
.withAutomaticReconnect() // Required to perform automatic reconnects
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// Redirect Core events to event handlers provided in callback class
|
|
||||||
QSS_API_WRAPPER.connection.onreconnecting(function (error) {
|
|
||||||
console.log('onreconnecting');
|
|
||||||
callback.core_onreconnecting(error);
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.connection.onreconnected(function (connectionId) {
|
|
||||||
console.log('onreconnected');
|
|
||||||
callback.core_onreconnected(connectionId);
|
|
||||||
});
|
|
||||||
QSS_API_WRAPPER.connection.onclose(function (error) {
|
|
||||||
console.log('onclose');
|
|
||||||
callback.core_onclose(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
await QSS_API_WRAPPER.connection.start();
|
|
||||||
console.log("Connected to ASP.NET Core SignalR!");
|
|
||||||
QSS_API_WRAPPER.type = 'core';
|
|
||||||
} catch (coreErr) {
|
|
||||||
console.error("Both SignalR connection attempts failed.", coreErr);
|
|
||||||
QSS_API_WRAPPER.type = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user