I've got a small app testing printing to a EPSON TM30 POS printer.
I'm including external JS scripts from Epson and also some code that I have in JS format. Then after loading I'm just running a script to connect and test print. It works in dev but when I deploy, it doesn't work and I get a uncaught reference error like the script wasn't loaded. I checked the inspection and saw through the network tab that the relevant files are loaded.
Code: Select all
Global nLoaded
Global nImports = 2
Procedure Main()
EnableJS
Connect();
DisableJS
EndProcedure
Procedure ScriptLoaded(URL$, Success)
If Success
nLoaded + 1
If nLoaded = nImports ; the number of files to import
Main()
EndIf
Else
Debug "Failed to load external: " + URL$
EndIf
EndProcedure
;Just open window
OpenWindow(0, 100, 100, 320, 200, "Window 0 - Resizable", #PB_Window_SizeGadget)
;from epson
LoadScript("epos-2.23.0.js", @ScriptLoaded())
;from myself
LoadScript("print.js", @ScriptLoaded())
Code: Select all
var ipAddress = "192.168.220.210";
var port = 8008;
var eposdev = new epson.ePOSDevice();
var printer = null;
var intervalID = null;
eposdev.onreconnecting = onReconnecting;
eposdev.onreconnect = onReconnect;
eposdev.ondisconnect = onDisconnect;
function onReconnecting(){
console.log("reconnecting");
}
function onReconnect(){
console.log("reconnect");
}
function onDisconnect(){
console.log("clear");
if ( intervalID == null ){
intervalID = setInterval(function(){
eposdev.connect(ipAddress, port, callback_connect);
}, 5000);
}
}
function Connect() {
console.log("Connect() clear");
eposdev.ondisconnect = null;
eposdev.disconnect();
eposdev.connect(ipAddress, port, callback_connect);
console.log("Connect() clear2");
}
var printer = null;
function callback_createDevice(deviceObj, errorCode){
console.log("callback_createDevice");
if (deviceObj === null) {
console.log("callback_createDevice error");
//Displays an error message if the system fails to retrieve the Printer object
return;
}
printer = deviceObj;
TestPrint();
//Registers the print complete event
printer.onreceive = function(response){
if (response.success) {
console.log("OK! Everything");
}
else {
console.log("NotOK! Everything");
}
};
}
function TestPrint() {
printer.addText("\n\n");
printer.addText("Test print:");
printer.addText("\n\n");
printer.addCut(printer.CUT_FEED);
printer.send();
}
function callback_connect(data) {
var deviceId = 'local_printer';
var options = {'crypto' : false, 'buffer' : false};
console.log("callback_connect");
clearInterval(intervalID);
intervalID = null;
eposdev.ondisconnect = onDisconnect;
console.log("Data", data);
if (data == "OK" || data == "SSL_CONNECT_OK") {
console.log("Printer conn");
eposdev.createDevice(deviceId, eposdev.DEVICE_TYPE_PRINTER, options, callback_createDevice);
console.log("Printing conn");
} else {
console.log('Recon');
setTimeout(function(){
eposdev.connect(ipAddress, port, callback_connect);
}, 5000);
}
}
https://file.io/FXPWBBcsrQke
For creating the app, I'm simply putting the App Name, the HTML Filename and check the Copy spiderbasic libraries
Then deploy to webserver and try with SSL enabled.
Can someone look and see if I'm doing anything dumb here? Thanks.