Choose where the webpage runs
Same PC HWCommX and the browser run on one computer.
Keep LAN access off.
API: http://127.0.0.1:8765
Different PC on LAN Enable LAN access in HWCommX and enter the HWCommX PC IP.
Example API: http://192.168.0.151:8765
Allow TCP port 8765 through the Private-network firewall.
Website on VPS Host the page using HTTPS.
Set Allowed Origin to the website origin, such as https://scale.example.com.
Use 127.0.0.1 when the browser and HWCommX are on the same PC.
Important: Allowed Origin is the address that serves the webpage—not the Bridge API URL. Do not double-click the HTML file. If Chrome asks whether the website may find and connect to devices on your local network, choose
Allow .
Read Chrome’s Local Network Access guide .
Run HWCommX Scale and confirm the Browser API is running.
Place hwcommx-scale.js beside your webpage and include it once.
Create HWCommXProductClient , then call download() or upload(products).
Complete integration code
JavaScript only
Complete HTML page
Include in an existing page Copy code
<script src="hwcommx-scale.js"></script>
<script>
const products = new HWCommXProductClient({
apiUrl: 'http://127.0.0.1:8765/api/scale/products',
requestTimeoutMs: 30000
});
async function getProductsFromScale() {
const rows = await products.download();
// Display rows in your table.
console.table(rows);
}
async function updateProductsToScale(rows) {
const result = await products.upload(rows);
console.log('Updated products:', result.updated);
}
</script>
Standalone browser page Copy HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Scale Products</title>
</head>
<body>
<button id="download">Get Product From Scale</button>
<button id="upload">Update Product To Scale</button>
<pre id="output"></pre>
<script src="hwcommx-scale.js"></script>
<script>
const output = document.getElementById('output');
const products = new HWCommXProductClient({
apiUrl: 'http://127.0.0.1:8765/api/scale/products',
requestTimeoutMs: 30000
});
let rows = [];
document.getElementById('download').onclick = async () => {
rows = await products.download();
output.textContent = JSON.stringify(rows, null, 2);
};
document.getElementById('upload').onclick = async () => {
const result = await products.upload(rows);
output.textContent = `Updated ${result.updated} products`;
};
</script>
</body>
</html>
Product row format Copy row
const row = {
pluNo: 1,
name: 'manzana',
code: '0000222',
price: 877,
mode: 'weight',
shelfLife: 30,
tare: 0,
labelNo: 0,
remarkA: '',
remarkB: '',
advertisement1: 0,
advertisement2: 0,
advertisement3: 0,
shopNo: 0
};
The webpage communicates with the HWCommX Scale local API. HWCommX Scale performs the raw Ethernet/TCP communication with the weighing scale.