-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,474 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# OpenProtocol™ .Net Interface Library | ||
|
||
Target Runtime: .NET Standard 1.6 | ||
|
||
.Net assembly to interface with the iChen® System using OpenProtocol™. | ||
|
||
This assembly is written in C# but supports all languages supported by .NET. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,6 @@ | ||
# OpenProtocol™ .NET Library | ||
# OpenProtocol™ .NET Interface Library | ||
|
||
.Net assembly to interface with the iChen® System using OpenProtocol™. | ||
|
||
This assembly is written in C# but supports all languages supported by .NET. | ||
The assembly is written in C# but supports all languages supported by .NET. | ||
This assembly targets the .NET Standard Framework version 1.6. | ||
|
||
|
||
## Example Programs | ||
|
||
### OpenProtocolViewer | ||
|
||
Location: `examples/OpenProtrocolViewer` | ||
|
||
A C# console example program that connects to an iChen® server using OpenProtocol™. | ||
Messages are displayed on-screen. | ||
It also acts as a user authenticator and job cards provider for testing the relevant features. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# OpenProtocol™ Viewer (C# Console) | ||
|
||
.NET Framework Version: 4.6.1 or up | ||
|
||
This is a simple console application written in C# that connects to an iChen® System using OpenProtocol™. | ||
|
||
OpenProtocol™ messages to and from the server are logged on-screen. | ||
|
||
This application also acts as a user authentication and job cards provider to test out the operator login and job card features. | ||
|
||
## How to Use | ||
|
||
Launch `OpenProtocolViewer.exe` in and enter the following information: | ||
|
||
**`WebSocket URL`** : URL of the OpenProtocol™ interface, usually `ws://MyiChenServerUrl:5788` or `ws://x.x.x.x:5788` (5788 is the default OpenProtocol™ interface port). | ||
|
||
**`Password`** : A login password to connect to the system. System default is `chenhsong` for the `admin` user with unlimited admin rights (other than MIS rights). | ||
To try out the MIS features (e.g. operator login, job cards), first set up a new user account with the appropriate rights, then login with that password. | ||
Otherwise, the user authentication and job cards provider will not work. | ||
|
||
_Warning: If you do not enter a password of a user account that has the appropriate access rights, you'll fail to see all OpenProtocol™ messages._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" /> | ||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# OpenProtocol™ Web Viewer (JavaScript) | ||
|
||
Language Version: ECMAScript 3 | ||
|
||
This is a simple web application written in JavaScript that connects to an iChen® System using OpenProtocol™. | ||
|
||
OpenProtocol™ messages to and from the server are logged on-screen. | ||
|
||
This application also acts as a user authentication and job cards provider to test out the operator login and job card features. | ||
|
||
## How to Use | ||
|
||
### 1. Enter Credentials | ||
|
||
Launch `index.html` in a web browser and enter the following information: | ||
|
||
**`URL`** : URL of the OpenProtocol™ interface, usually `ws://MyiChenServerUrl:5788` or `ws://x.x.x.x:5788` (5788 is the default OpenProtocol™ interface port). | ||
|
||
**`Password`** : A login password to connect to the system. System default is `chenhsong` for the `admin` user with unlimited admin rights (other than MIS rights). | ||
To try out the MIS features (e.g. operator login, job cards), first set up a new user account with the appropriate rights, then login with that password. | ||
Otherwise, the user authentication and job cards provider will not work. | ||
|
||
_Warning: If you do not enter a password of a user account that has the appropriate access rights, you'll fail to see all OpenProtocol™ messages._ | ||
|
||
### 2. Connect | ||
|
||
Next, press the `Connect to Server` button to connect to the iChen® System server. | ||
|
||
### 3. Other Features | ||
|
||
**`Get Mold Data`** reads the current state of the recipe (mold data set) on the controller specified. | ||
|
||
**`Read Mold Value`** reads the current value of a particular variable on the controller specified. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
document.addEventListener("DOMContentLoaded", function () | ||
{ | ||
/// Mock job scheduling system | ||
var Jobs = [ | ||
{ jobCardId: "JOB_CARD_1", moldId: "MOULD_001", progress: 0, total: 8000 }, | ||
{ jobCardId: "JOB_CARD_2", moldId: "MOULD_002", progress: 2000, total: 10000 }, | ||
{ jobCardId: "JOB_CARD_3", moldId: "MOULD_003", progress: 888, total: 3333 }, | ||
{ jobCardId: "JOB_CARD_4", moldId: "MOULD_004", progress: 123, total: 45678 } | ||
]; | ||
|
||
// DOM Elements | ||
var txtUrl = document.getElementById("txtUrl"); | ||
var txtPwd = document.getElementById("txtPwd"); | ||
var btnConnect = document.getElementById("btnConnect"); | ||
var txtId = document.getElementById("txtId"); | ||
var btnGetMoldData = document.getElementById("btnGetMoldData"); | ||
var txtField = document.getElementById("txtField"); | ||
var btnReadMoldData = document.getElementById("btnReadMoldData"); | ||
var divMessages = document.getElementById("messages"); | ||
|
||
// Hook up buttons | ||
btnConnect.addEventListener("click", run); | ||
btnGetMoldData.addEventListener("click", function () { return getMoldData(parseInt(txtId.value, 10)); }); | ||
btnReadMoldData.addEventListener("click", function () { return readMoldData(parseInt(txtId.value, 10), txtField.value); }); | ||
|
||
// Log text to page | ||
function logText(type, text) | ||
{ | ||
var div = document.createElement("div"); | ||
div.className = type; | ||
|
||
if (type === "message" || type === "command") { | ||
var code = document.createElement("code"); | ||
code.textContent = text; | ||
div.appendChild(code); | ||
} else { | ||
div.textContent = text; | ||
} | ||
|
||
divMessages.appendChild(div); | ||
} | ||
|
||
// Global variables | ||
var seq = 0; | ||
var ws; | ||
var handle = 0; | ||
|
||
// Send a message via WebSocket | ||
function sendMessage(msg, type) | ||
{ | ||
if (!type) type = "command"; | ||
var json = JSON.stringify(msg); | ||
logText(type, "Sent: " + json); | ||
ws.send(json); | ||
} | ||
|
||
// Main loop | ||
function run() | ||
{ | ||
var url = txtUrl.value.trim(); // WebSocket URL | ||
var password = txtPwd.value.trim(); // Password | ||
|
||
if (!url) { | ||
alert('Please enter a valid WebSocket URL in the format "ws://host:port" or "wss://host:port". Example: "ws://192.168.1.1:5788".'); | ||
txtUrl.focus(); | ||
return; | ||
} | ||
if (!/^wss?\:\/\/.*\:\d+$/.test(url)) { | ||
alert('Please enter a valid WebSocket URL in the format "ws://host:port" or "wss://host:port". Example: "ws://192.168.1.1:5788".'); | ||
txtUrl.focus(); | ||
return; | ||
} | ||
if (!password) { | ||
alert("Please enter a valid password."); | ||
txtPwd.focus(); | ||
return; | ||
} | ||
|
||
// Enable/disable UI elements | ||
txtUrl.disabled = txtPwd.disabled = btnConnect.disabled = true; | ||
txtId.disabled = btnGetMoldData.disabled = false; | ||
txtField.disabled = btnReadMoldData.disabled = false; | ||
|
||
logText("info", "Connecting to iChen 4.0 Server at " + url + "..."); | ||
|
||
// Create a WebSocket connection to the server | ||
ws = new WebSocket(url); | ||
|
||
ws.onopen = function () | ||
{ | ||
// Initialize handshake with server | ||
logText("info", "WebSocket connection established."); | ||
|
||
// Send a JOIN message | ||
sendMessage({ $type: "Join", language: "EN", version: "1.0", password: password, filter: "All, JobCards, Operators", sequence: ++seq }); | ||
|
||
loopHandle = setInterval(function () { sendMessage({ $type: "Alive", sequence: ++seq, priority: -10 }); }, 5000); | ||
}; | ||
|
||
// Wire up WebSocket events | ||
ws.onerror = function (ev) | ||
{ | ||
console.error(ev); | ||
logText("error", "An error has occurred!"); | ||
}; | ||
ws.onclose = function (ev) | ||
{ | ||
logText("info", "WebSocket connection to iChen 4.0 Server is closed."); | ||
logText("info", "Code = " + ev.code + ", Reason = " + ev.reason); | ||
clearInterval(loopHandle); | ||
}; | ||
ws.onmessage = function (msg) | ||
{ | ||
try { | ||
logText("message", "Received: " + msg.data); | ||
var reply_message = handleMessage(JSON.parse(msg.data)); | ||
if (reply_message) sendMessage(reply_message, "reply"); | ||
} catch (err) { console.error(err); } | ||
}; | ||
} | ||
|
||
// Handle message | ||
function handleMessage(message) | ||
{ | ||
switch (message.$type) { | ||
case "JoinResponse": { | ||
// Send a REQ_CNTRLER_LIST message | ||
sendMessage({ $type: "RequestControllersList", sequence: ++seq }); | ||
return null; | ||
} | ||
|
||
case "LoginOperator": { | ||
// MIS integration - return access level | ||
// Popup prompt to ask for the access level | ||
var resp = prompt("User on machine " + message.controllerId + " tries to login with password " + message.password + ". Access level (0-10)?"); | ||
|
||
// Pressed cancel --> ignore message | ||
if (resp === null) return null; | ||
|
||
var access_level = parseInt(resp, 10); | ||
if (access_level > 10) access_level = 10; | ||
if (access_level <= 0) return { $type: "OperatorInfo", controllerId: message.controllerId, operatorId: 0, name: "Disallowed", level: 0 }; | ||
return { $type: "OperatorInfo", controllerId: message.controllerId, operatorId: access_level * 100, name: "User" + access_level, password: message.password, level: access_level, sequence: ++seq }; | ||
} | ||
|
||
case "RequestJobCardsList": { | ||
// MIS integration - return job cards list | ||
var data = {}; | ||
for (var x = 0; x < Jobs.length; x++) data[Jobs[x].jobCardId] = Jobs[x]; | ||
return { $type: "JobCardsList", controllerId: message.controllerId, data: data, sequence: ++seq }; | ||
} | ||
|
||
default: return null; | ||
} | ||
} | ||
|
||
// Send command to get mold data | ||
function getMoldData(id) | ||
{ | ||
if (id === undefined || id === null || isNaN(id)) { | ||
alert("Please enter a valid machine number."); | ||
txtId.focus(); | ||
return; | ||
} | ||
|
||
// Send a REQ_CNTRLER_LIST message | ||
sendMessage({ $type: "RequestMoldData", controllerId: id, sequence: ++seq }); | ||
} | ||
|
||
// Send command to read mold data value | ||
function readMoldData(id, field) | ||
{ | ||
if (id === undefined || id === null || isNaN(id)) { | ||
alert("Please enter a valid machine number."); | ||
txtId.focus(); | ||
return; | ||
} | ||
// Send a READ_MOLD_DATA message | ||
sendMessage({ $type: "ReadMoldData", controllerId: id, field: field, sequence: ++seq }); | ||
} | ||
}); |
Oops, something went wrong.