Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Commerce forum / How to call HardwareSt...
Commerce forum
Unanswered

How to call HardwareStation extension from POS

Posted on by

I have HardwareStation for PDF printing, copied from RetailSDK example.  

In HardwareStation.Extension.Config.  I add assembly for new extensions and 3rd party library.  

<add source="assembly" value="FreeSpire.PDF" />
<add source="assembly" value="XXX.Commerce.HardwareStation.Extension.PDFPrinter" />
<add source="assembly" value="XXX.Commerce.HardwareStation.Extension.WindowsPrinter" />

In Controller as below

namespace XXX
{
namespace Commerce.HardwareStation.PDFPrinter
{
using System;
using System.Threading.Tasks;
using Microsoft.Dynamics.Commerce.HardwareStation;
using Microsoft.Dynamics.Commerce.Runtime.Hosting.Contracts;
using Spire.Pdf;

/// <summary>
/// PDF printer web API controller class.
/// </summary>
[RoutePrefix("PDFPrinterController")]
public class PDFPrinterController : IController
{
/// <summary>
/// Prints the content.
/// </summary>
/// <param name="printRequest">The print request.</param>
/// <exception cref="System.Web.Http.HttpResponseException">Exception thrown when an error occurs.</exception>
[HttpPost]
public Task<bool> Print(PrintPDFRequest printRequest)
{
ThrowIf.Null(printRequest, "printRequests");

try
{
byte[] receivedFile = Convert.FromBase64String(printRequest.EncodedBinary);

// Add here the code to send the PDF file to the printer.
PdfDocument pdf = new PdfDocument(receivedFile);
pdf.PrintSettings.PrinterName = printRequest.DeviceName;
pdf.Print();

return Task.FromResult(true);
}
catch (PeripheralException ex)
{
Console.WriteLine(ex.Message);
throw;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw new PeripheralException(PeripheralException.PrinterError, ex.Message, ex);
}
}
}
}
}

In POS Web AppBar extension, I call the HardwareStationRequest as in red text:

protected execute(): void {

this.isProcessing = true;
window.setTimeout((): void => {
this.isProcessing = false;
}, 2000);
this.getHardwareProfile();
this.getDataArea();

let pdfTransferOrders = this.getTransferOrderPDF(this._order.orderId, this.transferDataAreaId, this.hardwareProfileId);

pdfTransferOrders.then((response: Commerce.Proxy.Entities.Receipt[]):
Promise<ClientEntities.ICancelableDataResult<PrinterPrintResponse>> => {
let receipts: ProxyEntities.Receipt[] = response;

// Prints the receipts.
//let printerPrintRequest: PrinterPrintRequest<PrinterPrintResponse> = new PrinterPrintRequest(receipts);

//return this.context.runtime.executeAsync(printerPrintRequest);


let receipt: Commerce.Proxy.Entities.Receipt = Commerce.ArrayExtensions.firstOrUndefined(
receipts,
(p): boolean => { return Commerce.ArrayExtensions.hasElements(p.Printers) }
);

let printRequest: PrintPDFRequest = new PrintPDFRequest(receipt.Header, receipt.Printers[0].Name);

let hwsRequest: Commerce.HardwareStationDeviceActionRequest<Commerce.HardwareStationDeviceActionResponse>
= new Commerce.HardwareStationDeviceActionRequest<Commerce.HardwareStationDeviceActionResponse>(
"PDFPrinterController", // controller's name
"Print", // method name
printRequest
);

return this.context.runtime.executeAsync(hwsRequest)
.then((hwsResponse: ClientEntities.ICancelableDataResult<Commerce.HardwareStationDeviceActionResponse>)
: ClientEntities.ICancelableDataResult<PrintPackingSlipClientResponse> => {
this.isProcessing = false;
return <ClientEntities.ICancelableDataResult<PrintPackingSlipClientResponse>>{ canceled: hwsResponse.canceled };
});

}).then((): Promise<void> => {
// Resolves to a void result when fulfilled.
this.isProcessing = false;
return Promise.resolve();
}).catch((reason: any): Promise<void> => {
// Resolves to a void result when rejected. This matches existing POS printing behavior.
this.context.logger.logError("Print transfer order execute error: " + JSON.stringify(reason));
this.isProcessing = false;
return Promise.resolve();
});


}

