Dim Header1 As String, DecimalValue As Integer, BinaryValue As String
DecimalValue = &H1A
BinaryValue = DecToBins(DecimalValue, 8)
Header1 = DecToBins(DecimalValue, 8)
MsgBox "Header1 :" & vbCrLf & Header1
Dim Header2 As String
DecimalValue = &H5D
BinaryValue = DecToBins(DecimalValue, 8)
Header2 = DecToBins(DecimalValue, 8)
MsgBox "Header2 :" & vbCrLf & Header2
Dim CmdID As String, CmdOne As String, Cmdtwo As String, Cmdthree As String
DecimalValue = &H1
BinaryValue = DecToBins(DecimalValue, 8)
CmdOne = DecToBins(DecimalValue, 8)
MsgBox "CmdOne :" & vbCrLf & CmdOne
DecimalValue = &H2
BinaryValue = DecToBins(DecimalValue, 8)
Cmdtwo = DecToBins(DecimalValue, 8)
MsgBox "Cmdtwo :" & vbCrLf & Cmdtwo
This has now given me string like = 11111110DecimalValue = &H3
BinaryValue = DecToBins(DecimalValue, 8)
Cmdthree = DecToBins(DecimalValue, 8)
MsgBox "Cmdthree :" & vbCrLf & Cmdthree
CmdID = CmdOne & "><" & Cmdtwo & "><" & Cmdthree
MsgBox "CmdID :" & vbCrLf & CmdID
This has now given me string like = 11111111><11111110><111111Dim length As String, LengthFinal As String
LengthFinal = Len(Trim(CStr(JsonConverter.ConvertToJson(transaction, Whitespace:=3))) & Chr$(13))
DecimalValue = LengthFinal
BinaryValue = DecToBinLength(DecimalValue, 8)
length = DecToBinLength(DecimalValue, 8)
MsgBox "length :" & vbCrLf & length
This has now given me string like = 01010111Dim Content As String, cont As String, fulldata As String
cont = Len(Trim(CStr(JsonConverter.ConvertToJson(transaction, Whitespace:=3))) & Chr$(13))
DecimalValue = cont
BinaryValue = DecToBinContent(DecimalValue, 8)
Content = DecToBinContent(DecimalValue, 8)
MsgBox "Content :" & vbCrLf & Content
fulldata = "<" & Header1 & "><" & Header2 & "><" & CmdID & "><" & length & "><" & Content & ">"
Dim data() As Byte
Dim CRCs As String
data = StrConv(fulldata, vbFromUnicode)
CRCs = cal_crc(data, 10)
MsgBox "CRCs :" & vbCrLf & CRCs
Dim crc As String
DecimalValue = Len(CRCs)
BinaryValue = DecToBincrc(DecimalValue, 8)
crc = DecToBincrc(DecimalValue, 8)
MsgBox "CRC :" & vbCrLf & crc
This has now given me string like = 11111101String: <Header1><Header2><CmdID ><Length ><Content><CRC>
strData = "<" & Header1 & "><" & Header2 & "><" & CmdID & "><" & length & "><" & Content & "><" & crc & ">"
MsgBox "strData :" & vbCrLf & strData
=(strData) <11111010><11011101><11111111><11111110><11111111><01010111>01010111><11111101>
"baud=115200 parity=N data=8 stop=1"
=(strData) <11111010><11011101><11111111><11111110><11111111><01010111>01010111><11111101>
Current statusDim json As String
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long
Dim strError As String
Dim strData As String
Dim strDataToSend As String
Dim lngSize As Long
intPortID = Forms!frmLogin!txtFinComPort.Value
' Initialize Communications
lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
"baud=115200 parity=N data=8 stop=1")
If lngStatus <> 0 Then
' Handle error.
lngStatus = CommGetError(strError)
MsgBox "COM Error: " & strError
End If
' Set modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, True)
lngStatus = CommSetLine(intPortID, LINE_DTR, True)
lngSize = Len(strData)
lngStatus = CommWrite(intPortID, strData)
If lngStatus <> lngSize Then
' Handle error.
' Handle error.
On Error Resume Next
End If
‘Receing part of the VBA code' Read maximum of 14400 bytes from serial port.
Dim Jsons As Dictionary
Set Jsons = New Dictionary
Dim itemiz As Dictionary
lngStatus = CommRead(intPortID, strData, 14400)
Set rs = db.OpenRecordset("tblEfdReceiptsPOS")
If lngStatus > 0 Then
Set Jsons = JsonConverter.ParseJson(strData)
Z = 2
ElseIf lngStatus < 0 Then
Beep
MsgBox "Please note that there is no data to read", vbOKOnly, "The Comm Port has no data"
' Handle error.
On Error Resume Next
End If
' Process data.
For Each itemiz In Jsons
With rs
.AddNew
rs![TPIN] = item("TPIN")
rs![TaxpayerName] = itemiz("TaxpayerName")
rs![Address] = itemiz("Address")
rs![ESDTime] = itemiz("ESDTime")
rs![TerminalID] = itemiz("TerminalID")
rs![InvoiceCode] = itemiz("InvoiceCode")
rs![InvoiceNumber] = itemiz("InvoiceCode")
rs![FiscalCode] = itemiz("FiscalCode")
rs![TalkTime] = itemiz("TalkTime")
rs![Operator] = itemiz("Operator")
rs![Taxlabel] = itemiz("TaxItems")("TaxLabel")
rs![CategoryName] = itemiz("TaxItems")("CategoryName")
rs![Rate] = itemiz("TaxItems")("Rate")
rs![TaxAmount] = item("TaxItems")("TaxAmount")
rs![VerificationUrl] = itemiz("TaxItems")("VerificationUrl")
rs![INVID] = Me.ItemSoldID
rs.Update
End With
Z = Z + 1
Next
rs.Close
Set rs = Nothing
Set db = Nothing
Set Jsons = Nothing
' Reset modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, False)
lngStatus = CommSetLine(intPortID, LINE_DTR, False)
' Close communications.
Call CommClose(intPortID)
Dim Jsons As Dictionary
Set Jsons = New Dictionary
Dim itemiz As Dictionary
lngStatus = CommRead(intPortID, strData, 14400)
Set rs = db.OpenRecordset("tblEfdReceiptsPOS")
If lngStatus > 0 Then
Set Jsons = JsonConverter.ParseJson(strData)
Z = 2
ElseIf lngStatus < 0 Then
Beep
MsgBox "Please note that there is no data to read", vbOKOnly, "The Comm Port has no data"
' Handle error.
On Error Resume Next
End If
' Process data.
For Each itemiz In Jsons
With rs
.AddNew
rs![TPIN] = item("TPIN")
rs![TaxpayerName] = itemiz("TaxpayerName")
rs![Address] = itemiz("Address")
rs![ESDTime] = itemiz("ESDTime")
rs![TerminalID] = itemiz("TerminalID")
rs![InvoiceCode] = itemiz("InvoiceCode")
rs![InvoiceNumber] = itemiz("InvoiceCode")
rs![FiscalCode] = itemiz("FiscalCode")
rs![TalkTime] = itemiz("TalkTime")
rs![Operator] = itemiz("Operator")
rs![Taxlabel] = itemiz("TaxItems")("TaxLabel")
rs![CategoryName] = itemiz("TaxItems")("CategoryName")
rs![Rate] = itemiz("TaxItems")("Rate")
rs![TaxAmount] = item("TaxItems")("TaxAmount")
rs![VerificationUrl] = itemiz("TaxItems")("VerificationUrl")
rs![INVID] = Me.ItemSoldID
rs.Update
End With
Z = Z + 1
Next
rs.Close
Set rs = Nothing
Set db = Nothing
Set Jsons = Nothing
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE