Click here to Skip to main content
15,444,490 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi Am attempting to write a driver for a datecs fiscal printer that is linked to a third party software. The idea is to retrieve data from the the third party software and send it to the fiscal printer. I do not have access to the source code for the third party software and can only retrieve data from the data dictionary.

I believe I need to write a printer driver but have no idea where to begin. I have the user manual for the datecs printer that gives me a set of commands for instance:
Command: 48(30h) - is used to open a fiscal receipt

The printer has a driver but I have to issue manual commands to print. The idea is to automatically send the commands to the printer.

I would really appreciate any assistance you can give me.

Cheers!

T
Posted
Comments
Sergey Alexandrovich Kryukov 25-Jan-11 10:48am    
It like you need to hire a programmer
Orges Kreka 7-Aug-17 8:31am     CRLF
i have to communicate using hex commands with the same fiscal printer, can you give me any idea of the protocol it uses, or how it converts the text commands to hexadecimal. Thanks!

Did you try the SDK here? Doesn't that allow you to do what you say?

http://www.datecs.bg/support.php?cat=4[^]
 
Share this answer
 
Hy!

Class for direct print commands:



Public Class DATECS
Const strANS As String = "______,_,__;"

Private LDN As Short 'Logical Device Number
Private strLine As String
Private BillCtr As Integer
Dim noNbDec As New System.Globalization.NumberFormatInfo
Dim niDec As New System.Globalization.NumberFormatInfo
Dim threeDec As New System.Globalization.NumberFormatInfo

Public Sub New(ByVal strPath As String, ByVal LogicalDeviceNb As Short)

On Error GoTo errHandler

FileOpen(1, strPath, OpenMode.Output)
LDN = LogicalDeviceNb
BlockKeypad()

noNbDec.NumberDecimalDigits = 0
niDec.NumberDecimalDigits = 2
threeDec.NumberDecimalDigits = 3

Exit Sub
errHandler:
Err.Raise(Err.Number, "New DATECS", Err.Description)
End Sub

Public Sub BlockKeypad()
strLine = "H," & CStr(LDN) & ",______,_,__;"
PrintLine(1, strLine)
End Sub

Public Sub UnBlockKeypad()
strLine = "F," & CStr(LDN) & ",______,_,__;"
PrintLine(1, strLine)
End Sub

Public Sub AddProduct(ByVal productName As String, ByVal Qtyvar As Decimal, ByVal SalesValue As Decimal, ByVal SAIDvar As Integer, ByVal CatIDvar As Integer, ByVal VATGroup As Short)

strLine = "S," & CStr(LDN) & "," & strANS & Trim(Mid(productName, 1, 22)) & ";" & SalesValue.ToString("f", niDec) & ";" & Qtyvar.ToString("f", noNbDec) & ";" & CStr(SAIDvar) & ";" & CStr(CatIDvar) & ";" & CStr(VATGroup) & ";" & "0;0;"
PrintLine(1, strLine)

End Sub

Public Sub CashInOut(ByVal dSum As Decimal, Optional ByVal bWithdraw As Boolean = False)
Dim iCode As Integer = 1
'0 - cash IN
'1- cash OUT

On Error GoTo errHandler

If bWithdraw Then
iCode = 1 'cash out
Else
iCode = 0 'cash in
End If

strLine = "I," & CStr(LDN) & "," & strANS & iCode & ";" & dSum.ToString("f", niDec) & ";;;;"
PrintLine(1, strLine)

Exit Sub
errHandler:
MsgBox("Error nb: " & Err.Number & ", " & "Error desc.: " & Err.Description & ", Error src.: " & " WithdrawInput")
End Sub

Public Sub DiscountIncrease(ByVal dProcent As Decimal, Optional ByVal iCode As Integer = 1)
'0 -Increase
'1- Discount

strLine = "C," & CStr(LDN) & "," & strANS & iCode & ";" & dProcent.ToString("f", niDec) & ";;;;"
MsgBox(strLine)
PrintLine(1, strLine)

End Sub

Public Sub AddTextLine(ByVal T1 As String, Optional ByRef T2 As String = "", Optional ByRef T3 As String = "", Optional ByRef T4 As String = "", Optional ByRef T5 As String = "")

strLine = "P," & CStr(LDN) & "," & strANS & T1 & ";"
If Not IsDBNull(T2) Then strLine = strLine & T2 & ";"
If Not IsDBNull(T3) Then strLine = strLine & T3 & ";"
If Not IsDBNull(T4) Then strLine = strLine & T4 & ";"
If Not IsDBNull(T5) Then strLine = strLine & T5 & ";"

PrintLine(1, strLine)

End Sub

Public Sub Subtotal()

PrintLine(1, "T," & CStr(LDN) & "," & strANS & "4;;;;;")
'0 - cash
'1-ceck
'2-card
'3-ticket
'4 -subtotal

End Sub

Public Sub AddPayment(ByVal pmtType As Short)
PrintLine(1, "T," & CStr(LDN) & "," & strANS & CStr(pmtType) & ";;;;;")
End Sub

End Class

This is how you use this class:

Public Function DATECSFiscal() As String
Dim sHeader As String
Dim myBill As New DATECS
Dim c() As String
Dim SA As String = ""
Dim sSeparator As New StringBuilder()
Dim dQty As Decimal
Dim dPrice As Decimal
Dim dNetAmount As Decimal
Dim dInitialAmount As Decimal
Dim dSubTotal As Decimal
Dim iDepID As Integer = 1
Dim iGroupArt As Integer = 1
Dim dDiscount As Decimal

On Error GoTo errHandler

LDN = 1
BillCtr = CInt(dtData.Rows(0).Item(12))

myBill = New DATECS(BillINPPath, LDN, BillCtr)
SA = dtData.Rows(0).Item(10).ToString
myBill.AddTextLine(SA & " " & dtData.Rows(0).Item(11).ToString)
myBill.AddTextLine("Product Qty SubTotal")

sSeparator = New StringBuilder
sSeparator.Append("-", pLineSize)

myBill.AddTextLine(sSeparator.ToString)

dNetAmount = CDec(dtData.Rows(0).Item(15))
dInitialAmount = CDec(dtData.Rows(0).Item(13))
dDiscount = CDec(dtData.Rows(0).Item(14))

Dim drt As System.Data.DataRow
For Each drt In dtData.Rows

dQty = CDec(drt.Item(1).ToString())
dPrice = CDec(drt.Item(3).ToString)
dSubTotal = CDec(drt.Item(4).ToString)

iDepID = (CDec(drt.Item(17)) Mod maxDepNb) + 1
iGroupArt = (CDec(drt.Item(18)) Mod maxArtNb) + 1

myBill.AddProduct(Mid(Trim(drt.Item(2).ToString), 1, productLength), dQty, dPrice, iDepID, iGroupArt, 1)
Next

SQL
myBill.Subtotal()
     
       If dDiscount > 0 Then
           DiscountRate = (dDiscount / dInitialAmount) * 100           
           myBill.DiscountIncrease(DiscountRate)
       End If

       Select Case PmtModality
           Case Is = 2 'Cash
               myBill.AddPayment(0)
           Case Is = 3 'Credit Card
               myBill.AddPayment(2)
       End Select


myBill.CloseFiscalBill()
myBill = Nothing

Dim pResult As String
pResult = RunPrinterProcess(AppDriverPath, Port & " 9600 """ & BillINPPath & "\Bill" & CStr(BillCtr) & ".INP""")

On Error Resume Next

FileClose(1)

End Function

Private Function RunPrinterProcess(ByVal sFileName As String, ByVal sArguments As String) As String

Try

RunPrinterProcess = "OK"

Dim oPro As New Process
With oPro
.StartInfo.UseShellExecute = True
.StartInfo.Arguments = sArguments '"COM1 9600 " & InpFilePath
.StartInfo.FileName = sFileName '' "C:\Program Files\Datecs Applications\FPrintWIN\FPrint.exe"
.Start()
End With

Catch ex As Exception
RunPrinterProcess = "Error nb: " & Err.Number & ", " & "Error desc.: " & Err.Description & ", Error src.: " & " RunPrinterProcess " & " FileName: " & sFileName & " , Arguments: " & sArguments

FileClose(1)
End Try

End Function

First you must have FPrint.exe installed on the pc where the software is, and the printer must be connected to this pc.
In the code above I create a file "C:\Bill1.inp" and then I create and start the process :

"C:\Program Files\Datecs Applications\FPrint WIN\FPrint.exe" COM1 9600"C:\Bill1.inp"

Your file looks like this:

H,1,______,_,__;1,0;
P,1,______,_,__;Salon Sa1;;;;;
P,1,______,_,__;Product Qty SubTotal;;;;;
P,1,______,_,__;----------------------;;;;;
S,1,______,_,__;Miere 10gr;1.00;1;2;1;1;0;0;
T,1,______,_,__,4;;;;;


My printer is Datecs MP55B ...but if you have another type ...the only thing that will change will be the commands (but you will find this in documentation of your printer)

There is another example of inp file (another printer model):
48,1,______,_,__;1;000000;0;
49,1,______,_,__;Gherkins;0.05;1.000;5;0;0;0;
49,1,______,_,__;Gherkins;-0.05;1.000;5;0;0;0;
49,1,______,_,__;Potatoes;0.02;1.000;2;0;0;0;
49,1,______,_,__;Potatoes;-0.02;1.000;2;0;0;0;
T,1,______,_,__;

For testing, you have to enter in programming mode in cash register.
For Datecs MB55B I had to enter to cash register this:

ON
429 TOTAL
(or something like this...but you will find this in your cash register documentation also)

After testing you have to go back to sale mode.

The CashInOut and DiscountIncrease are not working...yet..I don't know why , because this is the sintax, I'm still testing..


If you must have this code in C:

http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]

Have a nice day!
Alina
 
Share this answer
 
v8
Hi!
We're welcome!
I really had a hard time to work this out also..
I figured out why discount wasn't working.
So the Discount function works like this (I've tested it):

'adding products
'S,1,______,_,__;ProductName;18.00;1;1;4;1;0;0;
'subtotal
'T,1,______,_,__,4;;;;;
'Discount
'C,1,______,_,__,1;50.00;;;;
'Total 'for cash payment
'T,1,______,_,__,0;;;;;

SQL
myBill.AddProduct(Mid(Trim(drt.Item(2).ToString), 1, productLength), dQty, dPrice, iDepID, iGroupArt, 1)
   
    myBill.Subtotal()
    If dDiscount > 0 Then
        DiscountRate = (dDiscount / dInitialAmount) * 100
        myBill.DiscountIncrease(DiscountRate)
    End If

    Select Case PmtModality
        Case Is = 2 'Cash
            myBill.AddPayment(0)
        Case Is = 3 'Credit Card
            myBill.AddPayment(2)
    End Select



The CASH IN , CASH OUT still doesn't work... If you'll find a solutin, please share it ;)

I modified my previous post also , I added the discount and I modified the CashINCashOUT function because I modified the parameters (0 value (cash in) or 1 (cash out)) . In my first code the parameters were messed up ( 1 -cash in , 0-cash out) ;)
Alina
 
Share this answer
 
v6
Try new version of fiscal printers based on FisBox with ARM Cortex M3 CPU and 4GB memory.
I think, there is right way to future of fiscal storage.
See also receipt example.
www.FisBox.eu
 
Share this answer
 
Hi Alina
Thank you so much for this. I really appreciate, I have been working on this for some time but we ran into problems with our test printer. As soon it is up and running I will test the code and let you know how it goes.
Thanks once again.
Cheers!
T
 
Share this answer
 
You can try my sourcecode for Openbravo POS http://forge.openbravo.com/projects/openbravopos/forum/fiscal-printer-datecs-native-support-is-ready--t7031961.html

My solution support low-level protocol for integration Datecs fiscal printer.
 
Share this answer
 
Comments
Member 10456578 13-Sep-14 17:09pm    
the link above page could not be found

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900