But once I run MPOS and click the AppBar button, I got error.  

The description for Event ID 46802 from source Microsoft-Dynamics-Commerce-ModernPos cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event:

Request.HardwareStationDeviceActionRequest.HardwareStationDeviceActionRequest
Pos_Extensibility_XXX
xxxxxx
7.3.0.0
["{\"number\":0,\"description\":\"\",\"stack\":\"CommerceError\\n at Error (ms-appx://microsoft.dynamics.retail.pos/Commerce.AsyncResult.js:29:21)\\n at HardwareStationRequestHandler.prototype._validateHardwareStationRequestUri (ms-appx://microsoft.dynamics.retail.pos/Pos.Core.js:56004:25)\\n at Anonymous function (ms-appx://microsoft.dynamics.retail.pos/Pos.Core.js:55965:25)\\n at Anonymous function (ms-appx://microsoft.dynamics.retail.pos/Pos.Framework.js:178:25)\",\"name\":\"CommerceError\",\"_canRetry\":false,\"_errorCode\":\"string_4908\",\"_externalLocalizedErrorMessage\":\"\",\"_handled\":false,\"_formatData\":[],\"_errorTitleResourceId\":\"\",\"_isUserError\":false,\"message\":\"\",\"ErrorCode\":\"string_4908\",\"ExternalLocalizedErrorMessage\":\"\",\"formatData\":[],\"errorTitleResourceId\":\"\",\"canRetry\":false,\"handled\":false,\"isUserError\":false,\"__proto__\":{}}"]
ff92ebb3-2add-c5e3-d120-0a432970c6b3
2e092f26-d287-70ae-9c51-480fdf5c7a0f
88a84cdc-b5f8-904e-5480-c9a581ce7688
1605156676546
1

The publisher has been disabled and its resource is not available. This usually occurs when the publisher is in the process of being uninstalled or upgraded

pastedimage1605156725861v1.png

pastedimage1605156823891v3.png

pastedimage1605156853743v4.png

I check in folder C:\Program Files (x86)\Microsoft Dynamics 365\70\Retail Modern POS\ClientBroker, those HardwareStation extension files are there already.   

Is it correct code for calling HardwareStation extension from POS?   

  • OriolMachin Profile Picture
    OriolMachin on at
    RE: How to call HardwareStation extension from POS

    Hello AyePKA,

    I corrected a typo on my earlier post, it was meant to say "Could you confirm if you are PAIRED TO theHardwareStation?"

    I'm very sorry for your experience. I'm not too familiar with the Support Plans, However I do see there are topics related to development and customizations.

    I'm hoping the community can contribute more to this topic, but if not, I believe the following two support topics should help with development issues.

    Selecting  Technical and System Administration > Development and customization:
    pastedimage1605642427292v1.png pastedimage1605642455659v2.png

    or I believe Commerce > Developer Experience

    pastedimage1605642507970v3.pngpastedimage1605642681843v4.png

    I hope this helps,

    Oriol Machin

    Support Engineer / Microsoft Dynamics 365 Commerce

    North America Customer Services and Support

  • pka Profile Picture
    pka on at
    RE: How to call HardwareStation extension from POS

    I don't know if we have to pay for HardwareStation extensibility.

    Actually, my company has Technical support with ASfP Plan that will forward to China team (same timezone).   They always reject to help if it's about extensibility.    They mention "Out of scope".

  • OriolMachin Profile Picture
    OriolMachin on at
    RE: How to call HardwareStation extension from POS

    Hello AeyPKA,

    Could you please confirm if you are paired to the HardwareStation?

    if you will not get any advice from the community, please create a support ticket for us so we can investigate it further.

    Thank you for using Microsoft Dynamics 365 Communities,

    Oriol Machin

    Support Engineer / Microsoft Dynamics 365 Commerce

    North America Customer Services and Support

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,914 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans